src/post2html: Ability to reference content of previous fence

I'll be using this to show example HTML code and then output it as actual
HTML to be rendered as part of the article.  Otherwise the HMTL has to be
duplicated and maintained in multiple places.

An alternative is to include a file, but that is much less convenient for
smaller snippets.
master
Mike Gerwitz 2019-08-09 22:07:58 -04:00
parent b3ad4f7599
commit 61b80c516f
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 9 additions and 0 deletions

View File

@ -109,6 +109,15 @@ prefmt()
next
}
# reference to the content of the last fence (e.g. if a previous
# code block is HTML and we want to render it as an example)
/^```/ {
gather = !gather
if ( gather ) gblock = ""
}
!/^```/ && gather { gblock = gblock $0 "\n" }
!gather && /^ *@LASTFENCE@$/ { print gblock; next }
{ print }
'
}