]> git.plutz.net Git - shellwiki/commitdiff
Merge commit '7a171a7dd5c5fcfc1e53c5e5d8165fac01291c0b'
authorPaul Hänsch <paul@plutz.net>
Sat, 20 May 2023 14:13:34 +0000 (16:13 +0200)
committerPaul Hänsch <paul@plutz.net>
Sat, 20 May 2023 14:13:34 +0000 (16:13 +0200)
1  2 
cgilite/markdown.awk

diff --combined cgilite/markdown.awk
index b5072666de89f34c4b425211b70dd7471b0d9f21,9955bf4ccd42f2b806538e20bd6b8af8b2e15202..9955bf4ccd42f2b806538e20bd6b8af8b2e15202
@@@ -74,7 -74,7 +74,7 @@@
  # -  ?  ... three-dot ellipsis (smartypants)
  # - [-] en-dash (smartypants)
  # - [ ] Automatic em-dash / en-dash
- # - [ ] Automatic -> Arrows <-
+ # - [x] Automatic -> Arrows <- (custom)
  
  function debug(text) { printf "\n---\n%s\n---\n", text > "/dev/stderr"; }
  
@@@ -113,7 -113,7 +113,7 @@@ function inline( line, LOCAL, len, code
    if ( line ~ /^$/ ) {  # Recursion End
      return "";
  
-   #  omit processing of escaped characters
+   # omit processing of escaped characters
    } else if ( line ~ /^\\[]\\`\*_\{\}\(\)#\+-\.![]/) {
      return substr(line, 2, 1) inline( substr(line, 3) );
  
  
    # inline links
    #                                 ,_______________________Image____________________________,
-   } else if ( match(line, /^\[([^]]+|!\[[^]]+\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/) ) {
+   } else if ( match(line, /^\[([^]]+|!\[[^]]*\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/) ) {
      len = RLENGTH;
-     text  = gensub(/^\[([^]]+|!\[[^]]+\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/, \
+     text  = gensub(/^\[([^]]+|!\[[^]]*\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/, \
                     "\\1", 1, substr(line, 1, len) );
-     href  = gensub(/^\[([^]]+|!\[[^]]+\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/, \
+     href  = gensub(/^\[([^]]+|!\[[^]]*\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/, \
                     "\\4", 1, substr(line, 1, len) );
-     title = gensub(/^\[([^]]+|!\[[^]]+\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/, \
+     title = gensub(/^\[([^]]+|!\[[^]]*\]\([^"\)]+([ \t]+"[^"]+")?\)(\{[a-zA-Z \t-]*\})?)\]\(([^"\)]+)([[:space:]]+"([^"]+)")?\)/, \
                     "\\6", 1, substr(line, 1, len) );
      if ( title ) {
        return "<a href=\"" URL(href) "\" title=\"" HTML(title) "\">" inline( text ) "</a>" inline( substr( line, len + 1) );
      }
  
    # inline images
-   } else if ( match(line, /^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/) ) {
+   } else if ( match(line, /^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/) ) {
      len = RLENGTH;
-     text   = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\1", "g", substr(line, 1, len) );
-     href   = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\2", "g", substr(line, 1, len) );
-     title  = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\4", "g", substr(line, 1, len) );
-     attrib = gensub(/^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\6", "g", substr(line, 1, len) );
+     text   = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\1", "g", substr(line, 1, len) );
+     href   = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\2", "g", substr(line, 1, len) );
+     title  = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\4", "g", substr(line, 1, len) );
+     attrib = gensub(/^!\[([^]]*)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?/, "\\6", "g", substr(line, 1, len) );
      if ( title && attrib ) {
        return "<img src=\"" URL(href) "\" alt=\"" HTML(text) "\" title=\"" HTML(title) "\" class=\"" HTML(attrib) "\">" \
               inline( substr( line, len + 1) );
      }
  
    # reference style images
-   } else if ( match(line, /^!\[([^]]+)\] ?\[([^]]*)\]/ ) ) {
+   } else if ( match(line, /^!\[([^]]*)\] ?\[([^]]*)\]/ ) ) {
      len = RLENGTH;
-     text = gensub(/^!\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\1", 1, substr(line, 1, len) );
-       id = gensub(/^!\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
+     text = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\1", 1, substr(line, 1, len) );
+       id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
      if ( ! id ) id = text;
      if ( rl_href[id] && rl_title[id] ) {
        return "<img src=\"" URL(rl_href[id]) "\" alt=\"" HTML(text) "\" title=\"" HTML(rl_title[id]) "\">" \
      len = RLENGTH;
      return substr( line, 1, len ) inline(substr(line, len + 1));
  
+   # Arrows
+   } else if ( line ~ /^-->( |$)/) {  # ignore multidash-arrow
+     return "--&gt;" inline( substr(line, 4) );
+   } else if ( line ~ /^<-( |$)/) {
+     return "&larr;" inline( substr(line, 3) );
+   } else if ( line ~ /^->( |$)/) {
+     return "&rarr;" inline( substr(line, 3) );
    # Escape lone HTML character
    } else if ( match( line, /^[&<>"']/) ) {
      return HTML(substr(line, 1, 1)) inline(substr(line, 2));
@@@ -557,12 -565,12 +565,12 @@@ function _block( block, LOCAL, st, len
             _block( substr( block, len + 1) );
  
    # block images (wrapped in <figure>)
-   } else if ( match(block, /^!\[([^]]+)\]\(([^"\)]+)([ \t]+"([^"]+)")?\)(\{([a-zA-Z \t-]*)\})?(\n|$)/) ) {
+   } 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);
+     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 "<figure data-src=\"" URL(href) "\" class=\"" HTML(attrib) "\">" \
                 "<img src=\"" URL(href) "\" alt=\"" HTML(text) "\" class=\"" HTML(attrib) "\">" \
      }
  
    # reference style images (block)
-   } else if ( match(line, /^!\[([^]]+)\] ?\[([^]]*)\](\n|$)/ ) ) {
+   } else if ( match(line, /^!\[([^]]*)\] ?\[([^]]*)\](\n|$)/ ) ) {
      len = RLENGTH;
-     text = gensub(/^!\[([^\n]+)\] ?\[([^\n]*)\](\n.*)?$/, "\\1", 1, block);
-       id = gensub(/^!\[([^\n]+)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
+     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 "<figure data-src=\"" URL(rl_href[id]) "\">" \