~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(-)
#848553 alpine.yml failed
#848554 freebsd.yml failed
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/35482/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..8aa7cc44 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) (text | 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: FAILED in 1m20s

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

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

✗ #848554 FAILED hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/848554
✗ #848553 FAILED hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/848553