~sircmpwn/hare-dev

hare: cmd/haredoc: add support for links in comments v1 PROPOSED

~pierrec: 1
 cmd/haredoc: add support for links in comments

 1 files changed, 48 insertions(+), 0 deletions(-)
#848575 alpine.yml success
#848576 freebsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/35483/mbox | git am -3
Learn more about email & git

[PATCH hare] cmd/haredoc: add support for links in comments Export this patch

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
builds.sr.ht <builds@sr.ht>
hare/patches: SUCCESS in 1m40s

[cmd/haredoc: add support for links in comments][0] from [~pierrec][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/35483
[1]: mailto:pierre.curto@gmail.com

✓ #848576 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/848576
✓ #848575 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/848575