Fix definition lists requiring 3 spaces after the marker (#384)
This commit is contained in:
1 parent
5a326ef5b7
commit
463eec7085
3 files changed
+70
-23
No files matched your search
@@ -101,7 +101,7 @@ namespace Markdig.Tests.Specs.DefinitionLists
|
|||||||
TestParser.TestSpec("Term 1\n\n: Definition\nwith lazy continuation.\n\n Second paragraph of the definition.", "<dl>\n<dt>Term 1</dt>\n<dd><p>Definition\nwith lazy continuation.</p>\n<p>Second paragraph of the definition.</p>\n</dd>\n</dl>", "definitionlists+attributes|advanced", context: "Example 2\nSection Extensions / Definition lists\n");
|
TestParser.TestSpec("Term 1\n\n: Definition\nwith lazy continuation.\n\n Second paragraph of the definition.", "<dl>\n<dt>Term 1</dt>\n<dd><p>Definition\nwith lazy continuation.</p>\n<p>Second paragraph of the definition.</p>\n</dd>\n</dl>", "definitionlists+attributes|advanced", context: "Example 2\nSection Extensions / Definition lists\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The definition must be indented to 4 characters including the `:`.
|
// The `:` or `~` must be followed by at least one space or tab. A single space is enough:
|
||||||
[Test]
|
[Test]
|
||||||
public void ExtensionsDefinitionLists_Example003()
|
public void ExtensionsDefinitionLists_Example003()
|
||||||
{
|
{
|
||||||
@@ -109,17 +109,26 @@ namespace Markdig.Tests.Specs.DefinitionLists
|
|||||||
// Section: Extensions / Definition lists
|
// Section: Extensions / Definition lists
|
||||||
//
|
//
|
||||||
// The following Markdown:
|
// The following Markdown:
|
||||||
// Term 1
|
// First Term
|
||||||
// : Invalid with less than 3 characters
|
// : This is the definition of the first term.
|
||||||
|
//
|
||||||
|
// Second Term
|
||||||
|
// : This is one definition of the second term.
|
||||||
|
// ~ This is another definition of the second term.
|
||||||
//
|
//
|
||||||
// Should be rendered as:
|
// Should be rendered as:
|
||||||
// <p>Term 1
|
// <dl>
|
||||||
// : Invalid with less than 3 characters</p>
|
// <dt>First Term</dt>
|
||||||
|
// <dd>This is the definition of the first term.</dd>
|
||||||
|
// <dt>Second Term</dt>
|
||||||
|
// <dd>This is one definition of the second term.</dd>
|
||||||
|
// <dd>This is another definition of the second term.</dd>
|
||||||
|
// </dl>
|
||||||
|
|
||||||
TestParser.TestSpec("Term 1\n: Invalid with less than 3 characters", "<p>Term 1\n: Invalid with less than 3 characters</p>", "definitionlists+attributes|advanced", context: "Example 3\nSection Extensions / Definition lists\n");
|
TestParser.TestSpec("First Term\n: This is the definition of the first term.\n\nSecond Term\n: This is one definition of the second term.\n~ This is another definition of the second term.", "<dl>\n<dt>First Term</dt>\n<dd>This is the definition of the first term.</dd>\n<dt>Second Term</dt>\n<dd>This is one definition of the second term.</dd>\n<dd>This is another definition of the second term.</dd>\n</dl>", "definitionlists+attributes|advanced", context: "Example 3\nSection Extensions / Definition lists\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The `:` can be indented up to 3 spaces:
|
// Without a space or tab after the `:`, the line is not a definition:
|
||||||
[Test]
|
[Test]
|
||||||
public void ExtensionsDefinitionLists_Example004()
|
public void ExtensionsDefinitionLists_Example004()
|
||||||
{
|
{
|
||||||
@@ -128,6 +137,24 @@ namespace Markdig.Tests.Specs.DefinitionLists
|
|||||||
//
|
//
|
||||||
// The following Markdown:
|
// The following Markdown:
|
||||||
// Term 1
|
// Term 1
|
||||||
|
// :Invalid without a space after the colon
|
||||||
|
//
|
||||||
|
// Should be rendered as:
|
||||||
|
// <p>Term 1
|
||||||
|
// :Invalid without a space after the colon</p>
|
||||||
|
|
||||||
|
TestParser.TestSpec("Term 1\n:Invalid without a space after the colon", "<p>Term 1\n:Invalid without a space after the colon</p>", "definitionlists+attributes|advanced", context: "Example 4\nSection Extensions / Definition lists\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The `:` can be indented up to 3 spaces:
|
||||||
|
[Test]
|
||||||
|
public void ExtensionsDefinitionLists_Example005()
|
||||||
|
{
|
||||||
|
// Example 5
|
||||||
|
// Section: Extensions / Definition lists
|
||||||
|
//
|
||||||
|
// The following Markdown:
|
||||||
|
// Term 1
|
||||||
// : Valid even if `:` starts at most 3 spaces
|
// : Valid even if `:` starts at most 3 spaces
|
||||||
//
|
//
|
||||||
// Should be rendered as:
|
// Should be rendered as:
|
||||||
@@ -136,14 +163,14 @@ namespace Markdig.Tests.Specs.DefinitionLists
|
|||||||
// <dd>Valid even if <code>:</code> starts at most 3 spaces</dd>
|
// <dd>Valid even if <code>:</code> starts at most 3 spaces</dd>
|
||||||
// </dl>
|
// </dl>
|
||||||
|
|
||||||
TestParser.TestSpec("Term 1\n : Valid even if `:` starts at most 3 spaces", "<dl>\n<dt>Term 1</dt>\n<dd>Valid even if <code>:</code> starts at most 3 spaces</dd>\n</dl>", "definitionlists+attributes|advanced", context: "Example 4\nSection Extensions / Definition lists\n");
|
TestParser.TestSpec("Term 1\n : Valid even if `:` starts at most 3 spaces", "<dl>\n<dt>Term 1</dt>\n<dd>Valid even if <code>:</code> starts at most 3 spaces</dd>\n</dl>", "definitionlists+attributes|advanced", context: "Example 5\nSection Extensions / Definition lists\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// But more than 3 spaces before `:` will trigger an indented code block:
|
// But more than 3 spaces before `:` will trigger an indented code block:
|
||||||
[Test]
|
[Test]
|
||||||
public void ExtensionsDefinitionLists_Example005()
|
public void ExtensionsDefinitionLists_Example006()
|
||||||
{
|
{
|
||||||
// Example 5
|
// Example 6
|
||||||
// Section: Extensions / Definition lists
|
// Section: Extensions / Definition lists
|
||||||
//
|
//
|
||||||
// The following Markdown:
|
// The following Markdown:
|
||||||
@@ -156,14 +183,14 @@ namespace Markdig.Tests.Specs.DefinitionLists
|
|||||||
// <pre><code>: Not valid
|
// <pre><code>: Not valid
|
||||||
// </code></pre>
|
// </code></pre>
|
||||||
|
|
||||||
TestParser.TestSpec("Term 1\n\n : Not valid", "<p>Term 1</p>\n<pre><code>: Not valid\n</code></pre>", "definitionlists+attributes|advanced", context: "Example 5\nSection Extensions / Definition lists\n");
|
TestParser.TestSpec("Term 1\n\n : Not valid", "<p>Term 1</p>\n<pre><code>: Not valid\n</code></pre>", "definitionlists+attributes|advanced", context: "Example 6\nSection Extensions / Definition lists\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Definition lists can be nested inside list items
|
// Definition lists can be nested inside list items
|
||||||
[Test]
|
[Test]
|
||||||
public void ExtensionsDefinitionLists_Example006()
|
public void ExtensionsDefinitionLists_Example007()
|
||||||
{
|
{
|
||||||
// Example 6
|
// Example 7
|
||||||
// Section: Extensions / Definition lists
|
// Section: Extensions / Definition lists
|
||||||
//
|
//
|
||||||
// The following Markdown:
|
// The following Markdown:
|
||||||
@@ -189,7 +216,7 @@ namespace Markdig.Tests.Specs.DefinitionLists
|
|||||||
// </dl></li>
|
// </dl></li>
|
||||||
// </ol>
|
// </ol>
|
||||||
|
|
||||||
TestParser.TestSpec("1. First\n \n2. Second\n \n Term 1\n : Definition\n \n Term 2\n : Second Definition", "<ol>\n<li><p>First</p></li>\n<li><p>Second</p>\n<dl>\n<dt>Term 1</dt>\n<dd>Definition</dd>\n<dt>Term 2</dt>\n<dd>Second Definition</dd>\n</dl></li>\n</ol>", "definitionlists+attributes|advanced", context: "Example 6\nSection Extensions / Definition lists\n");
|
TestParser.TestSpec("1. First\n \n2. Second\n \n Term 1\n : Definition\n \n Term 2\n : Second Definition", "<ol>\n<li><p>First</p></li>\n<li><p>Second</p>\n<dl>\n<dt>Term 1</dt>\n<dd>Definition</dd>\n<dt>Term 2</dt>\n<dd>Second Definition</dd>\n</dl></li>\n</ol>", "definitionlists+attributes|advanced", context: "Example 7\nSection Extensions / Definition lists\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,14 +72,33 @@ with lazy continuation.</p>
|
|||||||
</dl>
|
</dl>
|
||||||
````````````````````````````````
|
````````````````````````````````
|
||||||
|
|
||||||
The definition must be indented to 4 characters including the `:`.
|
The `:` or `~` must be followed by at least one space or tab. A single space is enough:
|
||||||
|
|
||||||
|
```````````````````````````````` example
|
||||||
|
First Term
|
||||||
|
: This is the definition of the first term.
|
||||||
|
|
||||||
|
Second Term
|
||||||
|
: This is one definition of the second term.
|
||||||
|
~ This is another definition of the second term.
|
||||||
|
.
|
||||||
|
<dl>
|
||||||
|
<dt>First Term</dt>
|
||||||
|
<dd>This is the definition of the first term.</dd>
|
||||||
|
<dt>Second Term</dt>
|
||||||
|
<dd>This is one definition of the second term.</dd>
|
||||||
|
<dd>This is another definition of the second term.</dd>
|
||||||
|
</dl>
|
||||||
|
````````````````````````````````
|
||||||
|
|
||||||
|
Without a space or tab after the `:`, the line is not a definition:
|
||||||
|
|
||||||
```````````````````````````````` example
|
```````````````````````````````` example
|
||||||
Term 1
|
Term 1
|
||||||
: Invalid with less than 3 characters
|
:Invalid without a space after the colon
|
||||||
.
|
.
|
||||||
<p>Term 1
|
<p>Term 1
|
||||||
: Invalid with less than 3 characters</p>
|
:Invalid without a space after the colon</p>
|
||||||
````````````````````````````````
|
````````````````````````````````
|
||||||
|
|
||||||
The `:` can be indented up to 3 spaces:
|
The `:` can be indented up to 3 spaces:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file is licensed under the BSD-Clause 2 license.
|
// This file is licensed under the BSD-Clause 2 license.
|
||||||
// See the license.txt file in the project root for more information.
|
// See the license.txt file in the project root for more information.
|
||||||
|
|
||||||
|
using Markdig.Helpers;
|
||||||
using Markdig.Parsers;
|
using Markdig.Parsers;
|
||||||
using Markdig.Syntax;
|
using Markdig.Syntax;
|
||||||
|
|
||||||
@@ -35,12 +36,12 @@ public class DefinitionListParser : BlockParser
|
|||||||
var startPosition = processor.Start;
|
var startPosition = processor.Start;
|
||||||
|
|
||||||
var column = processor.ColumnBeforeIndent;
|
var column = processor.ColumnBeforeIndent;
|
||||||
processor.NextChar();
|
var c = processor.NextChar();
|
||||||
processor.ParseIndent();
|
processor.ParseIndent();
|
||||||
var delta = processor.Column - column;
|
var delta = processor.Column - column;
|
||||||
|
|
||||||
// We expect to have a least
|
// The marker must be followed by at least one space or tab
|
||||||
if (delta < 4)
|
if (!c.IsSpaceOrTab())
|
||||||
{
|
{
|
||||||
// Return back to original position
|
// Return back to original position
|
||||||
processor.GoToColumn(column);
|
processor.GoToColumn(column);
|
||||||
@@ -144,12 +145,12 @@ public class DefinitionListParser : BlockParser
|
|||||||
{
|
{
|
||||||
var startPosition = processor.Start;
|
var startPosition = processor.Start;
|
||||||
var column = processor.ColumnBeforeIndent;
|
var column = processor.ColumnBeforeIndent;
|
||||||
processor.NextChar();
|
var c = processor.NextChar();
|
||||||
processor.ParseIndent();
|
processor.ParseIndent();
|
||||||
var delta = processor.Column - column;
|
var delta = processor.Column - column;
|
||||||
|
|
||||||
// We expect to have a least
|
// The marker must be followed by at least one space or tab
|
||||||
if (delta < 4)
|
if (!c.IsSpaceOrTab())
|
||||||
{
|
{
|
||||||
// Remove the blankline before breaking this definition item
|
// Remove the blankline before breaking this definition item
|
||||||
if (lastBlankLine != null)
|
if (lastBlankLine != null)
|
||||||
|
|||||||
Reference in new issue
Block a user