public
Description: Markdown processing with Nu. Use with any Nu or Objective-C project. Created by Grayson Hansard.
Homepage: http://programming.nu/posts/2007/10/10/markdown-in-nu
Clone URL: git://github.com/timburks/numarkdown.git
HTML Tokenization.

HTML Tokenization was broken.
This change set contains some improvements, but not enough.
timburks (author)
Thu Oct 25 22:06:54 -0700 2007
commit  5887f29c9aaac22f29e7db90393ee40f4b3f5a1a
tree    c42791e828b50a0212db0ec8f477108f83c038a7
parent  af40ce8b1ed390a9ced938ff2483ae1348907248
...
186
187
188
189
190
 
 
191
192
193
194
 
195
196
197
198
199
200
201
 
202
203
204
...
244
245
246
247
248
 
 
 
249
250
251
...
559
560
561
 
562
563
564
...
593
594
595
596
 
597
598
 
 
599
600
601
602
603
604
605
 
 
 
 
 
 
 
 
 
 
 
606
 
607
608
 
 
609
610
611
...
186
187
188
 
 
189
190
191
192
193
 
194
195
196
197
198
199
200
 
201
202
203
204
...
244
245
246
 
 
247
248
249
250
251
252
...
560
561
562
563
564
565
566
...
595
596
597
 
598
599
 
600
601
602
603
 
 
 
 
 
604
605
606
607
608
609
610
611
612
613
614
615
616
617
 
618
619
620
621
622
0
@@ -186,19 +186,19 @@
0
      (set nested_tags -"(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>])*>))*>))*>))*>))*>))*>)")
0
      (set match (eregex <<-END
0
     (?s: <! ( -- .*? -- \s* )+ > ) | # comment
0
- (?s: <? .*? ?> ) | # processing instruction
0
- (?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>]|(?:<[a-z/!$](?:[^<>])*>))*>))*>))*>))*>))*>)/ix; # nested tags
0
+ (?s: <\? .*? \?> ) | # processing instruction
0
+ #{nested_tags}
0
     END -"ix"))
0
      ((match findAllInString:str) each:
0
       (do (m)
0
- (set whole_tag (m groupAtIndex:1))
0
+ (set whole_tag (m groupAtIndex:0))
0
           (set r (m range))
0
           (set sec_start (+ (head r) (head (tail r))))
0
           (set tag_start (- sec_start (whole_tag length)))
0
           (if (< $pos tag_start)
0
               (tokens addObject:(list -"text" (str substringWithRange:(list $pos (- tag_start $pos))))))
0
           (tokens addObject:(list -"tag" (m group)))
0
- (set $pos (+ $pos ((m group) length)))))
0
+ (set $pos sec_start)))
0
      (if (< $pos len)
0
          (tokens addObject:(list -"text" (str substringFromIndex:$pos))))
0
      (tokens list))
0
@@ -244,8 +244,9 @@
0
     (.+?)    # $2 = The code block
0
     (?<!`)
0
     \1      # Matching closer
0
- (?!`)END -"sx") findAllInString:str) each:(do (m)
0
- (str replaceOccurrencesOfString:(m group) withString:-"<code>#{(markdown_EncodeCode ((m groupAtIndex:2) strip))}</code>")))
0
+ (?!`)END -"sx") findAllInString:str) each:
0
+ (do (m)
0
+ (str replaceOccurrencesOfString:(m group) withString:-"<code>#{(markdown_EncodeCode ((m groupAtIndex:2) strip))}</code>")))
0
      str)
0
 
0
 (function markdown_EncodeItalicsAndBolds (str)
0
@@ -559,6 +560,7 @@
0
 (function markdown_FormParagraphs (str)
0
      (set str (/(\A\n+)|(\n+\z)/ replaceWithString:"" inString:str))
0
      (set paragraphs (/\n{2,}/ splitString:str))
0
+
0
      ; Wrap <p> tags
0
      (set paragraphs (paragraphs map:(do (paragraph)
0
                                          (unless ($g_html_blocks valueForKey:paragraph)
0
@@ -593,19 +595,28 @@
0
      (-"\`*_{}[]()>#+-.!" each: (do (c) ($g_escape_table setObject:"!!#{(c hash)}!!" forKey:c)))
0
      
0
      (set $g_nested_brackets -"(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[\])*\])*\])*\])*\])*\])*")
0
- ; From running from Markdown.php
0
+ ;; From running from Markdown.php
0
      (set $g_list_level 0)
0
- ; Standardize line endings
0
+
0
+ ;; Standardize line endings
0
      (set str (/\r\n/ replaceWithString:"\n" inString:str)) ; Convert DOS to Unix
0
      (set str (/\r/ replaceWithString:"\n" inString:str)) ; Convert Mac to Unix
0
- (str appendString:"\n\n") ; Make sure text ends with a couple of newlines
0
- (set str (markdown_Detab str)) ; convert tabs into 4 spaces
0
- (set str (/^[ \t]+$/ replaceWithString:"" inString:str)) ; Strip any lines consisting only of spaces and tabs.
0
- (set str (markdown_HashHTMLBlocks str)) ; Turn block-level HTML blocks into hash entries
0
- (set str (markdown_StripLinkDefinitions str)) ; Strip link definitions, store in hashes.
0
+ ;; Make sure text ends with a couple of newlines
0
+ (str appendString:"\n\n")
0
+ ;; Convert tabs into 4 spaces
0
+ (set str (markdown_Detab str))
0
+ ;; Strip any lines consisting only of spaces and tabs.
0
+ (set str (/^[ \t]+$/ replaceWithString:"" inString:str))
0
+ ;; Turn block-level HTML blocks into hash entries
0
+ (set str (markdown_HashHTMLBlocks str))
0
+ ;; Strip link definitions, store in hashes.
0
+ (set str (markdown_StripLinkDefinitions str))
0
+
0
      (set str (markdown_RunBlockGamut str))
0
+
0
      (set str (markdown_UnescapeSpecialChars str))
0
- (unless (eq (str lastCharacter) '\n') (str appendCharacter:'\n'))
0
+
0
+ (str appendCharacter:'\n')
0
      str)
0
 
0
 (class NuMarkdown is NSObject

Comments

    No one has commented yet.