aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2022-04-10 19:10:30 +0200
committerJeremias Stotter <jeremias@stotter.eu>2022-04-10 19:10:30 +0200
commit3121b63b92555d286166db949f03f1ec36dd0101 (patch)
tree529355f1168ce9dc89306bb097aea1bf4c1704f9
parent8a3e714ebc0e2f1a7a2198464546c62efd89ab82 (diff)
downloadJBlog-3121b63b92555d286166db949f03f1ec36dd0101.tar.gz
JBlog-3121b63b92555d286166db949f03f1ec36dd0101.tar.bz2
JBlog-3121b63b92555d286166db949f03f1ec36dd0101.zip
Added fenced code. Titles can now be child to list
-rw-r--r--md.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/md.c b/md.c
index af8968a..2e283df 100644
--- a/md.c
+++ b/md.c
@@ -455,6 +455,8 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
int soft_newline_count = 0;
bool inline_code_wait = false;
+ bool fenced_code = false;
+ char fenced_char = '\0';
// @todo: These two variables should be globals! Why did I even define them here at all?
struct tree_element* root = new_element();
@@ -474,6 +476,18 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
continue;
}
+ // man is this disgusting
+ if(fenced_code) {
+ if((*cur_char == '\n' || *cur_char == '\r') &&
+ *(cur_char + 1) == fenced_char && *(cur_char + 2) == fenced_char && *(cur_char + 3) == fenced_char) {
+ cur_char += 3;
+ active_element = root;
+ fenced_code = false;
+ } else
+ append_char_to_active(root, &active_element, *cur_char);
+ continue;
+ }
+
if(str_chr_wait_ast && *cur_char != '*') {
str_wait_hit(root, &active_element, &str_cl_wait_ast, &str_fin_wait_ast, &temp_str_ast, &str_chr_wait_ast, '*', t_str_ast);
}
@@ -654,7 +668,23 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
str_chr_hit(root, &active_element, &str_cl_wait_und, &str_fin_wait_und, &temp_str_und, &str_chr_wait_und, t_str_und);
break;
// No 3 backticks are supported, use 4 spaces at the begining of a line to get a <pre><code> block
+
case('`'):
+ case('~'):
+ // Check for fenced code
+ if(active_element == root || newline) {
+ if(*cur_char == *(cur_char + 1) && *(cur_char + 2)) {
+ NEW_ACTIVE_CHILD(active_element, root, -1, t_code, true);
+ fenced_code = true;
+ fenced_char = *cur_char;
+ // Ignore the rest of the line
+ while(*cur_char != 0 && *cur_char != '\n')
+ cur_char++;
+ break;
+ }
+ }
+ if(*cur_char == '~')
+ goto default2;
DEFAULT_CHECKS;
if(inline_code_wait) {
struct tree_element* parent_code = find_parent_type(root, active_element, t_inline_code);
@@ -675,8 +705,6 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
inline_code_wait = true;
}
break;
- case('~'):
- break;
case('['):
char* link_text = NULL;
char* link_loc = NULL;
@@ -735,8 +763,9 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
break;
case('#'):
if(hash_chain == 0 || newline) {
- if(active_element == root || newline) {
- active_element = root;
+ if(active_element == root || newline || active_element->type == t_li) {
+ if(!(active_element->type == t_li))
+ active_element = root;
hash_chain = 1;
newline = false;
break;
@@ -760,7 +789,7 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
if(active_element->parent ? active_element->parent->type == t_h : false) {
active_element = active_element->parent;
} else {
- NEW_ACTIVE_CHILD(active_element, root, -1, t_h, true);
+ NEW_ACTIVE_CHILD(active_element, active_element, -1, t_h, true);
active_element->value = malloc(sizeof(int));
}
}
Jeremias Stotters git repositories generated by CGIT