mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
How can I exempt stretches of text from being processed as Markdown? #306
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @deanebarker on GitHub (Jul 1, 2019).
Is there anyway to turn off the parser for stretches of code? Like:
Clearly that doesn't work, but that's basically what I'm looking for.
@MihaZupan commented on GitHub (Jul 1, 2019):
Text inside html blocks will be copied verbatim.
For example
@deanebarker commented on GitHub (Jul 1, 2019):
That's what I thought, but I don't think it's what I'm seeing. I'll re-test. If I can't duplicate, I'll close.
@deanebarker commented on GitHub (Jul 2, 2019):
I did some testing, and this depends on there being no blank lines inside the HTML blocks. If you have this:
That will generate HTML inside the
divbecause of the blank line after the opening tag.In my situation, due to some pre-processing that generates the Markdown, I can't guarantee there won't be any blank lines.
Do I have any options to toggle Markdown processing in this situation?
@stevehurcombe commented on GitHub (Jul 2, 2019):
You could wrap the content in a
S.
From: Deane Barker notifications@github.com
Sent: 02 July 2019 11:00
To: lunet-io/markdig markdig@noreply.github.com
Cc: Subscribed subscribed@noreply.github.com
Subject: Re: [lunet-io/markdig] How can I exempt stretches of text from being processed as Markdown? (#350)
I did some testing, and this depends on there being no blank lines inside the HTML blocks. If you have this:
foo
bar
That will general HTML inside the div because of the blank line after the opening tag.
In my situation, due to some pre-processing that generates the Markdown, I can't guarantee there won't be any blank lines.
Do I have any options to toggle Markdown processing in this situation?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/lunet-io/markdig/issues/350?email_source=notifications&email_token=AAPQMIWLD7PVFNMYFVLCZP3P5MRKBA5CNFSM4H4VX5U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZAX4BA#issuecomment-507608580 , or mute the thread https://github.com/notifications/unsubscribe-auth/AAPQMIULT6LQ6GRKQ3MP3ALP5MRKBANCNFSM4H4VX5UQ . https://github.com/notifications/beacon/AAPQMIV74AMVNM6MLQXTSXTP5MRKBA5CNFSM4H4VX5U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZAX4BA.gif
@deanebarker commented on GitHub (Jul 2, 2019):
There might be child tags, also with blank lines. Worst case I could try to strip all newlines in a post-post-processing step, but I feel like this would be a handy addition to the library in general. There are other situations where this might come up.
@xoofx commented on GitHub (Jul 2, 2019):
It requires a new kind of raw custom container. PR welcome. If someone tackle this, I would like to see a proposal of the syntax, including a check on other major Markdown libraries (including Pandoc) in case we could reuse/agree on a similar syntax
@MihaZupan commented on GitHub (Jul 2, 2019):
You could also use fenced code blocks for this, I think that would be the least intrusive language-wise.
If you don't want to see
<code>and language html in the result, you can replace those blocks when post-processing the document.For example using "mdignore" as the info:
If you want to extract the actual content from the block (for example if you want to use a ParagraphBlock instead):
Side-note:
Even for a simple example like this it would be useful to have some more "document api" like ReplaceBy for Blocks. I can do PR for that.
@deanebarker commented on GitHub (Jul 3, 2019):
Here's what I found in AsciiDoc: Literal blocks
Elsewhere it says that block fencing is:
So, I think it would open and close with four dots.
@deanebarker commented on GitHub (Jul 3, 2019):
Here is Textile's version: notextile
The inline version is double equals:
@MihaZupan commented on GitHub (Jul 3, 2019):
That looks to me like a similar approach to using code blocks. Since they are already a part of regular markdown, is there some limitation preventing their use in your case?
@deanebarker commented on GitHub (Jul 3, 2019):
Explain to me the syntax. I see the
mdignorestuff above, to go in the "info", but I'm a little fuzzy on how that syntax might actually work/look.@MihaZupan commented on GitHub (Jul 3, 2019):
The simplest syntax is the indented code block where you indent a block with 4 spaces.
I personally prefer the fenced code blocks, for those you enclose text with three (or more) backticks or tildes and you can also specify the "info" aka language. This is what you use to get syntax highlighting on GitHub for example.
This will enclose the inner text in
<pre><code></code></pre>tags, so that's what I meant by replacing those elements from the document. Then markdown like this would not emit extra tags but simply embed the text as it was in the source.@deanebarker commented on GitHub (Jul 3, 2019):
So...?
@MihaZupan commented on GitHub (Jul 3, 2019):
Yes just three backticks at start and end
@deanebarker commented on GitHub (Jul 3, 2019):
Okay, putting together your stuff from above, I get this, which does work.
Markdown
Code (note: I've never gone past the
Markdown.ToHtml()static method before, so this might suck...)Result
Does that code look fine? If so (and even if not), I have a solution and we can probably resolve.
(I do think this might be handy to build into the core @xoofx, even if just like @MihaZupan has suggested above.)
@MihaZupan commented on GitHub (Jul 3, 2019):
The code looks fine, if you find yourself using a custom pipeline don't forget to also call
pipeline.Setup(renderer);before rendering.@deanebarker commented on GitHub (Jul 3, 2019):
Just implemented this in my production project. It works beautifully -- solves so many problems and eliminates so many workarounds.
Thank you for all the help on this, and I hope this issue resolution helps others down the road.