# Handles Markup Processing to HTML # Author: http://the-brown-dragon.com ####################################### # Save a paragraph tag in hold area 1{x;s,.*,

,;x;} # [lit(eral) stuff to embed in html /^\[lit.html\]/{ s/.*// :litloop n /\[lit.html.ends\]/d blitloop } # [lit(eral) stuff to embed in other outputs /^\[lit\./d # Special characters that we need to escape in HTML s/\&/\&/g s//\>/g # Quotation /^"->/s/.*/

/ /^<-"/s,.*,
, # Center /^|--center-->/s/.*/
/ /^<--center--|/s/.*/<\/center>/ # Code block /^\[code /{ s,\[code \([^\\/]*\)\],

\1

, s,\[code \(.*[\\/]\([^\\/]*\)\)\],

\2

, :codeloop n /^\[\/codeend\]/{s,.*,

,;b;} s/\&/\&/g s//\>/g s/ /\ /g s/$// bcodeloop } # Capitalized text gets a header marker (space at end disables) s/^[A-Z][-!? A-Z]\+[-!?A-Z]$/

&<\/div>/ # Escape a character (put into unlikely form)... s/\\\(.\)/ ~~~~~~~\1~~~~~~~ /g # Bold (** for multi word ** - *for* single word) s/\(^\|[^A-Za-z0-9]\)\*\*/\1\n/g;s/\*\*\($\|[^A-Za-z0-9]\)/\n\1/g s/\n\([^\n]\+\)\n/\1<\/b>/g;s/\n/**/g s/\(^\|[^A-Za-z0-9]\)\*\([^* ]\+\)\*\($\|[^A-Za-z0-9]\)/\1\2<\/b>\3/g # Italic (__ for multi word __ - _for_ single word) s/\(^\|[^A-Za-z0-9]\)__/\1\n/g;s/__\($\|[^A-Za-z0-9]\)/\n\1/g s/\n\([^\n]\+\)\n/\1<\/i>/g;s/\n/__/g s/\(^\|[^A-Za-z0-9]\)_\([^* ]\+\)_\($\|[^A-Za-z0-9]\)/\1\2<\/i>\3/g # 5 special classes. Marked on single words by ^^^^^word^^^^^ s/\^\{5\}\([^ ]\+\)\^\{5\}/\1<\/span>/g s/\^\{4\}\([^ ]\+\)\^\{4\}/\1<\/span>/g s/\^\{3\}\([^ ]\+\)\^\{3\}/\1<\/span>/g s/\^\{2\}\([^ ]\+\)\^\{2\}/\1<\/span>/g s/\^\([^ ]\+\)\^/\1<\/span>/g # ...Escape a character (safe now - restore from unlikely form) s/ ~~~~~~~\(.\)~~~~~~~ /\1/g # Anchors s/\[a \([^ ]\+\)\]/<\/a>/ # Images s/\[image \([^ ]\+\) \([^]]\+\)\]/\2/g # Image hyperlinks s/\[href \([^ ]\+\) img:\([^:]\+\):\([^]]\+\)\]/\3<\/a>/g # Hyperlinks s/\[href \([^ ]\+\) \([^]]\+\)\]/\2<\/a>/g # Inline code blocks s/\%\{4\}/\n/g;s/\n\([^\n]\+\)\n/\1<\/code>/g;s/\n/%%%%/g :ws s/\(.*\) \(.*<\/code>\)/\1\ \ \2/ tws # Paragraph managment 1b # Unordered Lists /^ *\*/{ s/\*// x /
    /{x;s,.*,
  • &
  • ,;x;} /\|/{s,.*,
      ,;x;s,.*,
        \n
      • &
      • ,;x;} x;b } # Blank lines /^$/{ x /\|/{s,.*,

        ,;x;s,^,

        ,;x;} /

          /{s,.*,

          ,;x;s,.*,

        ,;x;} x;b } # Leading spaces preserved :ls s/^\( *\) /\1\ / tls # Use saved paragraph (or break) tag x //{x;s,^,
        ,;x;} //s/.*// x