From e7aceb8df91e4225a1e4d690ca212bf6e4a64b2a Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 28 Dec 2021 13:39:58 -0500 Subject: [PATCH] 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! --- nihdoc.c | 16 ++++++---------- test/link.html | 6 ++++++ test/link.txt | 4 ++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/nihdoc.c b/nihdoc.c index eb06189..164af70 100644 --- a/nihdoc.c +++ b/nihdoc.c @@ -96,12 +96,6 @@ void handle_lf() { printf("\n", hlvl); } - /* Check for [url] style links */ - if (in_link == OPT_URL) { - in_link = NOL; - printf("%s", 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("%s", 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("", hlvl); in = HEADER; - } else if (in_link == OPT_URL) { - /* [url] style links */ - in_link = NOL; - printf("%s ", lnkdes, lnkdes); } else if (in == LIST_PARSE) { if (!listdepth) { newlist(); diff --git a/test/link.html b/test/link.html index 2c5e268..d9979df 100644 --- a/test/link.html +++ b/test/link.html @@ -25,3 +25,9 @@ this is a paragraph about this is a paragraph about my site yo!

+

+this is a https://alexkarle.com: without a space after +

+

+this is a link https://alexkarle.com: without a space after +

diff --git a/test/link.txt b/test/link.txt index 80c8244..63d881f 100644 --- 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 -- libgit2 1.1.1