mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
Request for help/sample #269
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 @picrap on GitHub (Jan 29, 2019).
Hi, I'm trying to create a custom parser/custom renderer, and I'm quite desperate 😢
I want to create an extension that may simply change the severity (warning, error) of a text between exclamation marks, so
!!this is a warning!!and!!!this is an error!!!would generate in HTML a<span>with the right color. I want blocks, because I want to be able to use inner emphasis, such as!!I'm not **happy**!!.So I started Implement my own
BlockParserandBlockRendererboth using my ownContainerBlock, however theContainerBlockhas no children. I've looked at themarkdigsource code which I don't understand much, so I'm basically lost. How have myContainerBlockchildren filled?@xoofx commented on GitHub (Jan 29, 2019):
If it is a span, it means that it's not a block, so you are likely looking for an inline parser. From the many extensions, find one that has a similar syntax and try to adapt it.
@picrap commented on GitHub (Jan 29, 2019):
What is the difference between a span and a block? (Because I also implemented a span and got the same empty children sequence).
@xoofx commented on GitHub (Jan 29, 2019):
Not sure to understand. You know the difference in HTML no?
@picrap commented on GitHub (Jan 29, 2019):
So it's a pure layout difference?
Also, I read the "many extensions", none of them really helped 😭
@xoofx commented on GitHub (Jan 29, 2019):
Sorry, but I really don't have time to help. You have to do your homework here. Many extensions are very simple. First you need to understand the difference between an inline and a block in CommonMark specs. In markdig, we are just replicating what is in CommonMark, we have block parsers (e.g fenced code blocks) and inline parsers (e.g emphasis, links...) Then you need to find an extension that has a similar syntax that you want to achieve and adapt it. The closest maybe is Custom containers and their specs
@picrap commented on GitHub (Jan 29, 2019):
EDIT: I cooled down. Thanks for links.
@MihaZupan commented on GitHub (Jan 29, 2019):
This is adapted from Custom Containers
@MihaZupan commented on GitHub (Jan 29, 2019):
In theory, triple characters could be added the same way, but currently the underlying Emphasis parser only works with max 2, so that'll have to be patched first for this approach.
Look at the Custom Containers extension source to see how it does the triple opening character for blocks.
@MihaZupan commented on GitHub (Jan 29, 2019):
The example above is literally the same as found in CC, with the name changed and ':' set to '!'
@picrap commented on GitHub (Jan 29, 2019):
Hi, thanks.
The point I missed when opening this issue is that the
bool Match(InlineProcessor processor, ref StringSlice slice)method should only insert as new block its own markup, then let the process deal with the following inlines. My mistake was to insert the whole part between opening and closing marks. Things are getting clearer now.Again, thanks.
@MihaZupan commented on GitHub (Jan 29, 2019):
With #301, doing this with the Emphasis parser should work properly.