v2.0.11

Blocks

Last updated


This page covers headings, paragraphs and blank lines, blockquotes with GitHub alerts, horizontal rules and raw HTML lines.

Headings


SyntaxOutput
# to ######, a space and textmd-h1 to md-h6
Text followed by a === linemd-h1 (Setext)
Text followed by a --- linemd-h2 (Setext)
Any heading with Init({ parseHeading: true })<h1> to <h6> with the same class instead of <span>; see API Reference

Headings accept every inline format.

Paragraphs and Blank Lines


SyntaxResult
Two adjacent lines of textMerged into one paragraph joined by a newline, shown as a space
One or more blank linesOne break node; consecutive blank lines are output once
Blank lines at the end of the documentNot output

Blockquotes and Alerts


Lines that start with > form a blockquote whose content can hold any block; >> nests a blockquote.
When the first line is only [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION] (case-insensitive), the blockquote becomes the matching alert. With other text on the same line, or inside a nested blockquote, it stays a normal blockquote.

Horizontal Rules


***, --- or ___: three or more of the same character, with optional spaces in between (such as - - -).

Raw HTML


A whole line that starts with an HTML tag is kept as an html node; at output, dangerous tags, event attributes and javascript: URLs are removed. See Security.
Line breaks written inside raw HTML (<br>, <br/>, <br />) are output as <br class="md-br"> and stay visible; the bare <br> the parser emits for blank lines is hidden by parser.css. Before v2.0.11 both were hidden, so a <br> between two badges did not break the line.

Examples


Headings


ATX headings 1 to 6 with inline formatting, and Setext headings.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. # Heading H1 *(1)*
  4. ## Heading H2 _(1)_
  5. ### Heading ~~H3~~
  6. #### Heading ==H4==
  7. ##### Heading H5
  8. ###### Heading H6
  9. Setext H1^(2)^
  10. ===
  11. Setext H2~(2)~
  12. ---
  13. </script>
  14. <script>
  15. const out = document.getElementById("out");
  16. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  17. MDParser.Refresh(out);
  18. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Paragraphs and Breaks


Adjacent lines merge into one paragraph; three blank lines still produce a single break.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Paragraph merge: two adjacent lines
  4. become one paragraph joined by a soft break.
  5. Three blank lines below produce a single break.
  6. This line follows the merged break.
  7. </script>
  8. <script>
  9. const out = document.getElementById("out");
  10. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  11. MDParser.Refresh(out);
  12. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Blockquotes and Alerts


Nested quotes, the five GitHub alerts, and markers that stay plain blockquotes.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. > First quote line
  4. > Second quote line **bold**
  5. >> Nested quote **bold**
  6. > [!NOTE]
  7. > Useful information users should know, even when skimming.
  8. > [!TIP]
  9. > Helpful advice, with **bold** and `code`.
  10. > [!IMPORTANT]
  11. > Key information users need to know.
  12. >
  13. > - Lists work inside
  14. > - Second item
  15. > [!WARNING]
  16. > Urgent info that needs immediate attention.
  17. > [!CAUTION]
  18. > Advises about risks or negative outcomes.
  19. Not alerts (marker only, text on the marker line, nested in a quote):
  20. > [!NOTE]
  21. > [!TIP] text on the same line
  22. > Outer quote
  23. >> [!WARNING]
  24. >> Marker inside a nested quote
  25. </script>
  26. <script>
  27. const out = document.getElementById("out");
  28. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  29. MDParser.Refresh(out);
  30. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Raw HTML Line Breaks


A <br> inside a raw HTML block breaks the line, while the blank line between blocks adds no visible break.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. <p align="center">
  4. <a href="https://github.com/pardnchiu/NanoMD"><img src="https://img.shields.io/badge/NANOMD-PARSER-blue?style=for-the-badge" alt="NanoMD"></a><br>
  5. <a href="https://www.npmjs.com/package/@pardnchiu/nanomd"><img src="https://img.shields.io/npm/v/@pardnchiu/nanomd?style=for-the-badge" alt="npm"></a>
  6. </p>
  7. <div>line one<br/>line two<br />line three</div>
  8. </script>
  9. <script>
  10. const out = document.getElementById("out");
  11. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  12. MDParser.Refresh(out);
  13. console.log(out.querySelectorAll("br.md-br").length + " author <br> kept, " + out.querySelectorAll("br:not(.md-br)").length + " blank-line <br> hidden");
  14. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Horizontal Rules and Pipes


The three rule styles, and lines that contain | but are not tables.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Lines containing | that are not tables keep their block type:
  4. # Heading A | B
  5. > Quote a | b
  6. ***
  7. - - -
  8. ___
  9. </script>
  10. <script>
  11. const out = document.getElementById("out");
  12. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  13. MDParser.Refresh(out);
  14. </script>
Live preview · @pardnchiu/nanomd@2.0.11
中文