summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2024-04-04 17:32:32 +0200
committerLinnnus <[email protected]>2024-04-04 17:34:38 +0200
commit6457d823443f30053d507d53d66dffedb7a53a07 (patch)
treed9a15c977d3f4eb66a0217dc90ee5a4e058ee54f
parent2c0719a6eec7207df3fdffed943bf2d11d602ce6 (diff)
feat(creole): Add horizontal rule
-rw-r--r--src/creole.c25
-rw-r--r--src/creole_test_main.c10
2 files changed, 29 insertions, 6 deletions
diff --git a/src/creole.c b/src/creole.c
index c8847bb..dc37075 100644
--- a/src/creole.c
+++ b/src/creole.c
@@ -24,6 +24,7 @@ long do_bold(const char *begin, const char *end, bool new_block, FILE *out);
long do_nowiki_inline(const char *begin, const char *end, bool new_block, FILE *out);
long do_nowiki_block(const char *begin, const char *end, bool new_block, FILE *out);
long do_list(const char *begin, const char *end, bool new_block, FILE *out);
+long do_horizontal_rule(const char *begin, const char *end, bool new_block, FILE *out);
// Prints string with special HTML characters escaped.
//
@@ -89,6 +90,7 @@ static parser_t parsers[] = {
do_headers,
do_nowiki_block,
do_list,
+ do_horizontal_rule,
do_paragraph, // <p> should be last as it eats anything
// Inline-level elements
@@ -97,7 +99,8 @@ static parser_t parsers[] = {
do_link,
do_raw_url,
do_nowiki_inline,
- do_replacements
+ do_replacements,
+
};
long do_headers(const char *begin, const char *end, bool new_block, FILE *out) {
@@ -508,6 +511,26 @@ long do_list(const char *begin, const char *end, bool new_block, FILE *out) {
return -(item_end - begin);
}
+long do_horizontal_rule(const char *begin, const char *end, bool new_block, FILE *out) {
+ if (!new_block) {
+ return 0;
+ }
+
+ unsigned length = 0;
+ const char *q = begin;
+ while (q < end && *q == '-') {
+ q++;
+ }
+
+ // Anything at least 4 hyphens long is a horizontal rule.
+ // See: http://www.wikicreole.org/wiki/HorizontalRuleReasoning
+ if (length >= 4) {
+ fputs("<hr>", out);
+ }
+
+ return q - end;
+}
+
void process(const char *begin, const char *end, bool new_block, FILE *out) {
assert(begin <= end);
diff --git a/src/creole_test_main.c b/src/creole_test_main.c
index 5c35e49..34ca07d 100644
--- a/src/creole_test_main.c
+++ b/src/creole_test_main.c
@@ -296,6 +296,11 @@ struct {
.input = "## Sublist item",
.output = "<p>## Sublist item</p>"
},
+ {
+ .name = "Horizontal rule",
+ .input = "Some text\n\n----\n\nSome more text",
+ .output = "<p>Some text</p><hr /><p>Some more text</p>"
+ },
#if 0
{
.name = "Ordered item with ordered sublist",
@@ -308,11 +313,6 @@ struct {
.output = "<ul><li> Item<ol>\n<li> Subitem</li></ol></li></ul>"
},
{
- .name = "Horizontal rule",
- .input = "Some text\n----\nSome more text",
- .output = "<p>Some text</p><hr /><p>Some more text</p>"
- },
- {
.name = "Preformatted block",
.input = "{{{\nPreformatted block\n}}}",
.output = "<pre>Preformatted block\n</pre>"