Skip to content

Language detected is wrong when using comments inside the block #2517

@luispcosta

Description

@luispcosta

I've opened this ticket over at highlightjs and they suspect that this might have to do with mkdocs instead of highlightjs...

Whenever a code block contains code in comments, the CSS class(es) applied to the code block is of a different language which will naturally screw up the syntax and the visual apparence of the text.
I could reproduce this issue with, at least, objectivec and swift.

When writing:

Screenshot 2021-07-22 at 09 12 50

And:

Screenshot 2021-07-22 at 09 13 09

It produces the wrong highlighting:

Screenshot 2021-07-22 at 09 14 10

If we take a look at the classes added:

For the Objective-C block:
Screenshot 2021-07-22 at 09 17 38

It's identifying the block as an SQL code block...

For the Swift Block:
Screenshot 2021-07-22 at 09 18 04

It's identifying the block as a bash code block...

If we remove the comments from the markdown

Screenshot 2021-07-22 at 09 21 17

Expected behavior
I expected the code blocks to appear correctly with the comment syntax.

Additional context

  • I'm using mkdocs version 1.0.4 and pymdown-extensions 7.1 and Markdown 3.2.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions