commit 02135370d1948712ce673dbee1adb82b15c66408
parent 2741bda906333f9c999821b5ed881f0aa1948490
Author: Umar Getagazov <umar@handlerug.me>
Date: Thu, 26 May 2022 15:56:26 +0000
haredoc: don't linkify <word> and comma
Fixes "TODO:" and alikes being mistakenly linkified.
Signed-off-by: Umar Getagazov <umar@handlerug.me>
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/cmd/haredoc/html.ha b/cmd/haredoc/html.ha
@@ -16,6 +16,7 @@ use hare::lex;
use hare::module;
use hare::unparse;
use io;
+use net::ip;
use net::uri;
use os;
use path;
@@ -400,11 +401,15 @@ fn markup_html(ctx: *context, in: io::handle) (void | io::error) = {
match (uri::parse(strings::trim(tx))) {
case let uri: uri::uri =>
defer uri::finish(&uri);
- fmt::fprint(ctx.out, "<a rel='nofollow noopener' href='")?;
- uri::fmt(ctx.out, &uri)?;
- fmt::fprint(ctx.out, "'>")?;
- html_escape(ctx.out, tx)?;
- fmt::fprint(ctx.out, "</a>")?;
+ if (uri.host is net::ip::addr || len(uri.host as str) > 0) {
+ fmt::fprint(ctx.out, "<a rel='nofollow noopener' href='")?;
+ uri::fmt(ctx.out, &uri)?;
+ fmt::fprint(ctx.out, "'>")?;
+ html_escape(ctx.out, tx)?;
+ fmt::fprint(ctx.out, "</a>")?;
+ } else {
+ html_escape(ctx.out, tx)?;
+ };
case uri::invalid =>
html_escape(ctx.out, tx)?;
};