Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Support multiple classes for fenced code blocks #775

Closed

Description

@nsheff

Right now, fenced code blocks can be assigned a class (which is typically used to define the language). But it is impossible to assign more than one class.

You may want to do this, for example, to distinguish input code blocks from output code blocks in a vignette. Right now, if you try to define multiple classes in a markdown fence block, using {.class1 .class2}, the HTML is not parsed correctly as a code block.

For a use case, see: mkdocs/mkdocs#1720

You may want to say: {.python .inputblock} or {.bash .outputblock} to add a second layer of distinguishing code blocks.

Activity

  1. added
    needs-decision
    on Jan 9, 2019
  2. waylan commented on Jan 14, 2019

    @waylan
    Member

    We should probably add support for this to bring our extension inline with PHP Markdown Extra's extension. A discussion of (and the code for) that implementation can be found at michelf/php-markdown#7.

  3. added
    feature
    extension
    confirmed
    and removed
    needs-decision
    on Jan 14, 2019
  4. facelessuser commented on Jan 15, 2019

    @facelessuser
    Collaborator

    So it seems that .classes and #id are allowed in fenced blocks over at PHP Markdown. They threw out attributes from what I can tell. I know Python Markdown allows other options via key="value" for settings.

    Am I to assume the idea is to allow these all to be intermingled?

    ```language .class #id option="value" .more-classes
    content
    ```
    

    Or to assume that classes and ids must come before options?

    ```language .class #id .more-classes option="value"
    content
    ```
    

    It's a small thing, but important to note when we are deciding how to refactor this to support such behavior.

  5. waylan commented on Jan 15, 2019

    @waylan
    Member

    I know Python Markdown allows other options via key="value" for settings.

    Right. I forgot about that. Thanks for the reminder.

    allow these all to be intermingled?

    Good question. I'm not sure what the best approach is here.

    I suppose that this is a significant factor in why we haven't yet added support. There are a lot of moving parts between settings which control the highlighter (Pygments) and attributes to the HTML which provide CSS hooks.

  6. facelessuser commented on Jan 15, 2019

    @facelessuser
    Collaborator

    I don't think it will too hard to implement, but we definitely need to clearly define how we want it to look. I personally prefer that the style stuff comes first, but that is more of a preference than it is something with solid reasons behind it 🤷‍♂️ .

  7. waylan commented on Jan 15, 2019

    @waylan
    Member

    There are two extensions at work here. The fenced_code extension, which assigns the classes/id to the HTML elements and code_hilite, which handles code highlighting. I'm thinking there needs to be an obvious separation between the two, but what that separation should be is not clear.

  8. waylan commented on Apr 12, 2019

    @waylan
    Member

    I think perhaps the best approach here is to use .class and #id for attributes on the generated HTML elements (with .class .otherclass for more than one class). Then key=value pairs should be reserved for codehilight options only. I don't think it matters what order the various pieces are listed in, but in the docs we probably want to be consistent.

    But how do we determine which "class" designates the language? The first .class in the list? Whichever one is prepended with language- (for example .language-python). I think probably we can support both. Perhaps something like this: If a single string (with or without a dot), use that, else if a .language-* class is defined, use that, else if the first item is a dot class, use that, else no language is defined.

  9. linked a pull request that will close this issueRefactor fenced code attributes #816on Mar 26, 2020
  10. added a commit that references this issue on Jun 23, 2020
    10058fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedextensionfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions