0
- (?:\n+|\Z)END -"mx") findAllInString:str) each
:
0
+ (?:\n+|\Z)END -"mx") findAllInString:str) each
InReverse:
0
($g_urls setObject:(markdown_EncodeAmpsAndAngles (m groupAtIndex:2)) forKey:(m groupAtIndex:1))
0
(if (!= (m groupAtIndex:3) nil)
0
($g_titles setObject:(m groupAtIndex:3) forKey:(m groupAtIndex:1)))
0
- (str replace
OccurrencesOfString:(m group) withString:-"")))
0
+ (str replace
CharactersInRange:(m range) withString:"")))
0
(function markdown_EncodeCode (str)
0
- )END -"xsge") findAllInString:str) each:(do (m)
0
- (set whole_match (m groupAtIndex:1))
0
- (set alt_text (m groupAtIndex:2))
0
- (set link_id (m groupAtIndex:3))
0
- (set link_id alt_text))
0
- (set alt_text ((regex "\"") replaceWithString:-""" inString:alt_text))
0
- (if (!= ($g_urls objectForKey:link_id) nil)
0
- (set url (markdown_EncodeItalicsAndBolds ($g_urls objectForKey:link_id)))
0
- (set result "<img src=\"#{url}\" alt=\"#{alt_text}\"")
0
- (if (!= ($g_titles valueForKey:link_id) nil)
0
- (then (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds ($g_titles objectForKey:link_id))))
0
- (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
- ;; it seems like this else clause should be included
0
- ;; but it breaks the MarkdownTests regressions
0
- ;; which I think is a bug in Markdown.pl
0
- ;;(else (set result (result stringByAppendingString:" title=\"\""))
0
- (set result (result stringByAppendingString:-" />"))
0
- (else (set result whole_match)))
0
- (str replaceOccurrencesOfString:whole_match withString:result)))
0
+ )END -"xsge") findAllInString:str) eachInReverse:
0
+ (set whole_match (m groupAtIndex:1))
0
+ (set alt_text (m groupAtIndex:2))
0
+ (set link_id (m groupAtIndex:3))
0
+ (set link_id alt_text))
0
+ (set alt_text ((regex "\"") replaceWithString:-""" inString:alt_text))
0
+ (if (!= ($g_urls objectForKey:link_id) nil)
0
+ (set url (markdown_EncodeItalicsAndBolds ($g_urls objectForKey:link_id)))
0
+ (set result "<img src=\"#{url}\" alt=\"#{alt_text}\"")
0
+ (if (!= ($g_titles valueForKey:link_id) nil)
0
+ (then (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds ($g_titles objectForKey:link_id))))
0
+ (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
+ ;; it seems like this else clause should be included
0
+ ;; but it breaks the MarkdownTests regressions
0
+ ;; which I think is a bug in Markdown.pl
0
+ ;;(else (set result (result stringByAppendingString:" title=\"\""))
0
+ (set result (result stringByAppendingString:-" />"))
0
+ (else (set result whole_match)))
0
+ (str replaceOccurrencesOfString:whole_match withString:result)))
0
; Next, handle inline images: 
0
( # wrap whole match in $1
0
- )END -"xsge") findAllInString:str) each:(do (m)
0
- (set whole_match (m groupAtIndex:1))
0
- (set alt_text (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds (m groupAtIndex:2))))
0
- (set url (m groupAtIndex:3))
0
- (set result "<img src=\"#{url}\" alt=\"#{alt_text}\"")
0
- (if (!= (m groupAtIndex:6) nil)
0
- (then (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds (m groupAtIndex:6))))
0
- (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
- (else (set result (result stringByAppendingString:" title=\"\""))))
0
- (set result (result stringByAppendingString:-" />"))
0
- (str replaceOccurrencesOfString:whole_match withString:result)))
0
+ )END -"xsge") findAllInString:str) eachInReverse:
0
+ (set whole_match (m groupAtIndex:1))
0
+ (set alt_text (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds (m groupAtIndex:2))))
0
+ (set url (m groupAtIndex:3))
0
+ (set result "<img src=\"#{url}\" alt=\"#{alt_text}\"")
0
+ (if (!= (m groupAtIndex:6) nil)
0
+ (then (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds (m groupAtIndex:6))))
0
+ (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
+ (else (set result (result stringByAppendingString:" title=\"\""))))
0
+ (set result (result stringByAppendingString:-" />"))
0
+ (str replaceOccurrencesOfString:whole_match withString:result)))
0
(function markdown_DoAnchors (str)
0
- )END -"xsge") findAllInString:str) each:(do (m)
0
- (set whole_match (m groupAtIndex:1))
0
- (set link_text (m groupAtIndex:2))
0
- (set link_id (m groupAtIndex:3))
0
- (if (== link_id -"") (set link_id link_text))
0
- (if (!= ($g_urls valueForKey:link_id) nil)
0
- (set url (markdown_EncodeItalicsAndBolds ($g_urls valueForKey:link_id)))
0
- (set result "<a href=\"#{url}\"")
0
- (if (!= ($g_titles valueForKey:link_id) nil)
0
- (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds ($g_titles valueForKey:link_id))))
0
- (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
- (set result (result stringByAppendingString:-">#{link_text}</a>"))
0
- (else (set result whole_match)))
0
- (str replaceOccurrencesOfString:whole_match withString:result)))
0
+ )END -"xsge") findAllInString:str) eachInReverse:
0
+ (set whole_match (m groupAtIndex:1))
0
+ (set link_text (m groupAtIndex:2))
0
+ (set link_id (m groupAtIndex:3))
0
+ (if (== link_id -"") (set link_id link_text))
0
+ (if (!= ($g_urls valueForKey:link_id) nil)
0
+ (set url (markdown_EncodeItalicsAndBolds ($g_urls valueForKey:link_id)))
0
+ (set result "<a href=\"#{url}\"")
0
+ (if (!= ($g_titles valueForKey:link_id) nil)
0
+ (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds ($g_titles valueForKey:link_id))))
0
+ (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
+ (set result (result stringByAppendingString:-">#{link_text}</a>"))
0
+ (else (set result whole_match)))
0
+ (str replaceOccurrencesOfString:whole_match withString:result)))
0
; Next, inline-style links: [link text](url -"optional title")
0
- )END -"xsge") findAllInString:str) each:(do (m)
0
- (set whole_match (m groupAtIndex:1))
0
- (set link_text (m groupAtIndex:2))
0
- (set url (markdown_EncodeItalicsAndBolds (m groupAtIndex:3)))
0
- (set title (m groupAtIndex:6))
0
- (set result "<a href=\"#{url}\"")
0
- (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds (title))))
0
- (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
- (set result (result stringByAppendingString:-">#{link_text}</a>"))
0
- (str replaceOccurrencesOfString:whole_match withString:result)))
0
+ )END -"xsge") findAllInString:str) eachInReverse:
0
+ (set whole_match (m groupAtIndex:1))
0
+ (set link_text (m groupAtIndex:2))
0
+ (set url (markdown_EncodeItalicsAndBolds (m groupAtIndex:3)))
0
+ (set title (m groupAtIndex:6))
0
+ (set result "<a href=\"#{url}\"")
0
+ (set title (markdown_EncodeQuotes (markdown_EncodeItalicsAndBolds (title))))
0
+ (set result (result stringByAppendingString:" title=\"#{title}\"")))
0
+ (set result (result stringByAppendingString:-">#{link_text}</a>"))
0
+ (str replaceOccurrencesOfString:whole_match withString:result)))
0
(function markdown_UnescapeSpecialChars (str)
0
- (((eregex -"^(.+)[ \t]*\n=+[ \t]*\n+" -"mx") findAllInString:str) each
:
0
+ (((eregex -"^(.+)[ \t]*\n=+[ \t]*\n+" -"mx") findAllInString:str) each
InReverse:
0
(do (m) ; Note the multi-line hack below. -"\n\n" is not turned into new lines.
0
- (str replaceOccurrencesOfString:(m group) withString:"<h1>#{(markdown_RunSpanGamut (m groupAtIndex:1))}</h1>\n\n")))
0
- (((eregex -"^(.+)[ \t]*\n-+[ \t]*\n+" -"mx") findAllInString:str) each:
0
+ (str replaceCharactersInRange:(m range) withString:"<h1>#{(markdown_RunSpanGamut (m groupAtIndex:1))}</h1>\n\n")))
0
+ (((eregex -"^(.+)[ \t]*\n-+[ \t]*\n+" -"mx") findAllInString:str) eachInReverse:
0
- (str replace
OccurrencesOfString:(m group) withString:"<h2>#{(markdown_RunSpanGamut (m groupAtIndex:1))}</h2>\n\n")))
0
+ (str replace
CharactersInRange:(m range) withString:"<h2>#{(markdown_RunSpanGamut (m groupAtIndex:1))}</h2>\n\n")))
0
(.+?) # $2 = Header text
0
\#* # optional closing #'s (not counted)
0
- \n+END -"mx") findAllInString:str) each:(do (m)
0
- (str replaceOccurrencesOfString:(m group)
0
- withString:"<h#{((m groupAtIndex:1) length)}>#{(markdown_RunSpanGamut (m groupAtIndex:2))}</h#{((m groupAtIndex:1) length)}>\n\n"
0
+ \n+END -"mx") findAllInString:str) eachInReverse:
0
+ (str replaceCharactersInRange:(m range)
0
+ withString:"<h#{((m groupAtIndex:1) length)}>#{(markdown_RunSpanGamut (m groupAtIndex:2))}</h#{((m groupAtIndex:1) length)}>\n\n")))
0
(function markdown_Outdent (item)
0
(#{marker_any}) [ \t]+ # list marker = $3
0
((?s:.+?) # list item text = $4
0
- (?= \n* (\z | \2 (#{marker_any}) [ \t]+))END -"mx") findAllInString:list_str) each
:
0
+ (?= \n* (\z | \2 (#{marker_any}) [ \t]+))END -"mx") findAllInString:list_str) each
InReverse:
0
(set item (m groupAtIndex:4))
0
(set leading_line (m groupAtIndex:1))
0
(if (or leading_line ((regex -"\n{2,}") findInString:item))
0
(then (set item (markdown_RunBlockGamut (markdown_Outdent item))))
0
(else (set item (markdown_RunSpanGamut ((markdown_DoLists (markdown_Outdent item)) chomp)))))
0
- (list_str replace
OccurrencesOfString:(m group) withString:"<li>#{item}</li>\n" options:0 range:(list 0 (list_str length)))))
0
+ (list_str replace
CharactersInRange:(m range) withString:"<li>#{item}</li>\n")))
0
(set $g_list_level (- $g_list_level 1))
0
(set whole_list -"(([ ]{0,3}(#{marker_any})[ \t]+)(?s:.+?)(\z|\n{2,}(?=\S)(?![ \t]*#{marker_any}[ \t]+)))")
0
(set result str) ;; default
0
(if (> $g_list_level 0)
0
- (then (((eregex -"^#{whole_list}" -"mx") findAllInString:str) each
:
0
+ (then (((eregex -"^#{whole_list}" -"mx") findAllInString:str) each
InReverse:
0
(set m_list (m groupAtIndex:1))
0
(if ((regex marker_ul) findInString:(m groupAtIndex:3)) (then (set list_type -"ul")) (else (set list_type -"ol")))
0
(set m_list ((regex -"\n{2,}") replaceWithString:"\n\n\n" inString:m_list))
0
(set formattedList (markdown_ProcessListItems m_list marker_any))
0
(set formattedList "<#{list_type}>\n#{formattedList}</#{list_type}>\n")
0
- (result replace
OccurrencesOfString:(m group) withString:formattedList options:0 range:(list 0 (result length))))))
0
+ (result replace
CharactersInRange:(m range) withString:formattedList))))
0
- (((eregex -"(?:(?<=\n\n)|\A\n?)#{whole_list}" -"mx") findAllInString:str) each
:
0
+ (((eregex -"(?:(?<=\n\n)|\A\n?)#{whole_list}" -"mx") findAllInString:str) each
InReverse:
0
(set m_list (m groupAtIndex:1))
0
(if ((regex marker_ul) findInString:(m groupAtIndex:3)) (then (set list_type -"ul")) (else (set list_type -"ol")))
0
(set m_list ((regex -"\n{2,}") replaceWithString:"\n\n\n" inString:m_list))
0
(set formattedList (markdown_ProcessListItems m_list marker_any))
0
(set formattedList "<#{list_type}>\n#{formattedList}</#{list_type}>\n")
0
- (result replaceOccurrencesOfString:(m group) withString:formattedList options:0 range:(list 0 (result length)))))
0
+ (result replaceCharactersInRange:(m range) withString:formattedList)))))
0
(function markdown_Detab (str)
0
((?=^[ ]{0,4}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
0
- END -"mx") findAllInString:str) each
:
0
+ END -"mx") findAllInString:str) each
InReverse:
0
(set codeblock (m groupAtIndex:1))
0
(set codeblock (markdown_Detab (markdown_EncodeCode (markdown_Outdent codeblock))))
0
(set codeblock ((regex -"(\A\n+)|(\s+\z)") replaceWithString:-"" inString:codeblock))
0
- (str replace
OccurrencesOfString:(m group) withString:"\n<pre><code>#{codeblock}\n</code></pre>\n\n")))
0
+ (str replace
CharactersInRange:(m range) withString:"\n<pre><code>#{codeblock}\n</code></pre>\n\n")))
0
(function markdown_DoBlockQuotes (str)
0
(.+\n)* # subsequent consecutive lines
0
- )/mx findAllInString:str) each
:
0
+ )/mx findAllInString:str) each
InReverse:
0
(set bq (m groupAtIndex:1))
0
(set bq (/^[ \t]*>[ \t]?/m replaceWithString:"" inString:bq)) ;; trim one level of quoting
0
(set bq (markdown_RunBlockGamut bq))
0
(set bq (/^/m replaceWithString:" " inString:bq))
0
; These leading spaces screw with <pre> content, so we need to fix that:
0
- (((eregex -"(\s*<pre>.+?</pre>)" -"egsx") findAllInString:bq) each
:
0
+ (((eregex -"(\s*<pre>.+?</pre>)" -"egsx") findAllInString:bq) each
InReverse:
0
- (bq replaceOccurrencesOfString:(m2 group) withString:((eregex -"^ " -"mg") replaceWithString:-"" inString:(m2 groupAtIndex:1)))))
0
- (str replaceOccurrencesOfString:(m group) withString:"<blockquote>\n#{bq}\n</blockquote>\n\n")))
0
+ (bq replaceCharactersInRange:(m2 range) withString:((eregex -"^ " -"mg") replaceWithString:-"" inString:(m2 groupAtIndex:1)))))
0
+ (str replaceCharactersInRange:(m range) withString:"<blockquote>\n#{bq}\n</blockquote>\n\n")))
0
(function markdown_FormParagraphs (str)
Comments
No one has commented yet.