hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c2c7d3b78ae84014787012a6ca78ff722de4c8e0
parent 4bdc65c00d0223d38ad7a0ca81ac231b9b4bb01e
Author: Umar Getagazov <umar@handlerug.me>
Date:   Fri, 25 Mar 2022 23:53:33 +0700

haredoc: use uri::parse for link detection

Signed-off-by: Umar Getagazov <umar@handlerug.me>

Diffstat:
Mcmd/haredoc/html.ha | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/cmd/haredoc/html.ha b/cmd/haredoc/html.ha @@ -15,6 +15,7 @@ use hare::lex; use hare::module; use hare::unparse; use io; +use net::uri; use os; use path; use strings; @@ -355,17 +356,17 @@ fn markup_html(ctx: *context, in: io::handle) (void | io::error) = { fmt::fprintln(ctx.out)?; fmt::fprint(ctx.out, "<p>")?; case let tx: text => - if (strings::hasprefix(tx, "https://")) { - // Temporary hack + defer free(tx); + match (uri::parse(strings::trim(tx))) { + case let uri: uri::uri => + defer uri::finish(&uri); fmt::fprint(ctx.out, "<a rel='nofollow noopener' href='")?; - html_escape(ctx.out, tx)?; + uri::fmt(ctx.out, &uri)?; fmt::fprint(ctx.out, "'>")?; html_escape(ctx.out, tx)?; fmt::fprint(ctx.out, "</a>")?; - free(tx); - } else { + case uri::invalid => html_escape(ctx.out, tx)?; - free(tx); }; case let re: reference => htmlref(ctx, re)?;