├── Support ├── lib │ └── markdown.rb ├── bin │ ├── redcarpet.rb │ └── html2text.py └── help.markdown ├── Snippets └── Hard linebreak.plist ├── Preferences ├── Disable spell checking for raw.plist ├── Indent: Raw.plist ├── Symbol List: Heading.plist ├── Symbol List: Heading copy.tmPreferences ├── Typing Pairs: Disable _ for Raw.plist └── Miscellaneous.plist ├── README.md ├── Commands ├── Syntax Cheat Sheet.tmCommand └── Preview.tmCommand ├── info.plist ├── Tests ├── test-minimal.markdown └── test.markdown └── Syntaxes └── Markdown Redcarpet.tmLanguage /Support/lib/markdown.rb: -------------------------------------------------------------------------------- 1 | require 'redcarpet' 2 | -------------------------------------------------------------------------------- /Snippets/Hard linebreak.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | 7 | 8 | keyEquivalent 9 | ^ 10 | name 11 | Hard Linebreak 12 | scope 13 | text.html.markdown -meta.disable-markdown 14 | uuid 15 | 4405912F-4AD5-40F8-93B3-A63394036ACA 16 | 17 | 18 | -------------------------------------------------------------------------------- /Support/bin/redcarpet.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Usage: redcarpet [...] 3 | # Convert one or more Markdown files to HTML and write to standard output. With 4 | # no or when is '-', read Markdown source text from standard input. 5 | if ARGV.include?('--help') 6 | File.read(__FILE__).split("\n").grep(/^# /).each do |line| 7 | puts line[2..-1] 8 | end 9 | exit 0 10 | end 11 | 12 | require 'rubygems' 13 | require 'redcarpet' 14 | STDOUT.write(Redcarpet.new(ARGF.read, :safelink, 15 | :autolink, :tables, :strikethrough, :no_intraemphasis, 16 | :fenced_code).to_html) 17 | -------------------------------------------------------------------------------- /Preferences/Disable spell checking for raw.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Spell Checking: Disable 7 | scope 8 | text.html.markdown meta.reference, meta.link.markdown entity.name 9 | settings 10 | 11 | spellChecking 12 | 0 13 | 14 | uuid 15 | C2DBC2F2-D859-4B35-A38E-244927A8447F 16 | 17 | 18 | -------------------------------------------------------------------------------- /Preferences/Indent: Raw.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Indent: Raw Block 7 | scope 8 | markup.raw.block.markdown 9 | settings 10 | 11 | decreaseIndentPattern 12 | ^(.*\*/)?\s*\}[;\s]*$ 13 | increaseIndentPattern 14 | ^.*(\{[^}"']*|\([^)"']*)$ 15 | 16 | uuid 17 | E23C5DD2-9A36-4B4A-9729-2A769A055B92 18 | 19 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TextMate Bundle for GitHub's Redcarpet Markdown 2 | ----------------------------------------------- 3 | 4 | This is pretty hacky. First, make sure you've got `redcarpet` installed with your gem library: 5 | 6 | ``` bash 7 | [sudo] gem install redcarpet 8 | ``` 9 | 10 | Put this bundle in your TextMate bundle directory: 11 | 12 | ``` bash 13 | cd ~/Library/Application\ Support/TextMate/Bundles/ 14 | git clone git://github.com/streeter/markdown-redcarpet.tmbundle.git 15 | ``` 16 | 17 | Reload TextMate and tell it to read `.md` files as Markdown Redcarpet types. 18 | 19 | For more information about GitHub's Redcarpet markdown, [checkout this post][github-flavored-markdown]. 20 | 21 | 22 | [github-flavored-markdown]: http://github.github.com/github-flavored-markdown/ -------------------------------------------------------------------------------- /Preferences/Symbol List: Heading.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Symbol List: Heading 7 | scope 8 | text.html.markdown markup.heading.markdown 9 | settings 10 | 11 | showInSymbolList 12 | 1 13 | symbolTransformation 14 | 15 | s/\s*#*\s*\z//g; # strip trailing space and #'s 16 | s/(?<=#)#/ /g; # change all but first # to m-space 17 | s/^#( *)\s+(.*)/$1$2/; # strip first # and space before title 18 | 19 | 20 | uuid 21 | C02A37C1-E770-472F-A13E-358FF0C6AD89 22 | 23 | 24 | -------------------------------------------------------------------------------- /Preferences/Symbol List: Heading copy.tmPreferences: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Symbol List: Heading copy 7 | scope 8 | text.html.markdown.redcarpet markup.heading.markdown 9 | settings 10 | 11 | showInSymbolList 12 | 1 13 | symbolTransformation 14 | 15 | s/\s*#*\s*\z//g; # strip trailing space and #'s 16 | s/(?<=#)#/ /g; # change all but first # to m-space 17 | s/^#( *)\s+(.*)/$1$2/; # strip first # and space before title 18 | 19 | 20 | uuid 21 | 13D9017E-932F-41F3-BB6E-F8E832F63DB3 22 | 23 | 24 | -------------------------------------------------------------------------------- /Commands/Syntax Cheat Sheet.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | bundleUUID 8 | D99E8C0C-792F-11D9-A212-000D93B3A10E 9 | command 10 | . "$TM_SUPPORT_PATH/lib/webpreview.sh" 11 | html_header "Markdown Cheat Sheet" 12 | redcarpet.rb "$TM_BUNDLE_SUPPORT/help.markdown" 13 | html_footer 14 | input 15 | none 16 | keyEquivalent 17 | ^h 18 | name 19 | Syntax Cheat Sheet 20 | output 21 | showAsHTML 22 | scope 23 | text.html.markdown.redcarpet 24 | uuid 25 | 70120ECC-B129-4479-8A9C-F25D64037039 26 | 27 | 28 | -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | contactEmailRot13 6 | zfurrgf@juvgrsnyyf.bet 7 | contactName 8 | Chris Streeter 9 | description 10 | <a href="http://daringfireball.net/projects/markdown/">Markdown</a> allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML. This bundle provides preview functionality, syntax highlighting, and several useful commands. 11 | name 12 | Markdown Redcarpet 13 | ordering 14 | 15 | A2B854C4-044E-44A6-B28B-5CADA571F780 16 | 70120ECC-B129-4479-8A9C-F25D64037039 17 | BE79A69A-B9F5-4BCD-9068-893496E86663 18 | 13D9017E-932F-41F3-BB6E-F8E832F63DB3 19 | 20 | uuid 21 | 75CC094F-A72F-4782-B60D-34AA1A6C1DF6 22 | 23 | 24 | -------------------------------------------------------------------------------- /Preferences/Typing Pairs: Disable _ for Raw.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Typing Pairs: Disable _ for Raw and Links 7 | scope 8 | text.html.markdown markup.raw, text.html.markdown meta.link 9 | settings 10 | 11 | smartTypingPairs 12 | 13 | 14 | " 15 | " 16 | 17 | 18 | ( 19 | ) 20 | 21 | 22 | { 23 | } 24 | 25 | 26 | [ 27 | ] 28 | 29 | 30 | 31 | 32 | 33 | 34 | ` 35 | ` 36 | 37 | 38 | 39 | uuid 40 | 146B2643-D903-49A8-9586-BE9C509D65B1 41 | 42 | 43 | -------------------------------------------------------------------------------- /Preferences/Miscellaneous.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Typing Pairs: Defaults 7 | scope 8 | text.html.markdown 9 | settings 10 | 11 | smartTypingPairs 12 | 13 | 14 | " 15 | " 16 | 17 | 18 | ( 19 | ) 20 | 21 | 22 | { 23 | } 24 | 25 | 26 | [ 27 | ] 28 | 29 | 30 | 31 | 32 | 33 | 34 | ` 35 | ` 36 | 37 | 38 | _ 39 | _ 40 | 41 | 42 | < 43 | > 44 | 45 | 46 | 47 | uuid 48 | 15E0B3D5-8523-40EF-B767-5AF153FFD11E 49 | 50 | 51 | -------------------------------------------------------------------------------- /Commands/Preview.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | command 8 | . "$TM_SUPPORT_PATH/lib/webpreview.sh" 9 | html_header "Markdown Preview" "${TM_FILENAME:-}" 10 | 11 | if [[ -f "$TM_FILEPATH" ]]; then 12 | echo "<base href='tm-file://${TM_FILEPATH// /%20}'>" 13 | fi 14 | 15 | # Convert to html then make one of the html tags above caret 16 | # into a link that we scroll down to 17 | "${TM_MARKDOWN:-redcarpet.rb}"|"${TM_SMARTYPANTS:-SmartyPants.pl}"|ruby -e ' 18 | lines = STDIN.read.split("\n") 19 | n = [ENV["TM_LINE_NUMBER"].to_i, lines.length].min - 7 20 | 21 | while n > 0 && !lines[n].match(/<(h\d|p|ul|li|blockquote|pre|div|img|code|table|tr)>/i) 22 | n -= 1 23 | end 24 | 25 | if n > 0 && m = lines[n].match(/<(h\d|p|ul|li|blockquote|pre|div|img|code|table|tr)>(.*)$/i) 26 | lines[n] = "<#{m[1]} id=\"scroll_to_here\" >#{m[2]}" 27 | end 28 | 29 | puts lines.join("\n") 30 | puts "\n<script>window.location.hash = \"scroll_to_here\";</script>" 31 | ' 32 | html_footer 33 | input 34 | document 35 | keyEquivalent 36 | ^~@p 37 | name 38 | Preview 39 | output 40 | showAsHTML 41 | scope 42 | text.html.markdown.redcarpet 43 | uuid 44 | A2B854C4-044E-44A6-B28B-5CADA571F780 45 | 46 | 47 | -------------------------------------------------------------------------------- /Tests/test-minimal.markdown: -------------------------------------------------------------------------------- 1 | Inline styles 2 | =============== 3 | 4 | _italic_ 5 | 6 | _italic one_ not italic _italic two_ 7 | 8 | _italic\__ 9 | 10 | _italic \__ 11 | 12 | stuff * not italic* 13 | 14 | *italic__* 15 | 16 | _all _ italic_ 17 | 18 | _italic 19 | end italic_ 20 | 21 | \\\\_italic\\_ 22 | 23 | \\\\_italic\\\_\\\\_ 24 | 25 | \\\\_italic\\_ 26 | 27 | \_ not italic _ 28 | 29 | _not italic _ 30 | 31 | \\\\_not italic\_ 32 | 33 | _not italic \_ 34 | 35 | \\\_not italic\\_ 36 | 37 | _not italic 38 | 39 | not end italic_ 40 | 41 | __bold__ 42 | 43 | **bold\*** 44 | 45 | `raw more` 46 | 47 | ``dobule ` raw`` 48 | 49 | `raw \` more` 50 | 51 | Headings 52 | ================ 53 | 54 | heading 2 55 | ---------- 56 | 57 | ## heading 2 58 | 59 | ### heading 3 60 | 61 | ###### heading 6 62 | 63 | Horizontal lines 64 | ================= 65 | 66 | *** 67 | 68 | * * * 69 | 70 | ___ 71 | 72 | __ __ __ 73 | 74 | - - - 75 | 76 | ---------------- 77 | 78 | 79 | Block formatting 80 | ================ 81 | 82 | Lists 83 | ---------------- 84 | 85 | * This *is a list!* 86 | * This is another list item. 87 | But this one spans *two* lines. 88 | * Another list item with __inline__ formatting 89 | * This one is tricky 90 | * *This is a list* 91 | 92 | Because this should still be a list item. 93 | 94 | 1. This is a list item too 95 | 2. This list is numbered 96 | 97 | 1986\. This shouldn't be a list. 98 | 99 | Code block 100 | --------------- 101 | 102 | asdfsdafasdf 103 | This is code. 104 | Isn't it pretty! 105 | 106 | Quotes 107 | --------------- 108 | 109 | > Here is a quote block 110 | This quote continues on. Line breaking is OK in markdown 111 | > Here it is again 112 | > Lah-di-dah 113 | > I should really match headings in here too: 114 | > ## This is a heading in a block quote 115 | 116 | Things that don't work currently 117 | ================================ -------------------------------------------------------------------------------- /Support/help.markdown: -------------------------------------------------------------------------------- 1 | ## Resources 2 | [daring fireball](http://daringfireball.net/projects/markdown/syntax) 3 | [github](http://github.github.com/github-flavored-markdown/) 4 | 5 | ## Phrase Emphasis ## 6 | 7 | *italic* **bold** 8 | _italic_ __bold__ 9 | 10 | 11 | ## Links ## 12 | 13 | Inline: 14 | 15 | An [example](http://url.com/ "Title") 16 | 17 | Reference-style labels (titles are optional): 18 | 19 | An [example][id]. Then, anywhere 20 | else in the doc, define the link: 21 | 22 | [id]: http://example.com/ "Title" 23 | 24 | 25 | ## Images ## 26 | 27 | Inline (titles are optional): 28 | 29 | ![alt text](/path/img.jpg "Title") 30 | 31 | Reference-style: 32 | 33 | ![alt text][id] 34 | 35 | [id]: /url/to/img.jpg "Title" 36 | 37 | 38 | ## Headers ## 39 | 40 | Setext-style: 41 | 42 | Header 1 43 | ======== 44 | 45 | Header 2 46 | -------- 47 | 48 | atx-style (closing #'s are optional): 49 | 50 | # Header 1 # 51 | 52 | ## Header 2 ## 53 | 54 | ###### Header 6 55 | 56 | 57 | ## Lists ## 58 | 59 | Ordered, without paragraphs: 60 | 61 | 1. Foo 62 | 2. Bar 63 | 64 | Unordered, with paragraphs: 65 | 66 | * A list item. 67 | 68 | With multiple paragraphs. 69 | 70 | * Bar 71 | 72 | You can nest them: 73 | 74 | * Abacus 75 | * answer 76 | * Bubbles 77 | 1. bunk 78 | 2. bupkis 79 | * BELITTLER 80 | 3. burper 81 | * Cunning 82 | 83 | 84 | ## Blockquotes ## 85 | 86 | > Email-style angle brackets 87 | > are used for blockquotes. 88 | 89 | > > And, they can be nested. 90 | 91 | > #### Headers in blockquotes 92 | > 93 | > * You can quote a list. 94 | > * Etc. 95 | 96 | 97 | ## Code Spans ## 98 | 99 | `` spans are delimited 100 | by backticks. 101 | 102 | You can include literal backticks 103 | like `` `this` ``. 104 | 105 | 106 | ## Preformatted Code Blocks ## 107 | 108 | Indent every line of a code block by at least 4 spaces or 1 tab. 109 | 110 | This is a normal paragraph. 111 | 112 | This is a preformatted 113 | code block. 114 | 115 | 116 | ## Horizontal Rules ## 117 | 118 | Three or more dashes or asterisks: 119 | 120 | --- 121 | 122 | * * * 123 | 124 | - - - - 125 | 126 | 127 | ## Manual Line Breaks ## 128 | 129 | End a line with two or more spaces: 130 | 131 | Roses are red, 132 | Violets are blue. 133 | 134 | GitHub Flavored Markdown 135 | ================================ 136 | 137 | *View the [source of this content](http://github.github.com/github-flavored-markdown/sample_content.html).* 138 | 139 | Let's get the whole "linebreak" thing out of the way. The next paragraph contains two phrases separated by a single newline character: 140 | 141 | Roses are red 142 | Violets are blue 143 | 144 | The next paragraph has the same phrases, but now they are separated by two spaces and a newline character: 145 | 146 | Roses are red 147 | Violets are blue 148 | 149 | Oh, and one thing I cannot stand is the mangling of words with multiple underscores in them like perform_complicated_task or do_this_and_do_that_and_another_thing. 150 | 151 | 152 | Math is hard, let's go shopping 153 | ------------------------------- 154 | 155 | In first grade I learned that 5 > 3 and 2 < 7. Maybe some arrows. 1 -> 2 -> 3. 9 <- 8 <- 7. 156 | 157 | Triangles man! a^2 + b^2 = c^2 158 | 159 | We all like making lists 160 | ------------------------ 161 | 162 | The above header should be an H2 tag. Now, for a list of fruits: 163 | 164 | * Red Apples 165 | * Purple Grapes 166 | * Green Kiwifruits 167 | 168 | Let's get crazy: 169 | 170 | 1. This is a list item with two paragraphs. Lorem ipsum dolor 171 | sit amet, consectetuer adipiscing elit. Aliquam hendrerit 172 | mi posuere lectus. 173 | 174 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet 175 | vitae, risus. Donec sit amet nisl. Aliquam semper ipsum 176 | sit amet velit. 177 | 178 | 2. Suspendisse id sem consectetuer libero luctus adipiscing. 179 | 180 | What about some code **in** a list? That's insane, right? 181 | 182 | 1. In Ruby you can map like this: 183 | 184 | ['a', 'b'].map { |x| x.uppercase } 185 | 186 | 2. In Rails, you can do a shortcut: 187 | 188 | ['a', 'b'].map(&:uppercase) 189 | 190 | Some people seem to like definition lists 191 | 192 |
193 |
Lower cost
194 |
The new version of this product costs significantly less than the previous one!
195 |
Easier to use
196 |
We've changed the product so that it's much easier to use!
197 |
198 | 199 | I am a robot 200 | ------------ 201 | 202 | Maybe you want to print `robot` to the console 1000 times. Why not? 203 | 204 | def robot_invasion 205 | puts("robot " * 1000) 206 | end 207 | 208 | You see, that was formatted as code because it's been indented by four spaces. 209 | 210 | How about we throw some angle braces and ampersands in there? 211 | 212 | 215 | 216 | Set in stone 217 | ------------ 218 | 219 | Preformatted blocks are useful for ASCII art: 220 | 221 |
222 |              ,-. 
223 |     ,     ,-.   ,-. 
224 |    / \   (   )-(   ) 
225 |    \ |  ,.>-(   )-< 
226 |     \|,' (   )-(   ) 
227 |      Y ___`-'   `-' 
228 |      |/__/   `-' 
229 |      | 
230 |      | 
231 |      |    -hrr- 
232 |   ___|_____________ 
233 | 
234 | 235 | Playing the blame game 236 | ---------------------- 237 | 238 | If you need to blame someone, the best way to do so is by quoting them: 239 | 240 | > I, at any rate, am convinced that He does not throw dice. 241 | 242 | Or perhaps someone a little less eloquent: 243 | 244 | > I wish you'd have given me this written question ahead of time so I 245 | > could plan for it... I'm sure something will pop into my head here in 246 | > the midst of this press conference, with all the pressure of trying to 247 | > come up with answer, but it hadn't yet... 248 | > 249 | > I don't want to sound like 250 | > I have made no mistakes. I'm confident I have. I just haven't - you 251 | > just put me under the spot here, and maybe I'm not as quick on my feet 252 | > as I should be in coming up with one. 253 | 254 | Table for two 255 | ------------- 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 |
IDNameRank
1Tom Preston-WernerAwesome
2Albert EinsteinNearly as awesome
268 | 269 | Crazy linking action 270 | -------------------- 271 | 272 | I get 10 times more traffic from [Google] [1] than from 273 | [Yahoo] [2] or [MSN] [3]. 274 | 275 | [1]: http://google.com/ "Google" 276 | [2]: http://search.yahoo.com/ "Yahoo Search" 277 | [3]: http://search.msn.com/ "MSN Search" 278 | -------------------------------------------------------------------------------- /Support/bin/html2text.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """html2text: Turn HTML into equivalent Markdown-structured text.""" 3 | __version__ = "2.35" 4 | __author__ = "Aaron Swartz (me@aaronsw.com)" 5 | __copyright__ = "(C) 2004-2008 Aaron Swartz. GNU GPL 3." 6 | __contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes"] 7 | 8 | # TODO: 9 | # Support decoded entities with unifiable. 10 | # Relative URL resolution 11 | 12 | if not hasattr(__builtins__, 'True'): True, False = 1, 0 13 | import re, sys, urllib, htmlentitydefs, codecs, StringIO, types 14 | import sgmllib 15 | sgmllib.charref = re.compile('&#([xX]?[0-9a-fA-F]+)[^0-9a-fA-F]') 16 | 17 | try: from textwrap import wrap 18 | except: pass 19 | 20 | # Use Unicode characters instead of their ascii psuedo-replacements 21 | UNICODE_SNOB = 0 22 | 23 | # Put the links after each paragraph instead of at the end. 24 | LINKS_EACH_PARAGRAPH = 0 25 | 26 | # Wrap long lines at position. 0 for no wrapping. (Requires Python 2.3.) 27 | BODY_WIDTH = 78 28 | 29 | # Don't show internal links (href="#local-anchor") -- corresponding link targets 30 | # won't be visible in the plain text file anyway. 31 | SKIP_INTERNAL_LINKS = False 32 | 33 | ### Entity Nonsense ### 34 | 35 | def name2cp(k): 36 | if k == 'apos': return ord("'") 37 | if hasattr(htmlentitydefs, "name2codepoint"): # requires Python 2.3 38 | return htmlentitydefs.name2codepoint[k] 39 | else: 40 | k = htmlentitydefs.entitydefs[k] 41 | if k.startswith("&#") and k.endswith(";"): return int(k[2:-1]) # not in latin-1 42 | return ord(codecs.latin_1_decode(k)[0]) 43 | 44 | unifiable = {'rsquo':"'", 'lsquo':"'", 'rdquo':'"', 'ldquo':'"', 45 | 'copy':'(C)', 'mdash':'--', 'nbsp':' ', 'rarr':'->', 'larr':'<-', 'middot':'*', 46 | 'ndash':'-', 'oelig':'oe', 'aelig':'ae', 47 | 'agrave':'a', 'aacute':'a', 'acirc':'a', 'atilde':'a', 'auml':'a', 'aring':'a', 48 | 'egrave':'e', 'eacute':'e', 'ecirc':'e', 'euml':'e', 49 | 'igrave':'i', 'iacute':'i', 'icirc':'i', 'iuml':'i', 50 | 'ograve':'o', 'oacute':'o', 'ocirc':'o', 'otilde':'o', 'ouml':'o', 51 | 'ugrave':'u', 'uacute':'u', 'ucirc':'u', 'uuml':'u'} 52 | 53 | unifiable_n = {} 54 | 55 | for k in unifiable.keys(): 56 | unifiable_n[name2cp(k)] = unifiable[k] 57 | 58 | def charref(name): 59 | if name[0] in ['x','X']: 60 | c = int(name[1:], 16) 61 | else: 62 | c = int(name) 63 | 64 | if not UNICODE_SNOB and c in unifiable_n.keys(): 65 | return unifiable_n[c] 66 | else: 67 | return unichr(c) 68 | 69 | def entityref(c): 70 | if not UNICODE_SNOB and c in unifiable.keys(): 71 | return unifiable[c] 72 | else: 73 | try: name2cp(c) 74 | except KeyError: return "&" + c 75 | else: return unichr(name2cp(c)) 76 | 77 | def replaceEntities(s): 78 | s = s.group(1) 79 | if s[0] == "#": 80 | return charref(s[1:]) 81 | else: return entityref(s) 82 | 83 | r_unescape = re.compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));") 84 | def unescape(s): 85 | return r_unescape.sub(replaceEntities, s) 86 | 87 | def fixattrs(attrs): 88 | # Fix bug in sgmllib.py 89 | if not attrs: return attrs 90 | newattrs = [] 91 | for attr in attrs: 92 | newattrs.append((attr[0], unescape(attr[1]))) 93 | return newattrs 94 | 95 | ### End Entity Nonsense ### 96 | 97 | def onlywhite(line): 98 | """Return true if the line does only consist of whitespace characters.""" 99 | for c in line: 100 | if c is not ' ' and c is not ' ': 101 | return c is ' ' 102 | return line 103 | 104 | def optwrap(text): 105 | """Wrap all paragraphs in the provided text.""" 106 | if not BODY_WIDTH: 107 | return text 108 | 109 | assert wrap, "Requires Python 2.3." 110 | result = '' 111 | newlines = 0 112 | for para in text.split("\n"): 113 | if len(para) > 0: 114 | if para[0] is not ' ' and para[0] is not '-' and para[0] is not '*': 115 | for line in wrap(para, BODY_WIDTH): 116 | result += line + "\n" 117 | result += "\n" 118 | newlines = 2 119 | else: 120 | if not onlywhite(para): 121 | result += para + "\n" 122 | newlines = 1 123 | else: 124 | if newlines < 2: 125 | result += "\n" 126 | newlines += 1 127 | return result 128 | 129 | def hn(tag): 130 | if tag[0] == 'h' and len(tag) == 2: 131 | try: 132 | n = int(tag[1]) 133 | if n in range(1, 10): return n 134 | except ValueError: return 0 135 | 136 | class _html2text(sgmllib.SGMLParser): 137 | def __init__(self, out=sys.stdout.write): 138 | sgmllib.SGMLParser.__init__(self) 139 | 140 | if out is None: self.out = self.outtextf 141 | else: self.out = out 142 | self.outtext = u'' 143 | self.quiet = 0 144 | self.p_p = 0 145 | self.outcount = 0 146 | self.start = 1 147 | self.space = 0 148 | self.a = [] 149 | self.astack = [] 150 | self.acount = 0 151 | self.list = [] 152 | self.blockquote = 0 153 | self.pre = 0 154 | self.startpre = 0 155 | self.lastWasNL = 0 156 | self.abbr_title = None # current abbreviation definition 157 | self.abbr_data = None # last inner HTML (for abbr being defined) 158 | self.abbr_list = {} # stack of abbreviations to write later 159 | 160 | def outtextf(self, s): 161 | self.outtext += s 162 | 163 | def close(self): 164 | sgmllib.SGMLParser.close(self) 165 | 166 | self.pbr() 167 | self.o('', 0, 'end') 168 | 169 | return self.outtext 170 | 171 | def handle_charref(self, c): 172 | self.o(charref(c)) 173 | 174 | def handle_entityref(self, c): 175 | self.o(entityref(c)) 176 | 177 | def unknown_starttag(self, tag, attrs): 178 | self.handle_tag(tag, attrs, 1) 179 | 180 | def unknown_endtag(self, tag): 181 | self.handle_tag(tag, None, 0) 182 | 183 | def previousIndex(self, attrs): 184 | """ returns the index of certain set of attributes (of a link) in the 185 | self.a list 186 | 187 | If the set of attributes is not found, returns None 188 | """ 189 | if not attrs.has_key('href'): return None 190 | 191 | i = -1 192 | for a in self.a: 193 | i += 1 194 | match = 0 195 | 196 | if a.has_key('href') and a['href'] == attrs['href']: 197 | if a.has_key('title') or attrs.has_key('title'): 198 | if (a.has_key('title') and attrs.has_key('title') and 199 | a['title'] == attrs['title']): 200 | match = True 201 | else: 202 | match = True 203 | 204 | if match: return i 205 | 206 | def handle_tag(self, tag, attrs, start): 207 | attrs = fixattrs(attrs) 208 | 209 | if hn(tag): 210 | self.p() 211 | if start: self.o(hn(tag)*"#" + ' ') 212 | 213 | if tag in ['p', 'div']: self.p() 214 | 215 | if tag == "br" and start: self.o(" \n") 216 | 217 | if tag == "hr" and start: 218 | self.p() 219 | self.o("* * *") 220 | self.p() 221 | 222 | if tag in ["head", "style", 'script']: 223 | if start: self.quiet += 1 224 | else: self.quiet -= 1 225 | 226 | if tag in ["body"]: 227 | self.quiet = 0 # sites like 9rules.com never close 228 | 229 | if tag == "blockquote": 230 | if start: 231 | self.p(); self.o('> ', 0, 1); self.start = 1 232 | self.blockquote += 1 233 | else: 234 | self.blockquote -= 1 235 | self.p() 236 | 237 | if tag in ['em', 'i', 'u']: self.o("_") 238 | if tag in ['strong', 'b']: self.o("**") 239 | if tag == "code" and not self.pre: self.o('`') #TODO: `` `this` `` 240 | if tag == "abbr": 241 | if start: 242 | attrsD = {} 243 | for (x, y) in attrs: attrsD[x] = y 244 | attrs = attrsD 245 | 246 | self.abbr_title = None 247 | self.abbr_data = '' 248 | if attrs.has_key('title'): 249 | self.abbr_title = attrs['title'] 250 | else: 251 | if self.abbr_title != None: 252 | self.abbr_list[self.abbr_data] = self.abbr_title 253 | self.abbr_title = None 254 | self.abbr_data = '' 255 | 256 | if tag == "a": 257 | if start: 258 | attrsD = {} 259 | for (x, y) in attrs: attrsD[x] = y 260 | attrs = attrsD 261 | if attrs.has_key('href') and not (SKIP_INTERNAL_LINKS and attrs['href'].startswith('#')): 262 | self.astack.append(attrs) 263 | self.o("[") 264 | else: 265 | self.astack.append(None) 266 | else: 267 | if self.astack: 268 | a = self.astack.pop() 269 | if a: 270 | i = self.previousIndex(a) 271 | if i is not None: 272 | a = self.a[i] 273 | else: 274 | self.acount += 1 275 | a['count'] = self.acount 276 | a['outcount'] = self.outcount 277 | self.a.append(a) 278 | self.o("][" + `a['count']` + "]") 279 | 280 | if tag == "img" and start: 281 | attrsD = {} 282 | for (x, y) in attrs: attrsD[x] = y 283 | attrs = attrsD 284 | if attrs.has_key('src'): 285 | attrs['href'] = attrs['src'] 286 | alt = attrs.get('alt', '') 287 | i = self.previousIndex(attrs) 288 | if i is not None: 289 | attrs = self.a[i] 290 | else: 291 | self.acount += 1 292 | attrs['count'] = self.acount 293 | attrs['outcount'] = self.outcount 294 | self.a.append(attrs) 295 | self.o("![") 296 | self.o(alt) 297 | self.o("]["+`attrs['count']`+"]") 298 | 299 | if tag == 'dl' and start: self.p() 300 | if tag == 'dt' and not start: self.pbr() 301 | if tag == 'dd' and start: self.o(' ') 302 | if tag == 'dd' and not start: self.pbr() 303 | 304 | if tag in ["ol", "ul"]: 305 | if start: 306 | self.list.append({'name':tag, 'num':0}) 307 | else: 308 | if self.list: self.list.pop() 309 | 310 | self.p() 311 | 312 | if tag == 'li': 313 | if start: 314 | self.pbr() 315 | if self.list: li = self.list[-1] 316 | else: li = {'name':'ul', 'num':0} 317 | self.o(" "*len(self.list)) #TODO: line up
  1. s > 9 correctly. 318 | if li['name'] == "ul": self.o("* ") 319 | elif li['name'] == "ol": 320 | li['num'] += 1 321 | self.o(`li['num']`+". ") 322 | self.start = 1 323 | else: 324 | self.pbr() 325 | 326 | if tag in ["table", "tr"] and start: self.p() 327 | if tag == 'td': self.pbr() 328 | 329 | if tag == "pre": 330 | if start: 331 | self.startpre = 1 332 | self.pre = 1 333 | else: 334 | self.pre = 0 335 | self.p() 336 | 337 | def pbr(self): 338 | if self.p_p == 0: self.p_p = 1 339 | 340 | def p(self): self.p_p = 2 341 | 342 | def o(self, data, puredata=0, force=0): 343 | if self.abbr_data is not None: self.abbr_data += data 344 | 345 | if not self.quiet: 346 | if puredata and not self.pre: 347 | data = re.sub('\s+', ' ', data) 348 | if data and data[0] == ' ': 349 | self.space = 1 350 | data = data[1:] 351 | if not data and not force: return 352 | 353 | if self.startpre: 354 | #self.out(" :") #TODO: not output when already one there 355 | self.startpre = 0 356 | 357 | bq = (">" * self.blockquote) 358 | if not (force and data and data[0] == ">") and self.blockquote: bq += " " 359 | 360 | if self.pre: 361 | bq += " " 362 | data = data.replace("\n", "\n"+bq) 363 | 364 | if self.start: 365 | self.space = 0 366 | self.p_p = 0 367 | self.start = 0 368 | 369 | if force == 'end': 370 | # It's the end. 371 | self.p_p = 0 372 | self.out("\n") 373 | self.space = 0 374 | 375 | 376 | if self.p_p: 377 | self.out(('\n'+bq)*self.p_p) 378 | self.space = 0 379 | 380 | if self.space: 381 | if not self.lastWasNL: self.out(' ') 382 | self.space = 0 383 | 384 | if self.a and ((self.p_p == 2 and LINKS_EACH_PARAGRAPH) or force == "end"): 385 | if force == "end": self.out("\n") 386 | 387 | newa = [] 388 | for link in self.a: 389 | if self.outcount > link['outcount']: 390 | self.out(" ["+`link['count']`+"]: " + link['href']) #TODO: base href 391 | if link.has_key('title'): self.out(" ("+link['title']+")") 392 | self.out("\n") 393 | else: 394 | newa.append(link) 395 | 396 | if self.a != newa: self.out("\n") # Don't need an extra line when nothing was done. 397 | 398 | self.a = newa 399 | 400 | if self.abbr_list and force == "end": 401 | for abbr, definition in self.abbr_list.items(): 402 | self.out(" *[" + abbr + "]: " + definition + "\n") 403 | 404 | self.p_p = 0 405 | self.out(data) 406 | self.lastWasNL = data and data[-1] == '\n' 407 | self.outcount += 1 408 | 409 | def handle_data(self, data): 410 | if r'\/script>' in data: self.quiet -= 1 411 | self.o(data, 1) 412 | 413 | def unknown_decl(self, data): pass 414 | 415 | def wrapwrite(text): sys.stdout.write(text.encode('utf8')) 416 | 417 | def html2text_file(html, out=wrapwrite): 418 | h = _html2text(out) 419 | h.feed(html) 420 | h.feed("") 421 | return h.close() 422 | 423 | def html2text(html): 424 | return optwrap(html2text_file(html, None)) 425 | 426 | if __name__ == "__main__": 427 | if sys.argv[1:]: 428 | arg = sys.argv[1] 429 | if arg.startswith('http://'): 430 | j = urllib.urlopen(arg) 431 | try: 432 | from feedparser import _getCharacterEncoding as enc 433 | except ImportError: 434 | enc = lambda x, y: ('utf-8', 1) 435 | text = j.read() 436 | encoding = enc(j.headers, text)[0] 437 | if encoding == 'us-ascii': encoding = 'utf-8' 438 | data = text.decode(encoding) 439 | 440 | else: 441 | encoding = 'utf8' 442 | if len(sys.argv) > 2: 443 | encoding = sys.argv[2] 444 | data = open(arg, 'r').read().decode(encoding) 445 | else: 446 | data = sys.stdin.read().decode('utf8') 447 | wrapwrite(html2text(data)) 448 | 449 | -------------------------------------------------------------------------------- /Tests/test.markdown: -------------------------------------------------------------------------------- 1 | Markdown: Syntax 2 | ================ 3 | 4 | 11 | 12 | * [Overview](#overview) 13 | * [Philosophy](#philosophy) 14 | * [Inline HTML](#html) 15 | * [Automatic Escaping for Special Characters](#autoescape) 16 | * [Block Elements](#block) 17 | * [Paragraphs and Line Breaks](#p) 18 | * [Headers](#header) 19 | * [Blockquotes](#blockquote) 20 | * [Lists](#list) 21 | * [Code Blocks](#precode) 22 | * [Horizontal Rules](#hr) 23 | * [Span Elements](#span) 24 | * [Links](#link) 25 | * [Emphasis](#em) 26 | * [Code](#code) 27 | * [Images](#img) 28 | * [Miscellaneous](#misc) 29 | * [Backslash Escapes](#backslash) 30 | * [Automatic Links](#autolink) 31 | 32 | 33 | 34 | **Note:** This document is itself written using Markdown; you 35 | can [see the source for it by adding '.text' to the URL][src]. 36 | 37 | [src]: /projects/markdown/syntax.text 38 | 39 | * * * 40 | 41 |

    Overview

    42 | 43 |

    Philosophy

    44 | 45 | Markdown is intended to be as easy-to-read and easy-to-write as is feasible. 46 | 47 | Readability, however, is emphasized above all else. A Markdown-formatted 48 | document should be publishable as-is, as plain text, without looking 49 | like it's been marked up with tags or formatting instructions. While 50 | Markdown's syntax has been influenced by several existing text-to-HTML 51 | filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4], 52 | [Grutatext] [5], and [EtText] [6] -- the single biggest source of 53 | inspiration for Markdown's syntax is the format of plain text email. 54 | 55 | [1]: http://docutils.sourceforge.net/mirror/setext.html 56 | [2]: http://www.aaronsw.com/2002/atx/ 57 | [3]: http://textism.com/tools/textile/ 58 | [4]: http://docutils.sourceforge.net/rst.html 59 | [5]: http://www.triptico.com/software/grutatxt.html 60 | [6]: http://ettext.taint.org/doc/ 61 | 62 | To this end, Markdown's syntax is comprised entirely of punctuation 63 | characters, which punctuation characters have been carefully chosen so 64 | as to look like what they mean. E.g., asterisks around a word actually 65 | look like \*emphasis\*. Markdown lists look like, well, lists. Even 66 | blockquotes look like quoted passages of text, assuming you've ever 67 | used email. 68 | 69 | 70 |

    Inline HTML

    71 | 72 | Markdown's syntax is intended for one purpose: to be used as a 73 | format for *writing* for the web. 74 | 75 | Markdown is not a replacement for HTML, or even close to it. Its 76 | syntax is very small, corresponding only to a very small subset of 77 | HTML tags. The idea is *not* to create a syntax that makes it easier 78 | to insert HTML tags. In my opinion, HTML tags are already easy to 79 | insert. The idea for Markdown is to make it easy to read, write, and 80 | edit prose. HTML is a *publishing* format; Markdown is a *writing* 81 | format. Thus, Markdown's formatting syntax only addresses issues that 82 | can be conveyed in plain text. 83 | 84 | For any markup that is not covered by Markdown's syntax, you simply 85 | use HTML itself. There's no need to preface it or delimit it to 86 | indicate that you're switching from Markdown to HTML; you just use 87 | the tags. 88 | 89 | The only restrictions are that block-level HTML elements -- e.g. `
    `, 90 | ``, `
    `, `

    `, etc. -- must be separated from surrounding 91 | content by blank lines, and the start and end tags of the block should 92 | not be indented with tabs or spaces. Markdown is smart enough not 93 | to add extra (unwanted) `

    ` tags around HTML block-level tags. 94 | 95 | For example, to add an HTML table to a Markdown article: 96 | 97 | This is a regular paragraph. 98 | 99 |

    100 | 101 | 102 | 103 |
    Foo
    104 | 105 | This is another regular paragraph. 106 | 107 | Note that Markdown formatting syntax is not processed within block-level 108 | HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an 109 | HTML block. 110 | 111 | Span-level HTML tags -- e.g. ``, ``, or `` -- can be 112 | used anywhere in a Markdown paragraph, list item, or header. If you 113 | want, you can even use HTML tags instead of Markdown formatting; e.g. if 114 | you'd prefer to use HTML `` or `` tags instead of Markdown's 115 | link or image syntax, go right ahead. 116 | 117 | Unlike block-level HTML tags, Markdown syntax *is* processed within 118 | span-level tags. 119 | 120 | 121 |

    Automatic Escaping for Special Characters

    122 | 123 | In HTML, there are two characters that demand special treatment: `<` 124 | and `&`. Left angle brackets are used to start tags; ampersands are 125 | used to denote HTML entities. If you want to use them as literal 126 | characters, you must escape them as entities, e.g. `<`, and 127 | `&`. 128 | 129 | Ampersands in particular are bedeviling for web writers. If you want to 130 | write about 'AT&T', you need to write '`AT&T`'. You even need to 131 | escape ampersands within URLs. Thus, if you want to link to: 132 | 133 | http://images.google.com/images?num=30&q=larry+bird 134 | 135 | you need to encode the URL as: 136 | 137 | http://images.google.com/images?num=30&q=larry+bird 138 | 139 | in your anchor tag `href` attribute. Needless to say, this is easy to 140 | forget, and is probably the single most common source of HTML validation 141 | errors in otherwise well-marked-up web sites. 142 | 143 | Markdown allows you to use these characters naturally, taking care of 144 | all the necessary escaping for you. If you use an ampersand as part of 145 | an HTML entity, it remains unchanged; otherwise it will be translated 146 | into `&`. 147 | 148 | So, if you want to include a copyright symbol in your article, you can write: 149 | 150 | © 151 | 152 | and Markdown will leave it alone. But if you write: 153 | 154 | AT&T 155 | 156 | Markdown will translate it to: 157 | 158 | AT&T 159 | 160 | Similarly, because Markdown supports [inline HTML](#html), if you use 161 | angle brackets as delimiters for HTML tags, Markdown will treat them as 162 | such. But if you write: 163 | 164 | 4 < 5 165 | 166 | Markdown will translate it to: 167 | 168 | 4 < 5 169 | 170 | However, inside Markdown code spans and blocks, angle brackets and 171 | ampersands are *always* encoded automatically. This makes it easy to use 172 | Markdown to write about HTML code. (As opposed to raw HTML, which is a 173 | terrible format for writing about HTML syntax, because every single `<` 174 | and `&` in your example code needs to be escaped.) 175 | 176 | 177 | * * * 178 | 179 | 180 |

    Block Elements

    181 | 182 | 183 |

    Paragraphs and Line Breaks

    184 | 185 | A paragraph is simply one or more consecutive lines of text, separated 186 | by one or more blank lines. (A blank line is any line that looks like a 187 | blank line -- a line containing nothing but spaces or tabs is considered 188 | blank.) Normal paragraphs should not be intended with spaces or tabs. 189 | 190 | The implication of the "one or more consecutive lines of text" rule is 191 | that Markdown supports "hard-wrapped" text paragraphs. This differs 192 | significantly from most other text-to-HTML formatters (including Movable 193 | Type's "Convert Line Breaks" option) which translate every line break 194 | character in a paragraph into a `
    ` tag. 195 | 196 | When you *do* want to insert a `
    ` break tag using Markdown, you 197 | end a line with two or more spaces, then type return. 198 | 199 | Yes, this takes a tad more effort to create a `
    `, but a simplistic 200 | "every line break is a `
    `" rule wouldn't work for Markdown. 201 | Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l] 202 | work best -- and look better -- when you format them with hard breaks. 203 | 204 | [bq]: #blockquote 205 | [l]: #list 206 | 207 | 208 | 209 | 210 | 211 | Markdown supports two styles of headers, [Setext] [1] and [atx] [2]. 212 | 213 | Setext-style headers are "underlined" using equal signs (for first-level 214 | headers) and dashes (for second-level headers). For example: 215 | 216 | This is an H1 217 | ============= 218 | 219 | This is an H2 220 | ------------- 221 | 222 | Any number of underlining `=`'s or `-`'s will work. 223 | 224 | Atx-style headers use 1-6 hash characters at the start of the line, 225 | corresponding to header levels 1-6. For example: 226 | 227 | # This is an H1 228 | 229 | ## This is an H2 230 | 231 | ###### This is an H6 232 | 233 | Optionally, you may "close" atx-style headers. This is purely 234 | cosmetic -- you can use this if you think it looks better. The 235 | closing hashes don't even need to match the number of hashes 236 | used to open the header. (The number of opening hashes 237 | determines the header level.) : 238 | 239 | # This is an H1 # 240 | 241 | ## This is an H2 ## 242 | 243 | ### This is an H3 ###### 244 | 245 | 246 |

    Blockquotes

    247 | 248 | Markdown uses email-style `>` characters for blockquoting. If you're 249 | familiar with quoting passages of text in an email message, then you 250 | know how to create a blockquote in Markdown. It looks best if you hard 251 | wrap the text and put a `>` before every line: 252 | 253 | > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, 254 | > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. 255 | > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 256 | > 257 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse 258 | > id sem consectetuer libero luctus adipiscing. 259 | 260 | Markdown allows you to be lazy and only put the `>` before the first 261 | line of a hard-wrapped paragraph: 262 | 263 | > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, 264 | consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. 265 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 266 | 267 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse 268 | id sem consectetuer libero luctus adipiscing. 269 | 270 | Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by 271 | adding additional levels of `>`: 272 | 273 | > This is the first level of quoting. 274 | > 275 | > > This is nested blockquote. 276 | > 277 | > Back to the first level. 278 | 279 | Blockquotes can contain other Markdown elements, including headers, lists, 280 | and code blocks: 281 | 282 | > ## This is a header. 283 | > 284 | > 1. This is the first list item. 285 | > 2. This is the second list item. 286 | > 287 | > Here's some example code: 288 | > 289 | > return shell_exec("echo $input | $markdown_script"); 290 | 291 | Any decent text editor should make email-style quoting easy. For 292 | example, with BBEdit, you can make a selection and choose Increase 293 | Quote Level from the Text menu. 294 | 295 | 296 |

    Lists

    297 | 298 | Markdown supports ordered (numbered) and unordered (bulleted) lists. 299 | 300 | Unordered lists use asterisks, pluses, and hyphens -- interchangably 301 | -- as list markers: 302 | 303 | * Red 304 | * Green 305 | * Blue 306 | 307 | is equivalent to: 308 | 309 | + Red 310 | + Green 311 | + Blue 312 | 313 | and: 314 | 315 | - Red 316 | - Green 317 | - Blue 318 | 319 | Ordered lists use numbers followed by periods: 320 | 321 | 1. Bird 322 | 2. McHale 323 | 3. Parish 324 | 325 | It's important to note that the actual numbers you use to mark the 326 | list have no effect on the HTML output Markdown produces. The HTML 327 | Markdown produces from the above list is: 328 | 329 |
      330 |
    1. Bird
    2. 331 |
    3. McHale
    4. 332 |
    5. Parish
    6. 333 |
    334 | 335 | If you instead wrote the list in Markdown like this: 336 | 337 | 1. Bird 338 | 1. McHale 339 | 1. Parish 340 | 341 | or even: 342 | 343 | 3. Bird 344 | 1. McHale 345 | 8. Parish 346 | 347 | you'd get the exact same HTML output. The point is, if you want to, 348 | you can use ordinal numbers in your ordered Markdown lists, so that 349 | the numbers in your source match the numbers in your published HTML. 350 | But if you want to be lazy, you don't have to. 351 | 352 | If you do use lazy list numbering, however, you should still start the 353 | list with the number 1. At some point in the future, Markdown may support 354 | starting ordered lists at an arbitrary number. 355 | 356 | List markers typically start at the left margin, but may be indented by 357 | up to three spaces. List markers must be followed by one or more spaces 358 | or a tab. 359 | 360 | To make lists look nice, you can wrap items with hanging indents: 361 | 362 | * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 363 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, 364 | viverra nec, fringilla in, laoreet vitae, risus. 365 | * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 366 | Suspendisse id sem consectetuer libero luctus adipiscing. 367 | 368 | But if you want to be lazy, you don't have to: 369 | 370 | * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 371 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, 372 | viverra nec, fringilla in, laoreet vitae, risus. 373 | * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 374 | Suspendisse id sem consectetuer libero luctus adipiscing. 375 | 376 | If list items are separated by blank lines, Markdown will wrap the 377 | items in `

    ` tags in the HTML output. For example, this input: 378 | 379 | * Bird 380 | * Magic 381 | 382 | will turn into: 383 | 384 |

      385 |
    • Bird
    • 386 |
    • Magic
    • 387 |
    388 | 389 | But this: 390 | 391 | * Bird 392 | 393 | * Magic 394 | 395 | will turn into: 396 | 397 |
      398 |
    • Bird

    • 399 |
    • Magic

    • 400 |
    401 | 402 | List items may consist of multiple paragraphs. Each subsequent 403 | paragraph in a list item must be intended by either 4 spaces 404 | or one tab: 405 | 406 | 1. This is a list item with two paragraphs. Lorem ipsum dolor 407 | sit amet, consectetuer adipiscing elit. Aliquam hendrerit 408 | mi posuere lectus. 409 | 410 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet 411 | vitae, risus. Donec sit amet nisl. Aliquam semper ipsum 412 | sit amet velit. 413 | 414 | 2. Suspendisse id sem consectetuer libero luctus adipiscing. 415 | 416 | It looks nice if you indent every line of the subsequent 417 | paragraphs, but here again, Markdown will allow you to be 418 | lazy: 419 | 420 | * This is a list item with two paragraphs. 421 | 422 | This is the second paragraph in the list item. You're 423 | only required to indent the first line. Lorem ipsum dolor 424 | sit amet, consectetuer adipiscing elit. 425 | 426 | * Another item in the same list. 427 | 428 | To put a blockquote within a list item, the blockquote's `>` 429 | delimiters need to be indented: 430 | 431 | * A list item with a blockquote: 432 | 433 | > This is a blockquote 434 | > inside a list item. 435 | 436 | To put a code block within a list item, the code block needs 437 | to be indented *twice* -- 8 spaces or two tabs: 438 | 439 | * A list item with a code block: 440 | 441 | 442 | 443 | 444 | It's worth noting that it's possible to trigger an ordered list by 445 | accident, by writing something like this: 446 | 447 | 1986. What a great season. 448 | 449 | In other words, a *number-period-space* sequence at the beginning of a 450 | line. To avoid this, you can backslash-escape the period: 451 | 452 | 1986\. What a great season. 453 | 454 | 455 | 456 |

    Code Blocks

    457 | 458 | Pre-formatted code blocks are used for writing about programming or 459 | markup source code. Rather than forming normal paragraphs, the lines 460 | of a code block are interpreted literally. Markdown wraps a code block 461 | in both `
    ` and `` tags.
    462 | 
    463 | To produce a code block in Markdown, simply indent every line of the
    464 | block by at least 4 spaces or 1 tab. For example, given this input:
    465 | 
    466 |     This is a normal paragraph:
    467 | 
    468 |         This is a code block.
    469 | 
    470 | Markdown will generate:
    471 | 
    472 |     

    This is a normal paragraph:

    473 | 474 |
    This is a code block.
    475 |     
    476 | 477 | One level of indentation -- 4 spaces or 1 tab -- is removed from each 478 | line of the code block. For example, this: 479 | 480 | Here is an example of AppleScript: 481 | 482 | tell application "Foo" 483 | beep 484 | end tell 485 | 486 | will turn into: 487 | 488 |

    Here is an example of AppleScript:

    489 | 490 |
    tell application "Foo"
    491 |         beep
    492 |     end tell
    493 |     
    494 | 495 | A code block continues until it reaches a line that is not indented 496 | (or the end of the article). 497 | 498 | Within a code block, ampersands (`&`) and angle brackets (`<` and `>`) 499 | are automatically converted into HTML entities. This makes it very 500 | easy to include example HTML source code using Markdown -- just paste 501 | it and indent it, and Markdown will handle the hassle of encoding the 502 | ampersands and angle brackets. For example, this: 503 | 504 | 507 | 508 | will turn into: 509 | 510 |
    <div class="footer">
    511 |         &copy; 2004 Foo Corporation
    512 |     </div>
    513 |     
    514 | 515 | Regular Markdown syntax is not processed within code blocks. E.g., 516 | asterisks are just literal asterisks within a code block. This means 517 | it's also easy to use Markdown to write about Markdown's own syntax. 518 | 519 | 520 | 521 |

    Horizontal Rules

    522 | 523 | You can produce a horizontal rule tag (`
    `) by placing three or 524 | more hyphens, asterisks, or underscores on a line by themselves. If you 525 | wish, you may use spaces between the hyphens or asterisks. Each of the 526 | following lines will produce a horizontal rule: 527 | 528 | * * * 529 | 530 | *** 531 | 532 | ***** 533 | 534 | - - - 535 | 536 | --------------------------------------- 537 | 538 | _ _ _ 539 | 540 | 541 | * * * 542 | 543 |

    Span Elements

    544 | 545 | 546 | 547 | Markdown supports two style of links: *inline* and *reference*. 548 | 549 | In both styles, the link text is delimited by [square brackets]. 550 | 551 | To create an inline link, use a set of regular parentheses immediately 552 | after the link text's closing square bracket. Inside the parentheses, 553 | put the URL where you want the link to point, along with an *optional* 554 | title for the link, surrounded in quotes. For example: 555 | 556 | This is [an example](http://example.com/ "Title") inline link. 557 | 558 | [This link](http://example.net/) has no title attribute. 559 | 560 | Will produce: 561 | 562 |

    This is 563 | an example inline link.

    564 | 565 |

    This link has no 566 | title attribute.

    567 | 568 | If you're referring to a local resource on the same server, you can 569 | use relative paths: 570 | 571 | See my [About](/about/) page for details. 572 | 573 | Reference-style links use a second set of square brackets, inside 574 | which you place a label of your choosing to identify the link: 575 | 576 | This is [an example][id] reference-style link. 577 | 578 | You can optionally use a space to separate the sets of brackets: 579 | 580 | This is [an example] [id] reference-style link. 581 | 582 | Then, anywhere in the document, you define your link label like this, 583 | on a line by itself: 584 | 585 | [id]: http://example.com/ "Optional Title Here" 586 | 587 | That is: 588 | 589 | * Square brackets containing the link identifier (optionally 590 | indented from the left margin using spaces or tabs); 591 | * followed by a colon; 592 | * followed by one or more spaces (or tabs); 593 | * followed by the URL for the link; 594 | * optionally followed by a title attribute for the link, enclosed 595 | in double or single quotes. 596 | 597 | The link URL may, optionally, be surrounded by angle brackets: 598 | 599 | [id]: "Optional Title Here" 600 | 601 | You can put the title attribute on the next line and use extra spaces 602 | or tabs for padding, which tends to look better with longer URLs: 603 | 604 | [id]: http://example.com/longish/path/to/resource/here 605 | "Optional Title Here" 606 | 607 | Link definitions are only used for creating links during Markdown 608 | processing, and are stripped from your document in the HTML output. 609 | 610 | Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are *not* case sensitive. E.g. these two links: 611 | 612 | [link text][a] 613 | [link text][A] 614 | 615 | are equivalent. 616 | 617 | The *implicit link name* shortcut allows you to omit the name of the 618 | link, in which case the link text itself is used as the name. 619 | Just use an empty set of square brackets -- e.g., to link the word 620 | "Google" to the google.com web site, you could simply write: 621 | 622 | [Google][] 623 | 624 | And then define the link: 625 | 626 | [Google]: http://google.com/ 627 | 628 | Because link names may contain spaces, this shortcut even works for 629 | multiple words in the link text: 630 | 631 | Visit [Daring Fireball][] for more information. 632 | 633 | And then define the link: 634 | 635 | [Daring Fireball]: http://daringfireball.net/ 636 | 637 | Link definitions can be placed anywhere in your Markdown document. I 638 | tend to put them immediately after each paragraph in which they're 639 | used, but if you want, you can put them all at the end of your 640 | document, sort of like footnotes. 641 | 642 | Here's an example of reference links in action: 643 | 644 | I get 10 times more traffic from [Google] [1] than from 645 | [Yahoo] [2] or [MSN] [3]. 646 | 647 | [1]: http://google.com/ "Google" 648 | [2]: http://search.yahoo.com/ "Yahoo Search" 649 | [3]: http://search.msn.com/ "MSN Search" 650 | 651 | Using the implicit link name shortcut, you could instead write: 652 | 653 | I get 10 times more traffic from [Google][] than from 654 | [Yahoo][] or [MSN][]. 655 | 656 | [google]: http://google.com/ "Google" 657 | [yahoo]: http://search.yahoo.com/ "Yahoo Search" 658 | [msn]: http://search.msn.com/ "MSN Search" 659 | 660 | Both of the above examples will produce the following HTML output: 661 | 662 |

    I get 10 times more traffic from Google than from 664 | Yahoo 665 | or MSN.

    666 | 667 | For comparison, here is the same paragraph written using 668 | Markdown's inline link style: 669 | 670 | I get 10 times more traffic from [Google](http://google.com/ "Google") 671 | than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or 672 | [MSN](http://search.msn.com/ "MSN Search"). 673 | 674 | The point of reference-style links is not that they're easier to 675 | write. The point is that with reference-style links, your document 676 | source is vastly more readable. Compare the above examples: using 677 | reference-style links, the paragraph itself is only 81 characters 678 | long; with inline-style links, it's 176 characters; and as raw HTML, 679 | it's 234 characters. In the raw HTML, there's more markup than there 680 | is text. 681 | 682 | With Markdown's reference-style links, a source document much more 683 | closely resembles the final output, as rendered in a browser. By 684 | allowing you to move the markup-related metadata out of the paragraph, 685 | you can add links without interrupting the narrative flow of your 686 | prose. 687 | 688 | 689 |

    Emphasis

    690 | 691 | Markdown treats asterisks (`*`) and underscores (`_`) as indicators of 692 | emphasis. Text wrapped with one `*` or `_` will be wrapped with an 693 | HTML `` tag; double `*`'s or `_`'s will be wrapped with an HTML 694 | `` tag. E.g., this input: 695 | 696 | *single asterisks* 697 | 698 | _single underscores_ 699 | 700 | **double asterisks** 701 | 702 | __double underscores__ 703 | 704 | will produce: 705 | 706 | single asterisks 707 | 708 | single underscores 709 | 710 | double asterisks 711 | 712 | double underscores 713 | 714 | You can use whichever style you prefer; the lone restriction is that 715 | the same character must be used to open and close an emphasis span. 716 | 717 | Emphasis can be used in the middle of a word: 718 | 719 | un*fucking*believable 720 | 721 | But if you surround an `*` or `_` with spaces, it'll be treated as a 722 | literal asterisk or underscore. 723 | 724 | To produce a literal asterisk or underscore at a position where it 725 | would otherwise be used as an emphasis delimiter, you can backslash 726 | escape it: 727 | 728 | \\*this text is surrounded by literal asterisks\\* 729 | 730 | 731 | 732 |

    Code

    733 | 734 | To indicate a span of code, wrap it with backtick quotes (`` ` ``). 735 | Unlike a pre-formatted code block, a code span indicates code within a 736 | normal paragraph. For example: 737 | 738 | Use the `printf()` function. 739 | 740 | will produce: 741 | 742 |

    Use the printf() function.

    743 | 744 | To include a literal backtick character within a code span, you can 745 | backslash escape it: 746 | 747 | `There is a literal backtick (\`) here.` 748 | 749 | Or, if you prefer, you can use multiple backticks as the opening and 750 | closing delimiters: 751 | 752 | ``There is a literal backtick (`) here.`` 753 | 754 | Both of the previous two examples will produce this: 755 | 756 |

    There is a literal backtick (`) here.

    757 | 758 | With a code span, ampersands and angle brackets are encoded as HTML 759 | entities automatically, which makes it easy to include example HTML 760 | tags. Markdown will turn this: 761 | 762 | Please don't use any `` tags. 763 | 764 | into: 765 | 766 |

    Please don't use any <blink> tags.

    767 | 768 | You can write this: 769 | 770 | `—` is the decimal-encoded equivalent of `—`. 771 | 772 | to produce: 773 | 774 |

    &#8212; is the decimal-encoded 775 | equivalent of &mdash;.

    776 | 777 | 778 | 779 |

    Images

    780 | 781 | Admittedly, it's fairly difficult to devise a "natural" syntax for 782 | placing images into a plain text document format. 783 | 784 | Markdown uses an image syntax that is intended to resemble the syntax 785 | for links, allowing for two styles: *inline* and *reference*. 786 | 787 | Inline image syntax looks like this: 788 | 789 | ![Alt text](/path/to/img.jpg) 790 | 791 | ![Alt text](/path/to/img.jpg "Optional title") 792 | 793 | That is: 794 | 795 | * An exclamation mark: `!`; 796 | * followed by a set of square brackets, containing the `alt` 797 | attribute text for the image; 798 | * followed by a set of parentheses, containing the URL or path to 799 | the image, and an optional `title` attribute enclosed in double 800 | or single quotes. 801 | 802 | Reference-style image syntax looks like this: 803 | 804 | ![Alt text][id] 805 | 806 | Where "id" is the name of a defined image reference. Image references 807 | are defined using syntax identical to link references: 808 | 809 | [id]: url/to/image "Optional title attribute" 810 | 811 | As of this writing, Markdown has no syntax for specifying the 812 | dimensions of an image; if this is important to you, you can simply 813 | use regular HTML `` tags. 814 | 815 | 816 | * * * 817 | 818 | 819 |

    Miscellaneous

    820 | 821 | 822 | 823 | Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this: 824 | 825 | 826 | 827 | Markdown will turn this into: 828 | 829 | http://example.com/ 830 | 831 | Automatic links for email addresses work similarly, except that 832 | Markdown will also perform a bit of randomized decimal and hex 833 | entity-encoding to help obscure your address from address-harvesting 834 | spambots. For example, Markdown will turn this: 835 | 836 | 837 | 838 | into something like this: 839 | 840 | address@exa 843 | mple.com 844 | 845 | which will render in a browser as a clickable link to "address@example.com". 846 | 847 | (This sort of entity-encoding trick will indeed fool many, if not 848 | most, address-harvesting bots, but it definitely won't fool all of 849 | them. It's better than nothing, but an address published in this way 850 | will probably eventually start receiving spam.) 851 | 852 | 853 | 854 |

    Backslash Escapes

    855 | 856 | Markdown allows you to use backslash escapes to generate literal 857 | characters which would otherwise have special meaning in Markdown's 858 | formatting syntax. For example, if you wanted to surround a word with 859 | literal asterisks (instead of an HTML `` tag), you can backslashes 860 | before the asterisks, like this: 861 | 862 | \*literal asterisks\* 863 | 864 | Markdown provides backslash escapes for the following characters: 865 | 866 | \ backslash 867 | ` backtick 868 | * asterisk 869 | _ underscore 870 | {} curly braces 871 | [] square brackets 872 | () parentheses 873 | # hash mark 874 | . dot 875 | ! exclamation mark 876 | 877 | -------------------------------------------------------------------------------- /Syntaxes/Markdown Redcarpet.tmLanguage: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | fileTypes 6 | 7 | mdown 8 | markdown 9 | markdn 10 | md 11 | 12 | foldingStartMarker 13 | (?x) 14 | (<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?> 15 | |<!--(?!.*-->) 16 | |\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/))) 17 | ) 18 | foldingStopMarker 19 | (?x) 20 | (</(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)> 21 | |^\s*--> 22 | |(^|\s)\} 23 | ) 24 | keyEquivalent 25 | ^~M 26 | name 27 | Markdown Redcarpet 28 | patterns 29 | 30 | 31 | begin 32 | (?x)^ 33 | (?= [ ]{,3}>. 34 | | ([ ]{4}|\t)(?!$) 35 | | [#]{1,6}\s*+ 36 | | [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$ 37 | ) 38 | comment 39 | 40 | We could also use an empty end match and set 41 | applyEndPatternLast, but then we must be sure that the begin 42 | pattern will only match stuff matched by the sub-patterns. 43 | 44 | end 45 | (?x)^ 46 | (?! [ ]{,3}>. 47 | | ([ ]{4}|\t) 48 | | [#]{1,6}\s*+ 49 | | [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$ 50 | ) 51 | name 52 | meta.block-level.markdown 53 | patterns 54 | 55 | 56 | include 57 | #block_quote 58 | 59 | 60 | include 61 | #block_raw 62 | 63 | 64 | include 65 | #heading 66 | 67 | 68 | include 69 | #separator 70 | 71 | 72 | 73 | 74 | begin 75 | ^[ ]{0,3}([*+-])(?=\s) 76 | captures 77 | 78 | 1 79 | 80 | name 81 | punctuation.definition.list_item.markdown 82 | 83 | 84 | end 85 | ^(?=\S) 86 | name 87 | markup.list.unnumbered.markdown 88 | patterns 89 | 90 | 91 | include 92 | #list-paragraph 93 | 94 | 95 | 96 | 97 | begin 98 | ^[ ]{0,3}([0-9]+\.)(?=\s) 99 | captures 100 | 101 | 1 102 | 103 | name 104 | punctuation.definition.list_item.markdown 105 | 106 | 107 | end 108 | ^(?=\S) 109 | name 110 | markup.list.numbered.markdown 111 | patterns 112 | 113 | 114 | include 115 | #list-paragraph 116 | 117 | 118 | 119 | 120 | begin 121 | ^(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b)(?!.*?</\1>) 122 | comment 123 | 124 | Markdown formatting is disabled inside block-level tags. 125 | 126 | end 127 | (?<=^</\1>$\n) 128 | name 129 | meta.disable-markdown 130 | patterns 131 | 132 | 133 | include 134 | text.html.basic 135 | 136 | 137 | 138 | 139 | begin 140 | ^(?=<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b) 141 | comment 142 | Same rule but for one line disables. 143 | end 144 | $\n? 145 | name 146 | meta.disable-markdown 147 | patterns 148 | 149 | 150 | include 151 | text.html.basic 152 | 153 | 154 | 155 | 156 | captures 157 | 158 | 1 159 | 160 | name 161 | punctuation.definition.constant.markdown 162 | 163 | 10 164 | 165 | name 166 | punctuation.definition.string.end.markdown 167 | 168 | 11 169 | 170 | name 171 | string.other.link.description.title.markdown 172 | 173 | 12 174 | 175 | name 176 | punctuation.definition.string.begin.markdown 177 | 178 | 13 179 | 180 | name 181 | punctuation.definition.string.end.markdown 182 | 183 | 2 184 | 185 | name 186 | constant.other.reference.link.markdown 187 | 188 | 3 189 | 190 | name 191 | punctuation.definition.constant.markdown 192 | 193 | 4 194 | 195 | name 196 | punctuation.separator.key-value.markdown 197 | 198 | 5 199 | 200 | name 201 | punctuation.definition.link.markdown 202 | 203 | 6 204 | 205 | name 206 | markup.underline.link.markdown 207 | 208 | 7 209 | 210 | name 211 | punctuation.definition.link.markdown 212 | 213 | 8 214 | 215 | name 216 | string.other.link.description.title.markdown 217 | 218 | 9 219 | 220 | name 221 | punctuation.definition.string.begin.markdown 222 | 223 | 224 | match 225 | (?x: 226 | \s* # Leading whitespace 227 | (\[)(.+?)(\])(:) # Reference name 228 | [ \t]* # Optional whitespace 229 | (<?)(\S+?)(>?) # The url 230 | [ \t]* # Optional whitespace 231 | (?: 232 | ((\().+?(\))) # Match title in quotes… 233 | | ((").+?(")) # or in parens. 234 | )? # Title is optional 235 | \s* # Optional whitespace 236 | $ 237 | ) 238 | name 239 | meta.link.reference.def.markdown 240 | 241 | 242 | begin 243 | ^(?=\S)(?![=-]{3,}(?=$)) 244 | end 245 | ^(?:\s*$|(?=[ ]{,3}>.))|(?=[ \t]*\n)(?<=^===|^====|=====|^---|^----|-----)[ \t]*\n|(?=^#) 246 | name 247 | meta.paragraph.markdown 248 | patterns 249 | 250 | 251 | include 252 | #inline 253 | 254 | 255 | include 256 | text.html.basic 257 | 258 | 259 | captures 260 | 261 | 1 262 | 263 | name 264 | punctuation.definition.heading.markdown 265 | 266 | 267 | match 268 | ^(={3,})(?=[ \t]*$) 269 | name 270 | markup.heading.1.markdown 271 | 272 | 273 | captures 274 | 275 | 1 276 | 277 | name 278 | punctuation.definition.heading.markdown 279 | 280 | 281 | match 282 | ^(-{3,})(?=[ \t]*$) 283 | name 284 | markup.heading.2.markdown 285 | 286 | 287 | 288 | 289 | repository 290 | 291 | ampersand 292 | 293 | comment 294 | 295 | Markdown will convert this for us. We match it so that the 296 | HTML grammar will not mark it up as invalid. 297 | 298 | match 299 | &(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);) 300 | name 301 | meta.other.valid-ampersand.markdown 302 | 303 | block_quote 304 | 305 | begin 306 | \G[ ]{,3}(>)(?!$)[ ]? 307 | beginCaptures 308 | 309 | 1 310 | 311 | name 312 | punctuation.definition.blockquote.markdown 313 | 314 | 315 | comment 316 | 317 | We terminate the block quote when seeing an empty line, a 318 | separator or a line with leading > characters. The latter is 319 | to “reset” the quote level for quoted lines. 320 | 321 | end 322 | (?x)^ 323 | (?= \s*$ 324 | | [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$ 325 | | [ ]{,3}>. 326 | ) 327 | name 328 | markup.quote.markdown 329 | patterns 330 | 331 | 332 | begin 333 | (?x)\G 334 | (?= [ ]{,3}>. 335 | ) 336 | end 337 | ^ 338 | patterns 339 | 340 | 341 | include 342 | #block_quote 343 | 344 | 345 | 346 | 347 | applyEndPatternLast 348 | 1 349 | begin 350 | (?x)\G 351 | (?= ([ ]{4}|\t) 352 | | [#]{1,6}\s*+ 353 | | [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$ 354 | ) 355 | end 356 | ^ 357 | patterns 358 | 359 | 360 | include 361 | #block_raw 362 | 363 | 364 | include 365 | #heading 366 | 367 | 368 | include 369 | #separator 370 | 371 | 372 | 373 | 374 | begin 375 | (?x)\G 376 | (?! $ 377 | | [ ]{,3}>. 378 | | ([ ]{4}|\t) 379 | | [#]{1,6}\s*+ 380 | | [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$ 381 | ) 382 | end 383 | $|(?<=\n) 384 | patterns 385 | 386 | 387 | include 388 | #inline 389 | 390 | 391 | 392 | 393 | 394 | block_raw 395 | 396 | match 397 | \G([ ]{4}|\t).*$\n? 398 | name 399 | markup.raw.block.markdown 400 | 401 | bold 402 | 403 | begin 404 | (?x) 405 | (\*\*|__)(?=\S) # Open 406 | (?= 407 | ( 408 | <[^>]*+> # HTML tags 409 | | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw> 410 | # Raw 411 | | \\[\\`*_{}\[\]()#.!+\->]?+ # Escapes 412 | | \[ 413 | ( 414 | (?<square> # Named group 415 | [^\[\]\\] # Match most chars 416 | | \\. # Escaped chars 417 | | \[ \g<square>*+ \] # Nested brackets 418 | )*+ 419 | \] 420 | ( 421 | ( # Reference Link 422 | [ ]? # Optional space 423 | \[[^\]]*+\] # Ref name 424 | ) 425 | | ( # Inline Link 426 | \( # Opening paren 427 | [ \t]*+ # Optional whtiespace 428 | <?(.*?)>? # URL 429 | [ \t]*+ # Optional whtiespace 430 | ( # Optional Title 431 | (?<title>['"]) 432 | (.*?) 433 | \k<title> 434 | )? 435 | \) 436 | ) 437 | ) 438 | ) 439 | | (?!(?<=\S)\1). # Everything besides 440 | # style closer 441 | )++ 442 | (?<=\S)\1 # Close 443 | ) 444 | 445 | captures 446 | 447 | 1 448 | 449 | name 450 | punctuation.definition.bold.markdown 451 | 452 | 453 | end 454 | (?<=\S)(\1) 455 | name 456 | markup.bold.markdown 457 | patterns 458 | 459 | 460 | applyEndPatternLast 461 | 1 462 | begin 463 | (?=<[^>]*?>) 464 | end 465 | (?<=>) 466 | patterns 467 | 468 | 469 | include 470 | text.html.basic 471 | 472 | 473 | 474 | 475 | include 476 | #escape 477 | 478 | 479 | include 480 | #ampersand 481 | 482 | 483 | include 484 | #bracket 485 | 486 | 487 | include 488 | #raw 489 | 490 | 491 | include 492 | #italic 493 | 494 | 495 | include 496 | #image-inline 497 | 498 | 499 | include 500 | #link-inline 501 | 502 | 503 | include 504 | #link-inet 505 | 506 | 507 | include 508 | #link-email 509 | 510 | 511 | include 512 | #image-ref 513 | 514 | 515 | include 516 | #link-ref-literal 517 | 518 | 519 | include 520 | #link-ref 521 | 522 | 523 | 524 | bracket 525 | 526 | comment 527 | 528 | Markdown will convert this for us. We match it so that the 529 | HTML grammar will not mark it up as invalid. 530 | 531 | match 532 | <(?![a-z/?\$!]) 533 | name 534 | meta.other.valid-bracket.markdown 535 | 536 | escape 537 | 538 | match 539 | \\[-`*_#+.!(){}\[\]\\>] 540 | name 541 | constant.character.escape.markdown 542 | 543 | heading 544 | 545 | begin 546 | \G(#{1,6})(?!#)\s*(?=\S) 547 | captures 548 | 549 | 1 550 | 551 | name 552 | punctuation.definition.heading.markdown 553 | 554 | 555 | contentName 556 | entity.name.section.markdown 557 | end 558 | \s*(#*)$\n? 559 | name 560 | markup.heading.markdown 561 | patterns 562 | 563 | 564 | include 565 | #inline 566 | 567 | 568 | 569 | image-inline 570 | 571 | captures 572 | 573 | 1 574 | 575 | name 576 | punctuation.definition.string.begin.markdown 577 | 578 | 10 579 | 580 | name 581 | string.other.link.description.title.markdown 582 | 583 | 11 584 | 585 | name 586 | punctuation.definition.string.markdown 587 | 588 | 12 589 | 590 | name 591 | punctuation.definition.string.markdown 592 | 593 | 13 594 | 595 | name 596 | string.other.link.description.title.markdown 597 | 598 | 14 599 | 600 | name 601 | punctuation.definition.string.markdown 602 | 603 | 15 604 | 605 | name 606 | punctuation.definition.string.markdown 607 | 608 | 16 609 | 610 | name 611 | punctuation.definition.metadata.markdown 612 | 613 | 2 614 | 615 | name 616 | string.other.link.description.markdown 617 | 618 | 3 619 | 620 | name 621 | punctuation.definition.string.end.markdown 622 | 623 | 5 624 | 625 | name 626 | invalid.illegal.whitespace.markdown 627 | 628 | 6 629 | 630 | name 631 | punctuation.definition.metadata.markdown 632 | 633 | 7 634 | 635 | name 636 | punctuation.definition.link.markdown 637 | 638 | 8 639 | 640 | name 641 | markup.underline.link.image.markdown 642 | 643 | 9 644 | 645 | name 646 | punctuation.definition.link.markdown 647 | 648 | 649 | match 650 | (?x: 651 | \! # Images start with ! 652 | (\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\]) 653 | # Match the link text. 654 | ([ ])? # Space not allowed 655 | (\() # Opening paren for url 656 | (<?)(\S+?)(>?) # The url 657 | [ \t]* # Optional whitespace 658 | (?: 659 | ((\().+?(\))) # Match title in parens… 660 | | ((").+?(")) # or in quotes. 661 | )? # Title is optional 662 | \s* # Optional whitespace 663 | (\)) 664 | ) 665 | name 666 | meta.image.inline.markdown 667 | 668 | image-ref 669 | 670 | captures 671 | 672 | 1 673 | 674 | name 675 | punctuation.definition.string.begin.markdown 676 | 677 | 2 678 | 679 | name 680 | string.other.link.description.markdown 681 | 682 | 4 683 | 684 | name 685 | punctuation.definition.string.begin.markdown 686 | 687 | 5 688 | 689 | name 690 | punctuation.definition.constant.markdown 691 | 692 | 6 693 | 694 | name 695 | constant.other.reference.link.markdown 696 | 697 | 7 698 | 699 | name 700 | punctuation.definition.constant.markdown 701 | 702 | 703 | match 704 | \!(\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(.*?)(\]) 705 | name 706 | meta.image.reference.markdown 707 | 708 | inline 709 | 710 | patterns 711 | 712 | 713 | include 714 | #escape 715 | 716 | 717 | include 718 | #ampersand 719 | 720 | 721 | include 722 | #bracket 723 | 724 | 725 | include 726 | #raw 727 | 728 | 729 | include 730 | #bold 731 | 732 | 733 | include 734 | #italic 735 | 736 | 737 | include 738 | #line-break 739 | 740 | 741 | include 742 | #image-inline 743 | 744 | 745 | include 746 | #link-inline 747 | 748 | 749 | include 750 | #link-inet 751 | 752 | 753 | include 754 | #link-email 755 | 756 | 757 | include 758 | #image-ref 759 | 760 | 761 | include 762 | #link-ref-literal 763 | 764 | 765 | include 766 | #link-ref 767 | 768 | 769 | 770 | italic 771 | 772 | begin 773 | (?x) 774 | (\*|_)(?=\S) # Open 775 | (?= 776 | ( 777 | <[^>]*+> # HTML tags 778 | | (?<raw>`+)([^`]|(?!(?<!`)\k<raw>(?!`))`)*+\k<raw> 779 | # Raw 780 | | \\[\\`*_{}\[\]()#.!+\->]?+ # Escapes 781 | | \[ 782 | ( 783 | (?<square> # Named group 784 | [^\[\]\\] # Match most chars 785 | | \\. # Escaped chars 786 | | \[ \g<square>*+ \] # Nested brackets 787 | )*+ 788 | \] 789 | ( 790 | ( # Reference Link 791 | [ ]? # Optional space 792 | \[[^\]]*+\] # Ref name 793 | ) 794 | | ( # Inline Link 795 | \( # Opening paren 796 | [ \t]*+ # Optional whtiespace 797 | <?(.*?)>? # URL 798 | [ \t]*+ # Optional whtiespace 799 | ( # Optional Title 800 | (?<title>['"]) 801 | (.*?) 802 | \k<title> 803 | )? 804 | \) 805 | ) 806 | ) 807 | ) 808 | | \1\1 # Must be bold closer 809 | | (?!(?<=\S)\1). # Everything besides 810 | # style closer 811 | )++ 812 | (?<=\S)\1 # Close 813 | ) 814 | 815 | captures 816 | 817 | 1 818 | 819 | name 820 | punctuation.definition.italic.markdown 821 | 822 | 823 | end 824 | (?<=\S)(\1)((?!\1)|(?=\1\1)) 825 | name 826 | markup.italic.markdown 827 | patterns 828 | 829 | 830 | applyEndPatternLast 831 | 1 832 | begin 833 | (?=<[^>]*?>) 834 | end 835 | (?<=>) 836 | patterns 837 | 838 | 839 | include 840 | text.html.basic 841 | 842 | 843 | 844 | 845 | include 846 | #escape 847 | 848 | 849 | include 850 | #ampersand 851 | 852 | 853 | include 854 | #bracket 855 | 856 | 857 | include 858 | #raw 859 | 860 | 861 | include 862 | #bold 863 | 864 | 865 | include 866 | #image-inline 867 | 868 | 869 | include 870 | #link-inline 871 | 872 | 873 | include 874 | #link-inet 875 | 876 | 877 | include 878 | #link-email 879 | 880 | 881 | include 882 | #image-ref 883 | 884 | 885 | include 886 | #link-ref-literal 887 | 888 | 889 | include 890 | #link-ref 891 | 892 | 893 | 894 | line-break 895 | 896 | match 897 | {2,}$ 898 | name 899 | meta.dummy.line-break 900 | 901 | link-email 902 | 903 | captures 904 | 905 | 1 906 | 907 | name 908 | punctuation.definition.link.markdown 909 | 910 | 2 911 | 912 | name 913 | markup.underline.link.markdown 914 | 915 | 4 916 | 917 | name 918 | punctuation.definition.link.markdown 919 | 920 | 921 | match 922 | (<)((?:mailto:)?[-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(>) 923 | name 924 | meta.link.email.lt-gt.markdown 925 | 926 | link-inet 927 | 928 | captures 929 | 930 | 1 931 | 932 | name 933 | punctuation.definition.link.markdown 934 | 935 | 2 936 | 937 | name 938 | markup.underline.link.markdown 939 | 940 | 3 941 | 942 | name 943 | punctuation.definition.link.markdown 944 | 945 | 946 | match 947 | (<)((?:https?|ftp)://.*?)(>) 948 | name 949 | meta.link.inet.markdown 950 | 951 | link-inline 952 | 953 | captures 954 | 955 | 1 956 | 957 | name 958 | punctuation.definition.string.begin.markdown 959 | 960 | 10 961 | 962 | name 963 | string.other.link.description.title.markdown 964 | 965 | 11 966 | 967 | name 968 | punctuation.definition.string.begin.markdown 969 | 970 | 12 971 | 972 | name 973 | punctuation.definition.string.end.markdown 974 | 975 | 13 976 | 977 | name 978 | string.other.link.description.title.markdown 979 | 980 | 14 981 | 982 | name 983 | punctuation.definition.string.begin.markdown 984 | 985 | 15 986 | 987 | name 988 | punctuation.definition.string.end.markdown 989 | 990 | 16 991 | 992 | name 993 | punctuation.definition.metadata.markdown 994 | 995 | 2 996 | 997 | name 998 | string.other.link.title.markdown 999 | 1000 | 4 1001 | 1002 | name 1003 | punctuation.definition.string.end.markdown 1004 | 1005 | 5 1006 | 1007 | name 1008 | invalid.illegal.whitespace.markdown 1009 | 1010 | 6 1011 | 1012 | name 1013 | punctuation.definition.metadata.markdown 1014 | 1015 | 7 1016 | 1017 | name 1018 | punctuation.definition.link.markdown 1019 | 1020 | 8 1021 | 1022 | name 1023 | markup.underline.link.markdown 1024 | 1025 | 9 1026 | 1027 | name 1028 | punctuation.definition.link.markdown 1029 | 1030 | 1031 | match 1032 | (?x: 1033 | (\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\]) 1034 | # Match the link text. 1035 | ([ ])? # Space not allowed 1036 | (\() # Opening paren for url 1037 | (<?)(.*?)(>?) # The url 1038 | [ \t]* # Optional whitespace 1039 | (?: 1040 | ((\().+?(\))) # Match title in parens… 1041 | | ((").+?(")) # or in quotes. 1042 | )? # Title is optional 1043 | \s* # Optional whitespace 1044 | (\)) 1045 | ) 1046 | name 1047 | meta.link.inline.markdown 1048 | 1049 | link-ref 1050 | 1051 | captures 1052 | 1053 | 1 1054 | 1055 | name 1056 | punctuation.definition.string.begin.markdown 1057 | 1058 | 2 1059 | 1060 | name 1061 | string.other.link.title.markdown 1062 | 1063 | 4 1064 | 1065 | name 1066 | punctuation.definition.string.end.markdown 1067 | 1068 | 5 1069 | 1070 | name 1071 | punctuation.definition.constant.begin.markdown 1072 | 1073 | 6 1074 | 1075 | name 1076 | constant.other.reference.link.markdown 1077 | 1078 | 7 1079 | 1080 | name 1081 | punctuation.definition.constant.end.markdown 1082 | 1083 | 1084 | match 1085 | (\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)([^\]]*+)(\]) 1086 | name 1087 | meta.link.reference.markdown 1088 | 1089 | link-ref-literal 1090 | 1091 | captures 1092 | 1093 | 1 1094 | 1095 | name 1096 | punctuation.definition.string.begin.markdown 1097 | 1098 | 2 1099 | 1100 | name 1101 | string.other.link.title.markdown 1102 | 1103 | 4 1104 | 1105 | name 1106 | punctuation.definition.string.end.markdown 1107 | 1108 | 5 1109 | 1110 | name 1111 | punctuation.definition.constant.begin.markdown 1112 | 1113 | 6 1114 | 1115 | name 1116 | punctuation.definition.constant.end.markdown 1117 | 1118 | 1119 | match 1120 | (\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(\]) 1121 | name 1122 | meta.link.reference.literal.markdown 1123 | 1124 | list-paragraph 1125 | 1126 | patterns 1127 | 1128 | 1129 | begin 1130 | \G\s+(?=\S) 1131 | end 1132 | ^\s*$ 1133 | name 1134 | meta.paragraph.list.markdown 1135 | patterns 1136 | 1137 | 1138 | include 1139 | #inline 1140 | 1141 | 1142 | captures 1143 | 1144 | 1 1145 | 1146 | name 1147 | punctuation.definition.list_item.markdown 1148 | 1149 | 1150 | comment 1151 | Match the list punctuation 1152 | match 1153 | ^\s*([*+-]|[0-9]+\.) 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | raw 1160 | 1161 | captures 1162 | 1163 | 1 1164 | 1165 | name 1166 | punctuation.definition.raw.markdown 1167 | 1168 | 3 1169 | 1170 | name 1171 | punctuation.definition.raw.markdown 1172 | 1173 | 1174 | match 1175 | (`+)([^`]|(?!(?<!`)\1(?!`))`)*+(\1) 1176 | name 1177 | markup.raw.inline.markdown 1178 | 1179 | separator 1180 | 1181 | match 1182 | \G[ ]{,3}([-*_])([ ]{,2}\1){2,}[ \t]*$\n? 1183 | name 1184 | meta.separator.markdown 1185 | 1186 | 1187 | scopeName 1188 | text.html.markdown.redcarpet 1189 | uuid 1190 | BE79A69A-B9F5-4BCD-9068-893496E86663 1191 | 1192 | 1193 | --------------------------------------------------------------------------------