Markdown indented code blocks (#20473)

* Implement Markdown indented code blocks

Additional indentation of 4 spaces makes a block an "indented code block"
(monospaced text without syntax highlighting).
Also `::` RST syntax for code blocks is disabled.

So instead of
```rst
see::

  Some code
```

the code block should be written as
```markdown
see:

    Some code
```

* Migrate RST literal blocks :: to Markdown's ones
This commit is contained in:
Andrey Makarov
2022-10-05 21:03:10 +03:00
committed by GitHub
parent 594e93a66b
commit 6505bd347d
33 changed files with 697 additions and 603 deletions

View File

@@ -7,6 +7,8 @@ discard """
[Suite] RST indentation
[Suite] Markdown indentation
[Suite] Warnings
[Suite] RST include directive
@@ -124,12 +126,12 @@ suite "RST parsing":
check(dedent"""
Paragraph::
>x""".toAst == expected)
>x""".toAst(rstOptions = preferRst) == expected)
check(dedent"""
Paragraph::
>x""".toAst == expected)
>x""".toAst(rstOptions = preferRst) == expected)
test "RST quoted literal blocks, :: at a separate line":
let expected =
@@ -148,7 +150,7 @@ suite "RST parsing":
::
>x
>>y""".toAst == expected)
>>y""".toAst(rstOptions = preferRst) == expected)
check(dedent"""
Paragraph
@@ -156,7 +158,7 @@ suite "RST parsing":
::
>x
>>y""".toAst == expected)
>>y""".toAst(rstOptions = preferRst) == expected)
test "Markdown quoted blocks":
check(dedent"""
@@ -779,7 +781,7 @@ suite "RST parsing":
code
""".toAst ==
""".toAst(rstOptions = preferRst) ==
dedent"""
rnInner
rnLeaf 'Check'
@@ -788,6 +790,32 @@ suite "RST parsing":
rnLeaf 'code'
""")
test "Markdown indented code blocks":
check(dedent"""
See
some code""".toAst ==
dedent"""
rnInner
rnInner
rnLeaf 'See'
rnLiteralBlock
rnLeaf 'some code'
""")
# not a code block -- no blank line before:
check(dedent"""
See
some code""".toAst ==
dedent"""
rnInner
rnLeaf 'See'
rnLeaf ' '
rnLeaf 'some'
rnLeaf ' '
rnLeaf 'code'
""")
suite "RST tables":
test "formatting in tables works":
@@ -1238,6 +1266,31 @@ suite "RST indentation":
rnLeaf 'term3definition2'
""")
suite "Markdown indentation":
test "Markdown paragraph indentation":
# Additional spaces (<=3) of indentation does not break the paragraph.
# TODO: in 2nd case de-indentation causes paragraph to break, this is
# reasonable but does not seem to conform the Markdown spec.
check(dedent"""
Start1
stop1
Start2
stop2
""".toAst ==
dedent"""
rnInner
rnParagraph
rnLeaf 'Start1'
rnLeaf ' '
rnLeaf 'stop1'
rnParagraph
rnLeaf 'Start2'
rnParagraph
rnLeaf 'stop2'
rnLeaf ' '
""")
suite "Warnings":
test "warnings for broken footnotes/links/substitutions":
let input = dedent"""

View File

@@ -632,7 +632,7 @@ Test literal block
::
check """
let output1 = input1.toHtml
let output1 = input1.toHtml(preferRst)
doAssert "<pre>" in output1
test "Markdown code block":