]> git.plutz.net Git - cgilite/blobdiff - markdown.awk
Extension: Arrows
[cgilite] / markdown.awk
index fa60543b49d43ed013325bf939e2d93ed22e7a5b..4e1dfa63eeae56ad0c16a46caf3a8b58dd782c3c 100755 (executable)
@@ -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 @@ function inline( line, LOCAL, len, code, href, guard ) {
   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) );
 
@@ -286,6 +286,14 @@ function inline( line, LOCAL, len, code, href, guard ) {
     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));
@@ -608,6 +616,12 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib
       return "<p>" HTML(substr(block, 1, len)) "</p>\n" _block( substr(block, len + 1) );
     }
 
+  # Macros (standalone <<macro>> calls handled as block, so they are not wrapped in paragraph)
+  } else if ( AllowMacros && match( block, /^<<(([^>]|>[^>])+)>>(\n|$)/) ) {
+    len = RLENGTH;
+    text = gensub(/^<<(([^>]|>[^>])+)>>(\n.*)?$/, "\\1", 1, block);
+    return macro(text) _block(substr(block, len + 1));
+
   # Split paragraphs
   } else if ( match( block, /(^|\n)[[:space:]]*(\n|$)/) ) {
     len = RLENGTH; st = RSTART;