Skip to content

'class' attribute value in preAttributes and codeAttributes doesn't work #52

@handreistoicescu

Description

@handreistoicescu

Description

When a user adds a class attribute value to preAttributes or codeAttributes, nothing happens:

eleventyConfig.addPlugin(pluginSyntaxHighlight, {
    preAttributes: {
      class: "hey-this-is-a-custom-class-name",
    },
    codeAttributes: "this-is-also-custom-class-name",
});

Resulting DOM:

Screenshot 2021-06-03 at 23 48 32

I assume this is because <pre> and <code> already have a class name that denotes the language being used (e.g. language-js).

Possible solutions

  1. Maybe we can concatenate the new class names to the existing one, taking care not to overwrite the originals
  2. ...or add the possibility for the user to add a wrapper element over the <pre>, because the scenario (at least in my case) is to add some layout styling to the code block (say, max-width):
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
    wrapper: {
      element: "div",
      attributes: {
         // here be attributes
      }
    },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions