v2.0.11

Lists and Tables

Last updated


This page covers unordered, ordered, nested and task lists, the indent width setting, and tables with column alignment.

Lists


SyntaxOutput
- item, * item<ul class="md-list">
1. item<ol class="md-list">
- [ ] todo, - [x] done, - [X] done<li class="md-task"> with a disabled checkbox
More indentation than the parentNested list; the marker changes with depth: ul uses disc, circle, square, +, -, > and ol uses decimal, upper-alpha, lower-alpha, upper-roman, lower-roman, >
Indented content on the next lineBelongs to the same item and can hold any block
Unindented text on the next lineJoins the item's paragraph until another block starts

Indent Width


Lists decide nesting by column width, and the width of a tab comes from Init({ indent }), 4 by default. A list nested with tabs is read as different levels under indent: 2; see API Reference.

Tables


The first row is the header and the second is the separator row; each cell is made of -, with : on either side for alignment:
SeparatorAlignment
---None
:---Left
:---:Center
---:Right

Cells accept inline formatting; the table sizes to its content, a cell wraps once it reaches 40rem, and when wider than the page it scrolls horizontally inside md-table-wrap. Write \| for a literal | in a cell; this also works inside code spans and at the end of a row.

Examples


Lists


Bullets with nesting, ordered items and task items.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. - Item one
  4. - Item two
  5. - Nested item
  6. - Item three
  7. 1. First
  8. 2. Second
  9. - [ ] Todo
  10. - [x] Done
  11. - [X] Uppercase X also counts
  12. </script>
  13. <script>
  14. const out = document.getElementById("out");
  15. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  16. MDParser.Refresh(out);
  17. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Nested Markers


Six levels of ul and ol, each level with its own marker.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. - Level 1
  4. - Level 2
  5. - Level 3
  6. - Level 4
  7. - Level 5
  8. - Level 6
  9. 1. Level 1
  10. 1. Level 2
  11. 1. Level 3
  12. 1. Level 4
  13. 1. Level 5
  14. 1. Level 6
  15. </script>
  16. <script>
  17. const out = document.getElementById("out");
  18. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  19. MDParser.Refresh(out);
  20. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Indent 4


A tab-indented item nests under an item whose content starts at column 4.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. 1. Ordered item, content starts at column 4
  4. - Nested item indented with a tab
  5. </script>
  6. <script>
  7. const out = document.getElementById("out");
  8. MDParser.Init({ indent: 4 });
  9. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  10. MDParser.Refresh(out);
  11. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Indent 2


With indent: 2 the same tab no longer reaches column 4, so the list splits in two.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. 1. Ordered item, content starts at column 4
  4. - Nested item indented with a tab
  5. </script>
  6. <script>
  7. const out = document.getElementById("out");
  8. MDParser.Init({ indent: 2 });
  9. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  10. MDParser.Refresh(out);
  11. </script>
Live preview · @pardnchiu/nanomd@2.0.11

Tables


Column alignment, inline formatting in cells, and escaped \| that stays in one cell.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. | Field | Description |
  4. |:---|---:|
  5. | a | **bold** |
  6. | b | `code` |
  7. | c | a \| b |
  8. | d | `x \| y` |
  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. console.log("cells per row:", [...out.querySelectorAll("tr")].map((tr) => tr.children.length).join(" "));
  15. </script>
Live preview · @pardnchiu/nanomd@2.0.11
中文