From: Pierre Curto <pierre.curto@gmail.com>
Plain links, alone on a line, with two blank lines on either side are
linkified in the HTML output.
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
---
cmd/haredoc/docstr.ha | 48 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/cmd/haredoc/docstr.ha b/cmd/haredoc/docstr.ha
index b57f55f2..7e52bac1 100644
--- a/cmd/haredoc/docstr.ha
+++ b/cmd/haredoc/docstr.ha
@@ -6,6 +6,7 @@
// (c) 2022 Umar Getagazov <umar@handlerug.me>
use ascii;
use bufio;
+use bytes;
use encoding::utf8;
use fmt;
use hare::ast;
@@ -72,6 +73,8 @@ fn scandoc(par: *parser) (token | void) = {
return scansample(par);
case '-' =>
return scanlist(par);
+ case '\n' =>
+ return scanlink(par);
case =>
return scantext(par);
};
@@ -246,3 +249,48 @@ fn scanlist(par: *parser) (token | void) = {
par.state = docstate::LIST;
return listitem;
};
+
+fn scanlink(par: *parser) (token | void) = {
+ // 2 blank lines before the link
+ match (bufio::scanrune(&par.src)!) {
+ case io::EOF => return void;
+ case let rn: rune =>
+ if (rn != '\n') {
+ bufio::unreadrune(&par.src, rn);
+ return void;
+ };
+ };
+ match (bufio::scanrune(&par.src)!) {
+ case io::EOF => return void;
+ case let rn: rune =>
+ if (rn != '\n') {
+ bufio::unreadrune(&par.src, rn);
+ bufio::unreadrune(&par.src, rn);
+ return void;
+ };
+ };
+ // link line
+ const line = match (bufio::scanline(&par.src)!) {
+ case io::EOF => return void;
+ case let line: []u8 =>
+ yield line;
+ };
+ defer free(line);
+ const http: []u8 = ['h', 't', 't', 'p', ':', '/', '/'];
+ const https: []u8 = ['h', 't', 't', 'p', 's', ':', '/', '/'];
+ if (!bytes::hasprefix(line, http) || !bytes::hasprefix(line, https)) {
+ bufio::unread(&par.src, line);
+ return;
+ };
+ // blank line following the link
+ match (bufio::scanrune(&par.src)!) {
+ case io::EOF => return void;
+ case let rn: rune =>
+ if (rn != '\n') {
+ bufio::unreadrune(&par.src, rn);
+ bufio::unread(&par.src, line);
+ return void;
+ };
+ };
+ return strings::fromutf8(line): text;
+};
--
2.34.4
You can actually discard this patch as it is already possible to
include URLs (someone (cant remember who) mentioned on IRC after I
sent the patch)).
Le lun. 10 oct. 2022 à 11:03, Drew DeVault <sir@cmpwn.com> a écrit :
>
> Does this need updates to the html emitter to actually URLify these?