summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2024-02-17 04:00:31 +0100
committerLinnnus <[email protected]>2024-02-17 04:00:31 +0100
commitd7a869ffeb2f313df06d4505911cefdf8108ff7e (patch)
treef1af59e2992e88243c1cd78efcf08d01d487ff3c
parenta4a59f2fe8ff5df7d8cba81037f14dbd2c4ed33f (diff)
feat(creole): handle escaped raw URLs
-rw-r--r--src/creole.c26
-rw-r--r--src/creole_test_main.c5
2 files changed, 25 insertions, 6 deletions
diff --git a/src/creole.c b/src/creole.c
index 94e8020..c83ffd1 100644
--- a/src/creole.c
+++ b/src/creole.c
@@ -187,11 +187,21 @@ long do_link(const char *begin, const char *end, bool new_block, FILE *out)
long do_raw_url(const char *begin, const char *end, bool new_block, FILE *out)
{
+ const char *p = begin;
+
+ // This piece of spaghetti is necessary to handle escaped urls.
+ // These should not actually be turned into anchor tags.
+ // See: <http://www.wikicreole.org/wiki/Creole1.0#section-Creole1.0-EscapeCharacter>
+ bool escaped = false;
+ if (*begin == '~') {
+ escaped = true;
+ p += 1;
+ }
+
// Eat a scheme followed by a ":". Here are the relevant rules from RFC 3986.
// - URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
// - scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
// See: <https://www.rfc-editor.org/rfc/rfc3986#section-3.1>
- const char *p = begin;
if (!isalpha(*p)) {
return 0;
}
@@ -240,11 +250,15 @@ end_url:
q -= 1;
}
- fputs("<a href=\"", out);
- hprint(out, begin, q);
- fputs("\">", out);
- hprint(out, begin, q);
- fputs("</a>", out);
+ if (escaped) {
+ hprint(out, begin + 1 /* ~ */, q);
+ } else {
+ fputs("<a href=\"", out);
+ hprint(out, begin, q);
+ fputs("\">", out);
+ hprint(out, begin, q);
+ fputs("</a>", out);
+ }
return q - begin;
}
diff --git a/src/creole_test_main.c b/src/creole_test_main.c
index a284811..6b9e95b 100644
--- a/src/creole_test_main.c
+++ b/src/creole_test_main.c
@@ -124,6 +124,11 @@ struct {
"https://wiki.c2.com/</a>.</p>"
},
{
+ .name = "Escaped raw URL",
+ .input = "Please don't register ~https://cohost.org/!",
+ .output = "<p>Please don't register https://cohost.org/!</p>"
+ },
+ {
.name = "Unnamed URL",
.input = "[[http //example.com/examplepage]]",
.output = "<p><a href=\"http //example.com/examplepage\">"