You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
12 KiB

5 months ago
  1. <!doctype html>
  2. <title>CodeMirror: Markdown mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="../../addon/edit/continuelist.js"></script>
  8. <script src="../xml/xml.js"></script>
  9. <script src="../javascript/javascript.js"></script>
  10. <script src="markdown.js"></script>
  11. <style>
  12. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  13. .cm-s-default .cm-trailing-space-a:before,
  14. .cm-s-default .cm-trailing-space-b:before {position: absolute; content: "\00B7"; color: #777;}
  15. .cm-s-default .cm-trailing-space-new-line:before {position: absolute; content: "\21B5"; color: #777;}
  16. </style>
  17. <div id=nav>
  18. <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
  19. <ul>
  20. <li><a href="../../index.html">Home</a>
  21. <li><a href="../../doc/manual.html">Manual</a>
  22. <li><a href="https://github.com/codemirror/codemirror5">Code</a>
  23. </ul>
  24. <ul>
  25. <li><a href="../index.html">Language modes</a>
  26. <li><a class=active href="#">Markdown</a>
  27. </ul>
  28. </div>
  29. <article>
  30. <h2>Markdown mode</h2>
  31. <form><textarea id="code" name="code">
  32. Markdown: Basics
  33. ================
  34. &lt;ul id="ProjectSubmenu"&gt;
  35. &lt;li&gt;&lt;a href="/projects/markdown/" title="Markdown Project Page"&gt;Main&lt;/a&gt;&lt;/li&gt;
  36. &lt;li&gt;&lt;a class="selected" title="Markdown Basics"&gt;Basics&lt;/a&gt;&lt;/li&gt;
  37. &lt;li&gt;&lt;a href="/projects/markdown/syntax" title="Markdown Syntax Documentation"&gt;Syntax&lt;/a&gt;&lt;/li&gt;
  38. &lt;li&gt;&lt;a href="/projects/markdown/license" title="Pricing and License Information"&gt;License&lt;/a&gt;&lt;/li&gt;
  39. &lt;li&gt;&lt;a href="/projects/markdown/dingus" title="Online Markdown Web Form"&gt;Dingus&lt;/a&gt;&lt;/li&gt;
  40. &lt;/ul&gt;
  41. Getting the Gist of Markdown's Formatting Syntax
  42. ------------------------------------------------
  43. This page offers a brief overview of what it's like to use Markdown.
  44. The [syntax page] [s] provides complete, detailed documentation for
  45. every feature, but Markdown should be very easy to pick up simply by
  46. looking at a few examples of it in action. The examples on this page
  47. are written in a before/after style, showing example syntax and the
  48. HTML output produced by Markdown.
  49. It's also helpful to simply try Markdown out; the [Dingus] [d] is a
  50. web application that allows you type your own Markdown-formatted text
  51. and translate it to XHTML.
  52. **Note:** This document is itself written using Markdown; you
  53. can [see the source for it by adding '.text' to the URL] [src].
  54. [s]: /projects/markdown/syntax "Markdown Syntax"
  55. [d]: /projects/markdown/dingus "Markdown Dingus"
  56. [src]: /projects/markdown/basics.text
  57. ## Paragraphs, Headers, Blockquotes ##
  58. A paragraph is simply one or more consecutive lines of text, separated
  59. by one or more blank lines. (A blank line is any line that looks like
  60. a blank line -- a line containing nothing but spaces or tabs is
  61. considered blank.) Normal paragraphs should not be indented with
  62. spaces or tabs.
  63. Markdown offers two styles of headers: *Setext* and *atx*.
  64. Setext-style headers for `&lt;h1&gt;` and `&lt;h2&gt;` are created by
  65. "underlining" with equal signs (`=`) and hyphens (`-`), respectively.
  66. To create an atx-style header, you put 1-6 hash marks (`#`) at the
  67. beginning of the line -- the number of hashes equals the resulting
  68. HTML header level.
  69. Blockquotes are indicated using email-style '`&gt;`' angle brackets.
  70. Markdown:
  71. A First Level Header
  72. ====================
  73. A Second Level Header
  74. ---------------------
  75. Now is the time for all good men to come to
  76. the aid of their country. This is just a
  77. regular paragraph.
  78. The quick brown fox jumped over the lazy
  79. dog's back.
  80. ### Header 3
  81. &gt; This is a blockquote.
  82. &gt;
  83. &gt; This is the second paragraph in the blockquote.
  84. &gt;
  85. &gt; ## This is an H2 in a blockquote
  86. Output:
  87. &lt;h1&gt;A First Level Header&lt;/h1&gt;
  88. &lt;h2&gt;A Second Level Header&lt;/h2&gt;
  89. &lt;p&gt;Now is the time for all good men to come to
  90. the aid of their country. This is just a
  91. regular paragraph.&lt;/p&gt;
  92. &lt;p&gt;The quick brown fox jumped over the lazy
  93. dog's back.&lt;/p&gt;
  94. &lt;h3&gt;Header 3&lt;/h3&gt;
  95. &lt;blockquote&gt;
  96. &lt;p&gt;This is a blockquote.&lt;/p&gt;
  97. &lt;p&gt;This is the second paragraph in the blockquote.&lt;/p&gt;
  98. &lt;h2&gt;This is an H2 in a blockquote&lt;/h2&gt;
  99. &lt;/blockquote&gt;
  100. ### Phrase Emphasis ###
  101. Markdown uses asterisks and underscores to indicate spans of emphasis.
  102. Markdown:
  103. Some of these words *are emphasized*.
  104. Some of these words _are emphasized also_.
  105. Use two asterisks for **strong emphasis**.
  106. Or, if you prefer, __use two underscores instead__.
  107. Output:
  108. &lt;p&gt;Some of these words &lt;em&gt;are emphasized&lt;/em&gt;.
  109. Some of these words &lt;em&gt;are emphasized also&lt;/em&gt;.&lt;/p&gt;
  110. &lt;p&gt;Use two asterisks for &lt;strong&gt;strong emphasis&lt;/strong&gt;.
  111. Or, if you prefer, &lt;strong&gt;use two underscores instead&lt;/strong&gt;.&lt;/p&gt;
  112. ## Lists ##
  113. Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`,
  114. `+`, and `-`) as list markers. These three markers are
  115. interchangeable; this:
  116. * Candy.
  117. * Gum.
  118. * Booze.
  119. this:
  120. + Candy.
  121. + Gum.
  122. + Booze.
  123. and this:
  124. - Candy.
  125. - Gum.
  126. - Booze.
  127. all produce the same output:
  128. &lt;ul&gt;
  129. &lt;li&gt;Candy.&lt;/li&gt;
  130. &lt;li&gt;Gum.&lt;/li&gt;
  131. &lt;li&gt;Booze.&lt;/li&gt;
  132. &lt;/ul&gt;
  133. Ordered (numbered) lists use regular numbers, followed by periods, as
  134. list markers:
  135. 1. Red
  136. 2. Green
  137. 3. Blue
  138. Output:
  139. &lt;ol&gt;
  140. &lt;li&gt;Red&lt;/li&gt;
  141. &lt;li&gt;Green&lt;/li&gt;
  142. &lt;li&gt;Blue&lt;/li&gt;
  143. &lt;/ol&gt;
  144. If you put blank lines between items, you'll get `&lt;p&gt;` tags for the
  145. list item text. You can create multi-paragraph list items by indenting
  146. the paragraphs by 4 spaces or 1 tab:
  147. * A list item.
  148. With multiple paragraphs.
  149. * Another item in the list.
  150. Output:
  151. &lt;ul&gt;
  152. &lt;li&gt;&lt;p&gt;A list item.&lt;/p&gt;
  153. &lt;p&gt;With multiple paragraphs.&lt;/p&gt;&lt;/li&gt;
  154. &lt;li&gt;&lt;p&gt;Another item in the list.&lt;/p&gt;&lt;/li&gt;
  155. &lt;/ul&gt;
  156. ### Links ###
  157. Markdown supports two styles for creating links: *inline* and
  158. *reference*. With both styles, you use square brackets to delimit the
  159. text you want to turn into a link.
  160. Inline-style links use parentheses immediately after the link text.
  161. For example:
  162. This is an [example link](http://example.com/).
  163. Output:
  164. &lt;p&gt;This is an &lt;a href="http://example.com/"&gt;
  165. example link&lt;/a&gt;.&lt;/p&gt;
  166. Optionally, you may include a title attribute in the parentheses:
  167. This is an [example link](http://example.com/ "With a Title").
  168. Output:
  169. &lt;p&gt;This is an &lt;a href="http://example.com/" title="With a Title"&gt;
  170. example link&lt;/a&gt;.&lt;/p&gt;
  171. Reference-style links allow you to refer to your links by names, which
  172. you define elsewhere in your document:
  173. I get 10 times more traffic from [Google][1] than from
  174. [Yahoo][2] or [MSN][3].
  175. [1]: http://google.com/ "Google"
  176. [2]: http://search.yahoo.com/ "Yahoo Search"
  177. [3]: http://search.msn.com/ "MSN Search"
  178. Output:
  179. &lt;p&gt;I get 10 times more traffic from &lt;a href="http://google.com/"
  180. title="Google"&gt;Google&lt;/a&gt; than from &lt;a href="http://search.yahoo.com/"
  181. title="Yahoo Search"&gt;Yahoo&lt;/a&gt; or &lt;a href="http://search.msn.com/"
  182. title="MSN Search"&gt;MSN&lt;/a&gt;.&lt;/p&gt;
  183. The title attribute is optional. Link names may contain letters,
  184. numbers and spaces, but are *not* case sensitive:
  185. I start my morning with a cup of coffee and
  186. [The New York Times][NY Times].
  187. [ny times]: http://www.nytimes.com/
  188. Output:
  189. &lt;p&gt;I start my morning with a cup of coffee and
  190. &lt;a href="http://www.nytimes.com/"&gt;The New York Times&lt;/a&gt;.&lt;/p&gt;
  191. ### Images ###
  192. Image syntax is very much like link syntax.
  193. Inline (titles are optional):
  194. ![alt text](/path/to/img.jpg "Title")
  195. Reference-style:
  196. ![alt text][id]
  197. [id]: /path/to/img.jpg "Title"
  198. Both of the above examples produce the same output:
  199. &lt;img src="/path/to/img.jpg" alt="alt text" title="Title" /&gt;
  200. ### Code ###
  201. In a regular paragraph, you can create code span by wrapping text in
  202. backtick quotes. Any ampersands (`&amp;`) and angle brackets (`&lt;` or
  203. `&gt;`) will automatically be translated into HTML entities. This makes
  204. it easy to use Markdown to write about HTML example code:
  205. I strongly recommend against using any `&lt;blink&gt;` tags.
  206. I wish SmartyPants used named entities like `&amp;mdash;`
  207. instead of decimal-encoded entities like `&amp;#8212;`.
  208. Output:
  209. &lt;p&gt;I strongly recommend against using any
  210. &lt;code&gt;&amp;lt;blink&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;
  211. &lt;p&gt;I wish SmartyPants used named entities like
  212. &lt;code&gt;&amp;amp;mdash;&lt;/code&gt; instead of decimal-encoded
  213. entities like &lt;code&gt;&amp;amp;#8212;&lt;/code&gt;.&lt;/p&gt;
  214. To specify an entire block of pre-formatted code, indent every line of
  215. the block by 4 spaces or 1 tab. Just like with code spans, `&amp;`, `&lt;`,
  216. and `&gt;` characters will be escaped automatically.
  217. Markdown:
  218. If you want your page to validate under XHTML 1.0 Strict,
  219. you've got to put paragraph tags in your blockquotes:
  220. &lt;blockquote&gt;
  221. &lt;p&gt;For example.&lt;/p&gt;
  222. &lt;/blockquote&gt;
  223. Output:
  224. &lt;p&gt;If you want your page to validate under XHTML 1.0 Strict,
  225. you've got to put paragraph tags in your blockquotes:&lt;/p&gt;
  226. &lt;pre&gt;&lt;code&gt;&amp;lt;blockquote&amp;gt;
  227. &amp;lt;p&amp;gt;For example.&amp;lt;/p&amp;gt;
  228. &amp;lt;/blockquote&amp;gt;
  229. &lt;/code&gt;&lt;/pre&gt;
  230. ## Fenced code blocks (and syntax highlighting)
  231. ```javascript
  232. for (var i = 0; i < items.length; i++) {
  233. console.log(items[i], i); // log them
  234. }
  235. ```
  236. </textarea></form>
  237. <script>
  238. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  239. mode: 'markdown',
  240. lineNumbers: true,
  241. theme: "default",
  242. extraKeys: {"Enter": "newlineAndIndentContinueMarkdownList"}
  243. });
  244. </script>
  245. <p>If you also want support <code>strikethrough</code>, <code>emoji</code> and few other goodies, check out <a href="../gfm/index.html">GitHub-Flavored Markdown mode</a>.</p>
  246. <p>Optionally depends on other modes for properly highlighted code blocks,
  247. and XML mode for properly highlighted inline XML blocks.</p>
  248. <p>Markdown mode supports these options:</p>
  249. <ul>
  250. <li>
  251. <d1>
  252. <dt><code>highlightFormatting: boolean</code></dt>
  253. <dd>Whether to separately highlight markdown meta characters (<code>*[]()</code>etc.) (default: <code>false</code>).</dd>
  254. </d1>
  255. </li>
  256. <li>
  257. <d1>
  258. <dt><code>maxBlockquoteDepth: boolean</code></dt>
  259. <dd>Maximum allowed blockquote nesting (default: <code>0</code> - infinite nesting).</dd>
  260. </d1>
  261. </li>
  262. <li>
  263. <d1>
  264. <dt><code>xml: boolean</code></dt>
  265. <dd>Whether to highlight inline XML (default: <code>true</code>).</dd>
  266. </d1>
  267. </li>
  268. <li>
  269. <d1>
  270. <dt><code>fencedCodeBlockHighlighting: boolean</code></dt>
  271. <dd>Whether to syntax-highlight fenced code blocks, if given mode is included, or fencedCodeBlockDefaultMode is set (default: <code>true</code>).</dd>
  272. </d1>
  273. </li>
  274. <li>
  275. <d1>
  276. <dt><code>fencedCodeBlockDefaultMode: string</code></dt>
  277. <dd>Mode to use for fencedCodeBlockHighlighting, if given mode is not included.</dd>
  278. </d1>
  279. </li>
  280. <li>
  281. <d1>
  282. <dt><code>tokenTypeOverrides: Object</code></dt>
  283. <dd>When you want to override default token type names (e.g. <code>{code: "code"}</code>).</dd>
  284. </d1>
  285. </li>
  286. <li>
  287. <d1>
  288. <dt><code>allowAtxHeaderWithoutSpace: boolean</code></dt>
  289. <dd>Allow lazy headers without whitespace between hashtag and text (default: <code>false</code>).</dd>
  290. </d1>
  291. </li>
  292. </ul>
  293. <p><strong>MIME types defined:</strong> <code>text/x-markdown</code>.</p>
  294. <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#markdown_*">normal</a>, <a href="../../test/index.html#verbose,markdown_*">verbose</a>.</p>
  295. </article>