aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2022-03-20 19:14:19 +0100
committerJeremias Stotter <jeremias@stotter.eu>2022-03-20 19:14:19 +0100
commit76082c1cbbba512f68d157e441e8d1941823a128 (patch)
treefeb693cd9e8f555f856c21ad261575ce68704320
parentd7202016af72f39aed66cd7591a8227e24c21f51 (diff)
downloadJBlog-76082c1cbbba512f68d157e441e8d1941823a128.tar.gz
JBlog-76082c1cbbba512f68d157e441e8d1941823a128.tar.bz2
JBlog-76082c1cbbba512f68d157e441e8d1941823a128.zip
Added blockquotes
-rw-r--r--md.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/md.c b/md.c
index 5302718..a1db73d 100644
--- a/md.c
+++ b/md.c
@@ -51,7 +51,8 @@ enum html_type {
t_li,
t_hr,
t_code,
- t_inline_code
+ t_inline_code,
+ t_bq
};
// The file will be structured as a tree that, in the end will be converted to valid html
@@ -160,6 +161,7 @@ char* realloc_append(char* dest, char* src) {
#define hr_html "<hr/>\n"
#define code_html "<pre><code>%s</code></pre>\n"
#define inline_code_html "<code>%s</code>\n"
+#define bq_html "<blockquote>%s</blockquote>\n"
// Resolve a tree to html
int depth = 0;
char* tree_to_html(struct tree_element* root) {
@@ -255,6 +257,10 @@ char* tree_to_html(struct tree_element* root) {
strcat(html, inner_html);
}
break;
+ case(t_bq):
+ html = realloc_for_html(bq_html);
+ sprintf(html, bq_html, inner_html ? inner_html : "");
+ break;
default:
html=inner_html;
break;
@@ -690,6 +696,15 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
hash_chain++;
break;
}
+ case('>'):
+ if(newline || active_element == root) {
+ // Look if we already have a block quote parent somewhere, if so just continue, otherwise create a new one.
+ if(find_parent_type(root, active_element, t_bq))
+ break;
+ NEW_ACTIVE_CHILD(active_element, root, -1, t_bq, true);
+ break;
+ } else
+ goto default2;
case(' '):
if(hash_chain > 0) {
if(active_element->type != t_h) {
Jeremias Stotters git repositories generated by CGIT