~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

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

Details
Message ID
<166375764774.3812.11645634728545284079-0@git.sr.ht>
DKIM signature
missing
Download raw message
Patch: +48 -0
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

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CN20WF57YPHP.DL0LWZMCA29H@cirno>
In-Reply-To
<166375764774.3812.11645634728545284079-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
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]: 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
Details
Message ID
<CNI4F3EMTZHR.2SD9Z3MCRBHKJ@taiga>
In-Reply-To
<166375764774.3812.11645634728545284079-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Does this need updates to the html emitter to actually URLify these?
Details
Message ID
<CAG3idSfM60=iYmepP-h6H_prWGFUTMXY8sPa7rFHnU+KY7VR+w@mail.gmail.com>
In-Reply-To
<CNI4F3EMTZHR.2SD9Z3MCRBHKJ@taiga> (view parent)
DKIM signature
missing
Download raw message
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?
Reply to thread Export thread (mbox)