From fd385801d115e8a0aa29ffb9b9e6ff215c34cc42 Mon Sep 17 00:00:00 2001
From: Linnnus
Date: Sat, 17 Feb 2024 02:41:43 +0100
Subject: fix(creole): Handle escapes properly
A faulty boolean expression was to blame.
This patch also adds the necessary tests to prevent relapses (i forgot
det technical term).
---
src/creole.c | 4 +++-
src/creole_test_main.c | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/creole.c b/src/creole.c
index 5804ebd..94e8020 100644
--- a/src/creole.c
+++ b/src/creole.c
@@ -116,6 +116,8 @@ static struct {
// Escaped special characters
{"~[[", "[["},
{"~]]", "]]"}, // NOTE: This pattern is duplicated in do_link().
+ {"~//", "//"},
+ {"~**", "**"},
// Characters that have special meaning in HTML
// NOTE: These rules are duplicated in hprint().
{"<", "<"},
@@ -256,7 +258,7 @@ long do_emphasis(const char *begin, const char *end, bool new_block, FILE *out)
const char *stop = start;
do {
stop = strnstr(stop + 1, "//", end - (stop + 1));
- } while (stop != NULL && stop[-1] == '~' && stop[-1] == ':');
+ } while (stop != NULL && (stop[-1] == '~' || stop[-1] == ':'));
if (stop == NULL) {
return 0;
}
diff --git a/src/creole_test_main.c b/src/creole_test_main.c
index 334ba43..bae144b 100644
--- a/src/creole_test_main.c
+++ b/src/creole_test_main.c
@@ -135,6 +135,16 @@ struct {
.input = "Bold and italics should //be\nable// to cross lines.",
.output = "Bold and italics should be\nable to cross lines.
"
},
+ {
+ .name = "Emphasised URL",
+ .input = "//https://example.com//",
+ .output = "https://example.com
"
+ },
+ { // I don't know that this is necessarily //correct// behavior... Let's document it anyways
+ .name = "Emphasised URL ending in slash",
+ .input = "//https://example.com///",
+ .output = "https://example.com/
"
+ },
{
.name = "Emphasis does not cross paragraph boundaries",
.input = "This text should //not\n\nbe emphased// as it crosses a paragraph boundary.",
@@ -151,11 +161,21 @@ struct {
"http://www.wikicreole.org. This is what can go wrong "
"this should be an italic text.
"
},
+ {
+ .name = "Escaped emphasis",
+ .input = "I //love double ~// slashes//!",
+ .output = "I love double // slashes!
"
+ },
{
.name = "Bold",
.input = "**Strong**",
.output = "Strong
"
},
+ {
+ .name = "Escaped bold",
+ .input = "**Strong ~** still strong**",
+ .output = "Strong ** still strong
"
+ },
{
.name = "Nested bold/italic",
.input = "//**Strong and emphasized**//",
--
cgit v1.2.3