Skip to content

Snippet include file brefore/after label #2296

Answered by facelessuser
astromatt asked this question in Q&A
Discussion options

You must be logged in to vote

@astromatt

Just wrap your logic around the default highlighter.

  1. I changed the path handling just to make it easier for me to throw together the example. It looks in the same folder as the script. You can change it back to what you were doing.
  2. Use the default highlight validator to get the same options.
  3. Wrap your logic around the default validator.
import re
from pathlib import Path
from pymdownx.superfences import SuperFencesException, highlight_validator
import markdown

MD = """
```include title="Title"
file="myfile.py"
before="# Solution"
```
"""

def formatter(source, language, css_class, options, md, **kwargs):
    file = re.search(r'file="(.+)"', source).group(1)
    before = re.s…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by facelessuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
T: feature Feature. S: triage Issue needs triage.
2 participants
Converted from issue

This discussion was converted from issue #2294 on January 08, 2024 17:19.