Skip to content

Allow showing only a range of lines for code blocks #2242

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

You must be logged in to vote

Here's an example. We override all languages with * and define our custom formatter and validator. In our custom validator we validate our new option and then feed the great of the inputs through the default code validator. Then in our formatter, we check for our new option, modify the source as needed, and send it through the default highlight logic. That's it. It should work on any language then.

"""Example custom fence."""
import markdown
from pymdownx.superfences import highlight_validator


def remove_validator(language, inputs, options, attrs, md):
    """Highlight validator."""

    # Add validation for special new options
    for k, v in inputs.items():
        if k == 'show_lines':…

Replies: 6 comments 10 replies

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
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@facelessuser
Comment options

@llucax
Comment options

@facelessuser
Comment options

@llucax
Comment options

@facelessuser
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@facelessuser
Comment options

@llucax
Comment options

@geoffreyweal
Comment options

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.
3 participants
Converted from issue

This discussion was converted from issue #2240 on November 20, 2023 14:00.