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 --- demo/src/index.md | 3 +++ single.awk | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/demo/src/index.md b/demo/src/index.md index 6958e44..7b37979 100644 --- a/demo/src/index.md +++ b/demo/src/index.md @@ -98,3 +98,6 @@ x~2~^e^ = y^някоя си^~търсно то~ : **Common** [programmer](https://wikipedia.org "Me") phrase Lorem `ipsum` dolor tiada ad;l ``kfj `skigj`` jjsa + +![](https://syndamia.com/favicon.ico) ![](https://syndamia.com/favicon.ico "Hello") ![World](https://syndamia.com/favicon.ico) ![Hello](https://syndamia.com/favicon.ico "World") + 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