From 463eec70851e577c95fc3a6c7e25ce36e374eecb Mon Sep 17 00:00:00 2001
From: dualfroz Definition\nwith lazy continuation. Second paragraph of the definition. Term 1
- // : Invalid with less than 3 characters Term 1\n: Invalid with less than 3 characters Term 1
+ // :Invalid without a space after the colon Term 1\n:Invalid without a space after the colon Term 1 Term 1 First Second First Second\n
", "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]
public void ExtensionsDefinitionLists_Example003()
{
@@ -109,17 +109,26 @@ namespace Markdig.Tests.Specs.DefinitionLists
// Section: Extensions / Definition lists
//
// The following Markdown:
- // Term 1
- // : Invalid with less than 3 characters
+ // 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.
//
// Should be rendered as:
- //
+ //
- TestParser.TestSpec("Term 1\n: Invalid with less than 3 characters", "\n
", "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]
public void ExtensionsDefinitionLists_Example004()
{
@@ -128,6 +137,24 @@ namespace Markdig.Tests.Specs.DefinitionLists
//
// The following Markdown:
// Term 1
+ // :Invalid without a space after the colon
+ //
+ // Should be rendered as:
+ // : starts at most 3 spaces\n
", "definitionlists+attributes|advanced", context: "Example 4\nSection Extensions / Definition lists\n");
+ TestParser.TestSpec("Term 1\n : Valid even if `:` starts at most 3 spaces", ": starts at most 3 spaces\n
", "definitionlists+attributes|advanced", context: "Example 5\nSection Extensions / Definition lists\n");
}
// But more than 3 spaces before `:` will trigger an indented code block:
[Test]
- public void ExtensionsDefinitionLists_Example005()
+ public void ExtensionsDefinitionLists_Example006()
{
- // Example 5
+ // Example 6
// Section: Extensions / Definition lists
//
// The following Markdown:
@@ -156,14 +183,14 @@ namespace Markdig.Tests.Specs.DefinitionLists
// : starts at most 3 spaces
- TestParser.TestSpec("Term 1\n\n : Not valid", ": Not valid
//
", "definitionlists+attributes|advanced", context: "Example 5\nSection Extensions / Definition lists\n");
+ TestParser.TestSpec("Term 1\n\n : Not valid", ": Not valid\n
", "definitionlists+attributes|advanced", context: "Example 6\nSection Extensions / Definition lists\n");
}
// Definition lists can be nested inside list items
[Test]
- public void ExtensionsDefinitionLists_Example006()
+ public void ExtensionsDefinitionLists_Example007()
{
- // Example 6
+ // Example 7
// Section: Extensions / Definition lists
//
// The following Markdown:
@@ -189,7 +216,7 @@ namespace Markdig.Tests.Specs.DefinitionLists
//
//
- TestParser.TestSpec("1. First\n \n2. Second\n \n Term 1\n : Definition\n \n Term 2\n : Second Definition", ": Not valid\n\n
", "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", "\n
\n
", "definitionlists+attributes|advanced", context: "Example 7\nSection Extensions / Definition lists\n");
}
}
}
diff --git a/src/Markdig.Tests/Specs/DefinitionListSpecs.md b/src/Markdig.Tests/Specs/DefinitionListSpecs.md
index b0b1522..aaf9163 100644
--- a/src/Markdig.Tests/Specs/DefinitionListSpecs.md
+++ b/src/Markdig.Tests/Specs/DefinitionListSpecs.md
@@ -72,14 +72,33 @@ with lazy continuation.\n
Term 1 -: Invalid with less than 3 characters
+:Invalid without a space after the colon ```````````````````````````````` The `:` can be indented up to 3 spaces: diff --git a/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs b/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs index 85eb808..191fbc1 100644 --- a/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs +++ b/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs @@ -2,6 +2,7 @@ // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +using Markdig.Helpers; using Markdig.Parsers; using Markdig.Syntax; @@ -35,12 +36,12 @@ public class DefinitionListParser : BlockParser var startPosition = processor.Start; var column = processor.ColumnBeforeIndent; - processor.NextChar(); + var c = processor.NextChar(); processor.ParseIndent(); var delta = processor.Column - column; - // We expect to have a least - if (delta < 4) + // The marker must be followed by at least one space or tab + if (!c.IsSpaceOrTab()) { // Return back to original position processor.GoToColumn(column); @@ -144,12 +145,12 @@ public class DefinitionListParser : BlockParser { var startPosition = processor.Start; var column = processor.ColumnBeforeIndent; - processor.NextChar(); + var c = processor.NextChar(); processor.ParseIndent(); var delta = processor.Column - column; - // We expect to have a least - if (delta < 4) + // The marker must be followed by at least one space or tab + if (!c.IsSpaceOrTab()) { // Remove the blankline before breaking this definition item if (lastBlankLine != null)