Skip to content

Allow to customize attributes applied to the <pre>/<code> tags #22

@dweidner

Description

@dweidner

The syntaxhighlight plugin provides its own wrappers for code blocks (src/markdownSyntaxHighlightOptions.js:36) which overrides the default wrapper provided by markdown-it/markdown-it#189. Unfortunatly that leaves no room to customize the generated markup as we cannot use a custom renderer rule for code fence blocks. Removing the wrapper from the plugin however, would result in a breaking change as some sites may use the class on the <pre> tag as a styling hook.

Would you be open for a PR that implements an additional option to add custom attributes to the <pre> tag? I would love to display the highlighted language next to my code blocks. Currently my only option would be to do this entirely in CSS:

pre[class$='css'],
pre[class$='scss'],
pre[class$='js'],
pre[class$='php'] {
  position: relative;

  &::after {
    position: absolute;
    top: 0;
    right: 0;
    // ...
  }
}

pre[class$='css']::after  { content: 'CSS' }
pre[class$='scss']::after { content: 'SCSS' }
pre[class$='js']::after   { content: 'JavaScript' }
pre[class$='php']::after  { content: 'PHP' }
//

This would be much easier if I could add a data attribute to the <pre> tag:

pre[class|="language"][data-language] {
  position: relative;

  &::after {
    content: attr(data-language);
    //
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions