From c67dd619cc887371a989105d517ab5715049cf9c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 23 Jul 2024 17:45:47 +0300 Subject: (single) Implemented inline images --- single.awk | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'single.awk') diff --git a/single.awk b/single.awk index f24808c..708158f 100644 --- a/single.awk +++ b/single.awk @@ -15,7 +15,9 @@ # [ ] Reference # [x] Emphasis # [x] Code -# [ ] Images +# [.] Images +# [x] Inline +# [ ] Reference # [ ] Other # [ ] Autolinks # [ ] Escapes @@ -242,8 +244,14 @@ blankline { } # Links -/\[[^\]]*\]\([^)]*\)/ { - while (match($0, /\[[^\]]*\]\(/)) { +/!?\[[^\]]*\]\([^)]*\)/ { + isimg = 0 + while (match($0, /!?\[[^\]]*\]\(/)) { + if (substr($0, RSTART, 1) == "!") { + isimg = 1 + RSTART++ + RLENGTH-- + } astart = RSTART ## astart = indexof("[") inner_anchor = substr($0, RSTART + 1, RLENGTH - 3) ## ...[xxxxx](...)... @@ -251,14 +259,21 @@ blankline { match(substr($0, astart), /\]\([^)]*\)/) aend += RLENGTH - 2 ## aend = indexof(")") href = substr($0, astart + RSTART + 1, RLENGTH - 3) ## ...[...](xxxxx)... + sub(/[ \t]+/, "", href) - title = "" if (match(href, /"[^"]*"[ \t]*$/)) { - title = " title=" substr(href, RSTART, RLENGTH) + title = substr(href, RSTART, RLENGTH) href = substr(href, 1, RSTART - 1) } + else { + title = "\"\"" + } + + if (isimg) elem = "\""" + else elem = "" inner_anchor "" - $0 = substr($0, 1, astart - 1) "" inner_anchor "" substr($0, aend + 1) + $0 = substr($0, 1, astart - 1 - isimg) elem substr($0, aend + 1) + isimg = 0 } } -- cgit v1.3.1-26-gb76a