You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Sorry if this is a silly question - I've just started using mistletoe today! (I really like the interface, thank you for your work!)
I'd like to implement an [embed]: (file.txt) token, which will read the file and include it inline.
I have code like this:
classEmbed(SpanToken):
parse_inner=Falsepattern=re.compile(r"\[embed\]\s*:?\s*#?\s*\((.*)\)")
def__init__(self, match):
self.include_path=match.group(1)
classWriteupRenderer(HtmlRenderer):
def__init__(self, **kwargs):
super().__init__(Embed, **kwargs)
defrender_embed(self, token: Embed):
# will read and output the file contentsreturn"RENDERING EMBED"
The only issue is that most of my embeds live inside code blocks or code fences like:
`code with [embed]: (./shell64.s)`
Which results in markup that's expected to me now, but I'd like to change this behaviour:
<p><code>code with [embed]: (./shell64.s)</code></p>
(My embed tokens work fine outside of code blocks and fences)
From what I could see, the CodeBlock does not parse inner tokens, how to go about implementing this? Is it possible without re-creating too many tokens / blocks?
The text was updated successfully, but these errors were encountered:
Hi @MilyMilo, it is certainly possible to make custom tokens for fenced code blocks and for code spans with the behavior that you want, but I believe it's going to be a lot of work.
The embedding feature you want would probably be easier to build as a pre-processing step, working on the raw text input. That would also make sense from a conceptual point of view, imho.
Maybe you could use a cusomized parser which only recognizes paragraphs and links in that first step 😄
As both of you mentioned - this is currently implemented in preprocessing. We just have a regex to do that, however doesn't feel very clean and robust. That's why I wanted to use mistletoe to improve this.
I'll check if there's a nice way to get it working and post the code here if I end-up implementing this.
Hi! Sorry if this is a silly question - I've just started using mistletoe today! (I really like the interface, thank you for your work!)
I'd like to implement an
[embed]: (file.txt)
token, which will read the file and include it inline.I have code like this:
The only issue is that most of my embeds live inside code blocks or code fences like:
Which results in markup that's expected to me now, but I'd like to change this behaviour:
(My embed tokens work fine outside of code blocks and fences)
From what I could see, the CodeBlock does not parse inner tokens, how to go about implementing this? Is it possible without re-creating too many tokens / blocks?
The text was updated successfully, but these errors were encountered: