From: Paul Hänsch Date: Thu, 18 May 2023 11:48:02 +0000 (+0200) Subject: extesion: introduce
-wrapped images as block elements X-Git-Url: http://git.plutz.net/?p=cgilite;a=commitdiff_plain;h=697a1bb3a7823c889abe31df5168a57dd11f37d4 extesion: introduce
-wrapped images as block elements --- diff --git a/markdown.awk b/markdown.awk index 4f18b9b..fa60543 100755 --- a/markdown.awk +++ b/markdown.awk @@ -42,6 +42,8 @@ # - [x] Automatic heading identifiers (custom) # - [x] Fenced code blocks (php md, pandoc) # - [x] Fenced code attributes +# - [x] Images (as block elements,
-wrapped) (custom) +# - [x] reference style block images # - [/] Tables # - ? Simple table (pandoc) # - ? Multiline table (pandoc) @@ -554,6 +556,58 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib "\n\n" \ _block( substr( block, len + 1) ); + # block images (wrapped in
) + } else if ( match(block, /^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n|$)/) ) { + len = RLENGTH; + text = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\1", "g", block); + href = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\2", "g", block); + title = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\4", "g", block); + attrib = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n.*)?$/, "\\6", "g", block); + if ( title && attrib ) { + return "
" \ + "\""" \ + "
" inline(title) "
" \ + "
\n\n" \ + _block( substr( block, len + 1) ); + } else if ( title ) { + return "
" \ + "\""" \ + "
" inline(title) "
" \ + "
\n\n" \ + _block( substr( block, len + 1) ); + } else if ( attrib ) { + return "
" \ + "\""" \ + "
\n\n" \ + _block( substr( block, len + 1) ); + } else { + return "
" \ + "\""" \ + "
\n\n" \ + _block( substr( block, len + 1) ); + } + + # reference style images (block) + } else if ( match(line, /^!\[([^]]+)\] ?\[([^]]*)\](\n|$)/ ) ) { + len = RLENGTH; + text = gensub(/^!\[([^\n]+)\] ?\[([^\n]*)\](\n.*)?$/, "\\1", 1, block); + id = gensub(/^!\[([^\n]+)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block); + if ( ! id ) id = text; + if ( rl_href[id] && rl_title[id] ) { + return "
" \ + "\""" \ + "
" inline(rl_title[id]) "
" \ + "
\n\n" \ + _block( substr( block, len + 1) ); + } else if ( rl_href[id] ) { + return "
" \ + "\""" \ + "
\n\n" \ + _block( substr( block, len + 1) ); + } else { + return "

" HTML(substr(block, 1, len)) "

\n" _block( substr(block, len + 1) ); + } + # Split paragraphs } else if ( match( block, /(^|\n)[[:space:]]*(\n|$)/) ) { len = RLENGTH; st = RSTART;