-
-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When doing .ToHtml() how to avoid the outer <p> element? #658
Labels
Comments
Use |
You can also write a custom renderer based on the built-in Something like var pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.Use(new MyParagraphExtension("summary"))
.Build(); MyParagraphExtension.cspublic sealed class MyParagraphExtension : IMarkdownExtension
{
private readonly CustomTagParagraphRenderer _renderer;
public MyParagraphExtension(string tag)
{
_renderer = new CustomTagParagraphRenderer(tag);
}
public void Setup(MarkdownPipelineBuilder pipeline) { }
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
{
if (renderer is HtmlRenderer)
{
renderer.ObjectRenderers.ReplaceOrAdd<HtmlObjectRenderer<ParagraphBlock>>(_renderer);
}
}
private sealed class CustomTagParagraphRenderer : HtmlObjectRenderer<ParagraphBlock>
{
private readonly string _openingTag;
private readonly string _closingTag;
public CustomTagParagraphRenderer(string tag)
{
_openingTag = $"<{tag}";
_closingTag = $"</{tag}>";
}
protected override void Write(HtmlRenderer renderer, ParagraphBlock obj)
{
if (!renderer.ImplicitParagraph && renderer.EnableHtmlForBlock)
{
if (!renderer.IsFirstInContainer)
{
renderer.EnsureLine();
}
renderer.Write(_openingTag);
renderer.WriteAttributes(obj);
renderer.Write('>');
}
renderer.WriteLeafInline(obj);
if (!renderer.ImplicitParagraph)
{
if (renderer.EnableHtmlForBlock)
{
renderer.WriteLine(_closingTag);
}
renderer.EnsureLine();
}
}
}
} |
This still puts in a and ending even for text without newlines. How do I turn that behavior off? |
string.StartWith + replace and/or trim. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't quite figure out how to get rid of that
<p>
element in every parsed markdown.My context is that I want to put the parsed markdown in the
<summary>
element, but<p>
make the parsed text go to a new line, making an ugly looking summary.Or even better it would nice to know how to choose with which outer HTML element parse the markdown to HTML.
The text was updated successfully, but these errors were encountered: