Fix extension DisableHtml not working properly with inline HTML (issue #46)

This commit is contained in:
Alexandre Mutel
2016-09-18 10:56:37 +02:00
parent fa281f1ca1
commit 72b7fce48c
6 changed files with 86 additions and 0 deletions

View File

@@ -88,6 +88,7 @@
<None Include="Specs\HardlineBreakSpecs.md" />
<None Include="Specs\BootstrapSpecs.md" />
<None Include="Specs\DiagramsSpecs.md" />
<None Include="Specs\NoHtmlSpecs.md" />
<None Include="Specs\TaskListSpecs.md" />
<None Include="Specs\SmartyPantsSpecs.md" />
<None Include="Specs\MediaSpecs.md" />

View File

@@ -0,0 +1,27 @@
# Extensions
## NoHTML
The extension DisableHtml allows to disable the parsing of HTML:
For inline HTML:
```````````````````````````````` example
this is some text</td></tr>
.
<p>this is some text&lt;/td&gt;&lt;/tr&gt;</p>
````````````````````````````````
For Block HTML:
```````````````````````````````` example
<div>
this is some text
</div>
.
<p>&lt;div&gt;
this is some text
&lt;/div&gt;</p>
````````````````````````````````

View File

@@ -19845,4 +19845,54 @@ namespace Markdig.Tests
}
}
// TODO: Add other text diagram languages
// # Extensions
//
// ## NoHTML
//
// The extension DisableHtml allows to disable the parsing of HTML:
//
// For inline HTML:
[TestFixture]
public partial class TestExtensionsNoHTML
{
[Test]
public void Example001()
{
// Example 1
// Section: Extensions NoHTML
//
// The following CommonMark:
// this is some text</td></tr>
//
// Should be rendered as:
// <p>this is some text&lt;/td&gt;&lt;/tr&gt;</p>
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 1, "Extensions NoHTML");
TestParser.TestSpec("this is some text</td></tr>", "<p>this is some text&lt;/td&gt;&lt;/tr&gt;</p>", "nohtml");
}
}
// For Block HTML:
[TestFixture]
public partial class TestExtensionsNoHTML
{
[Test]
public void Example002()
{
// Example 2
// Section: Extensions NoHTML
//
// The following CommonMark:
// <div>
// this is some text
// </div>
//
// Should be rendered as:
// <p>&lt;div&gt;
// this is some text
// &lt;/div&gt;</p>
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 2, "Extensions NoHTML");
TestParser.TestSpec("<div>\nthis is some text\n</div>", "<p>&lt;div&gt;\nthis is some text\n&lt;/div&gt;</p>", "nohtml");
}
}
}

View File

@@ -59,6 +59,7 @@ SOFTWARE.
new KeyValuePair<string, string>(Host.ResolvePath("AutoIdentifierSpecs.md"), "autoidentifiers|advanced"),
new KeyValuePair<string, string>(Host.ResolvePath("TaskListSpecs.md"), "tasklists|advanced"),
new KeyValuePair<string, string>(Host.ResolvePath("DiagramsSpecs.md"), "diagrams|advanced"),
new KeyValuePair<string, string>(Host.ResolvePath("NoHtmlSpecs.md"), "nohtml"),
};
var emptyLines = false;
var displayEmptyLines = false;

View File

@@ -487,6 +487,9 @@ namespace Markdig
case "nofollowlinks":
pipeline.UseNoFollowLinks();
break;
case "nohtml":
pipeline.DisableHtml();
break;
default:
throw new ArgumentException($"Invalid extension `{extension}` from `{extensions}`", nameof(extensions));
}

View File

@@ -62,6 +62,10 @@ namespace Markdig.Parsers.Inlines
Column = column
};
}
else
{
return false;
}
return true;
}