mymarkdown

My markdown
git clone https://git.grace.moe/mymarkdown
Log | Files | Refs

commit 2c4a3e2b7a887a254b827cc4fef5e8f5a17a530d
parent c310fb63ca2691020956ef1292add8e87b194304
Author: gracefu <81774659+gracefuu@users.noreply.github.com>
Date:   Thu, 22 May 2025 04:15:26 +0800

add sample.my to snapshot tests

Diffstat:
Msrc/test.zig | 4++++
Rsample.my -> src/test/sample.my | 0
Asrc/test/sample.my.ast | 356+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 360 insertions(+), 0 deletions(-)

diff --git a/src/test.zig b/src/test.zig @@ -88,6 +88,10 @@ test "Thematic break" { try testSnapshot("src/test/thematic_break.my"); } +test "Sample" { + try testSnapshot("src/test/sample.my"); +} + test "Super long line" { const input = try std.testing.allocator.create([(1 << 24) * 4 + PADDING + 1]u8); defer std.testing.allocator.destroy(input); diff --git a/sample.my b/src/test/sample.my diff --git a/src/test/sample.my.ast b/src/test/sample.my.ast @@ -0,0 +1,356 @@ +.document + .heading + .marker + "#" + .text + "Mymarkdown syntax showcase" + .paragraph + .text + "@@ $toc.generate()" + .heading + .marker + "##" + .text + "Block syntaxes" + .heading + .marker + "###" + .text + "Paragraphs" + .paragraph + .text + "Normal blocks of text separated by newlines, constitute paragraphs." + .space_text + "This sentence is part of the same paragraph as above." + .paragraph + .text + "While the first line of a paragraph may not be indented," + .space_text + " subsequent lines may be indented relative to the first line." + .quote + .paragraph + .text + "This is a paragraph." + .paragraph + .error .inconsistent_indentation at 17:3 + .text + "This is a syntax error." + .paragraph + .text + "In general, indented blocks are not allowed unless explicitly introduced by a marker." + .space_text + "In particular, indented code blocks do not exist in mymarkdown." + .space_text + "This is because indented blocks can easily arise from having insufficient indentation on the previous element." + .paragraph + .text + "Paragraphs may also be introduced with the `;` marker," + .space_text + "similar to other block syntaxes." + .space_text + "An indented set of blocks follows the `;` marker." + .heading + .marker + "###" + .text + "Headings" + .paragraph + .text + "Headings are introduced with hashes." + .space_text + "The number of hashes indicates the level of the heading (h1 = `#`, h2 = `##`, ...)." + .space_text + "A single indented inline block follows the marker." + .paragraph + .text + "Note that indented blocks in mymarkdown are strict ---" + .space_text + "the first non-whitespace character after the marker is used to determine the indentation," + .space_text + "after which all subsequent lines must have matching or more indentation." + .quote + .heading + .marker + "####" + .text + "This is a" + .space_text + "multiline heading." + .heading + .marker + "####" + .text + "This is also a" + .space_text + " multiline heading." + .heading + .marker + "####" + .text + "This is a syntax error." + .space_text + .error .unexpected_block_in_inline_context + "This is because there are two paragraphs following the marker." + .heading + .marker + "####" + .text + "This heading itself is not a syntax error." + .space_text + .error .inconsistent_indentation at 48:5 + "But this misaligned second line is interpreted as an indented paragraph, which is a syntax error." + .heading + .marker + "###" + .text + "Blocks" + .quote + .paragraph + .text + "Blocks are introduced by the `>` marker." + .paragraph + .text + "An indented set of blocks follows the `>` marker." + .quote + .paragraph + .text + "Unlike markdown, placing `>` before each line is probably a mistake." + .quote + .paragraph + .text + "This is because each `>` introduces a new block quote, making this the third blockquote in this section." + .heading + .marker + "###" + .text + "Lists" + .paragraph + .text + "There are many types of lists in mymarkdown. They are:" + .list + .unordered_item + .marker + "-" + .text + "Unordered list, introduced by `-`" + .unordered_item + .marker + "-" + .text + "Ordered list, introduced by `.`" + .unordered_item + .marker + "-" + .text + "Description list, introduced by `:`" + .unordered_item + .marker + "-" + .text + "Task list, introduced by `- [ ]`, `- [x]`, or `- [X]`" + .paragraph + .text + "In all cases, the list is formed by grouping list items of the same marker type," + .space_text + "and an indented inline block follows the list item marker." + .paragraph + .text + "The level of nesting can be increased by repeating the marker:" + .list + .unordered_item + .marker + "-" + .text + "Level-2 unordered list marker: `--`" + .unordered_item + .marker + "-" + .text + "Level-2 ordered list marker: `..`" + .unordered_item + .marker + "-" + .text + "Level-2 description list marker: `::`" + .unordered_item + .marker + "-" + .text + "Level-2 task list marker: `-- [ ]`, `-- [x]`, or `-- [X]`" + .paragraph + .text + "Note that for ordered lists, no numbers or letters are allowed before the marker." + .space_text + "Instead they are simply automatically numbered from 1." + .space_text + "Use directives to adjust the starting index." + .paragraph + .text + "Nested labels extend the parent's counter rather than beginning a new counter." + .list + .ordered_item + .marker + "." + .text + "List item 1" + .ordered_item + .marker + "." + .text + "List item 2" + .ordered_item + .marker + ".." + .text + "List item 2.1" + .ordered_item + .marker + ".." + .text + "List item 2.2" + .ordered_item + .marker + "." + .text + "List item 3" + .paragraph + .text + "For all list items, an indented //inline// block follows the list marker," + .space_text + "**not** an arbitrary **set** of indented blocks." + .space_text + "That means the following is a syntax error:" + .quote + .list + .unordered_item + .marker + "-" + .text + "This is a syntax error." + .space_text + .error .unexpected_block_in_inline_context + "One should not use multiple paragraphs in a list item." + .paragraph + .text + "To have items that contain multiple paragraphs, instead use a short phrase or sentence for the list item itself," + .space_text + "and follow it up with a longer series of paragraphs that [//elaborate//](#List item elaborations) on the list item." + .heading + .marker + "###" + .text + "List item elaborations" + .paragraph + .text + "Sometimes, lists are used not to convey merely a list of items," + .space_text + "but also come with a **elaboration** or **description** of the item." + .space_text + "In such cases, elaboration blocks introduced by `+` markers matching the level of the list item" + .space_text + "can be added immediately after the list item to be described or elaborated on." + .space_text + "This way, the main list marker itself can be used to contain just the key point or phrase." + .paragraph + .text + "An indented set of blocks follows the list item elaboration marker." + .heading + .marker + "####" + .text + "Examples" + .list + .unordered_item + .marker + "-" + .text + "Some examples of when list item elaborations can be used:" + .unordered_item + .marker + "--" + .text + "**In a list of pros and cons.**" + .elaboration + .marker + "++" + .paragraph + .text + "The main list items can be used to list the actual pros and cons," + .space_text + "while list item elaborations can be used to justify them." + .unordered_item + .marker + "--" + .text + "**In a list of examples.**" + .elaboration + .marker + "++" + .paragraph + .text + "The main list items can be used for the names of the examples," + .space_text + "while elaborations go into more detail about how the examples work." + .space_text + "Like this example!" + .unordered_item + .marker + "-" + .text + "Some examples of when list item elaborations must be used:" + .unordered_item + .marker + "--" + .text + "**When you want to nest multiple paragraphs within a bullet.**" + .elaboration + .marker + "++" + .paragraph + .text + "As the list item markers themselves only take in one indented inline block," + .space_text + "they physically cannot contain multiple paragraphs." + .space_text + "This limitation is meant to discourage using lists in situations" + .space_text + "where a subsection would be more appropriate." + .paragraph + .text + "In such cases, it is usually beneficial to add a short \"name\" or \"title\" for your paragraphs" + .space_text + "in the actual list item (and emphasize or strongly emphasize them)," + .space_text + "and then place the paragraphs themselves inside the list item elaboration." + .paragraph + .text + "If that is not desirable however, the workaround is to use an //empty// list item," + .space_text + "so that the paragraphs you place inside the list item elaboration" + .space_text + "become the only paragraphs nested under the bullet." + .unordered_item + .marker + "-" + .text + "Some examples of when list item elaborations should not be used:" + .unordered_item + .marker + "--" + .text + "**When you simply have long list items.**" + .elaboration + .marker + "++" + .paragraph + .text + "Regardless of the length of the content you wish to place in the list items," + .space_text + "the key consideration to keep in mind is whether the content \"belongs\" to the main list," + .space_text + "or simply to the current list item." + .paragraph + .text + "If the content does truly belong to the main list, then the content should be used as the list item itself." + .space_text + "In such cases, it may be worth making the list a //loose// list, which means placing empty lines after each list item."