nihdoc

WIP markup parser (txt -> html)
git clone git://git.alexkarle.com.com/blag
Log | Files | Refs | README | LICENSE

commit e7aceb8df91e4225a1e4d690ca212bf6e4a64b2a (patch)
parent c083e8917360793a1dac9050c04cb3e7e85d6202
Author: Alex Karle <alex@alexkarle.com>
Date:   Tue, 28 Dec 2021 13:39:58 -0500

Fix [url] links with non-space characters after

I noticed on my blog that [url]: foo was broken--we need to check for
[url] links for all characters, not just whitespace!

Diffstat:
Mnihdoc.c | 16++++++----------
Mtest/link.html | 6++++++
Mtest/link.txt | 4++++
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/nihdoc.c b/nihdoc.c @@ -96,12 +96,6 @@ void handle_lf() { printf("</h%d>\n", hlvl); } - /* Check for [url] style links */ - if (in_link == OPT_URL) { - in_link = NOL; - printf("<a href=\"%s\">%s</a>", lnkdes, lnkdes); - } - /* multi-line types (two lf to close) */ if (lastc == '\n' || (lastc == '>' && blockquote)) { switch (in) { @@ -169,6 +163,12 @@ int parse() { continue; } + /* Any character other than a '(' terminates a link at ']' */ + if (in_link == OPT_URL && c != '(') { + in_link = NOL; + printf("<a href=\"%s\">%s</a>", lnkdes, lnkdes); + } + /* Handle Escapes before any other bit of the main loop */ if (escape) { maybe_startp(); @@ -203,10 +203,6 @@ int parse() { if (in == HEADER_PARSE) { printf("<h%d>", hlvl); in = HEADER; - } else if (in_link == OPT_URL) { - /* [url] style links */ - in_link = NOL; - printf("<a href=\"%s\">%s</a> ", lnkdes, lnkdes); } else if (in == LIST_PARSE) { if (!listdepth) { newlist(); diff --git a/test/link.html b/test/link.html @@ -25,3 +25,9 @@ this is a paragraph about this is a paragraph about <a href="https://alexkarle.com">my site</a> yo! </p> +<p> +this is a <a href="link">https://alexkarle.com</a>: without a space after +</p> +<p> +this is a link <a href="https://alexkarle.com">https://alexkarle.com</a>: without a space after +</p> diff --git a/test/link.txt b/test/link.txt @@ -17,3 +17,7 @@ this is a paragraph about this is a paragraph about [my site](https://alexkarle.com) yo! + +this is a [https://alexkarle.com](link): without a space after + +this is a link [https://alexkarle.com]: without a space after