11ty / eleventy-plugin-syntaxhighlight

A pack of Eleventy plugins for syntax highlighting in Markdown, Liquid, and Nunjucks templates.
https://www.11ty.dev/docs/plugins/syntaxhighlight/
MIT License
130 stars 32 forks source link

Add language name as data-attribute #65

Closed fhemberger closed 2 years ago

fhemberger commented 2 years ago

Allows displaying highlight language name as a hint, e.g.:

pre[class*="language-"]::before {
  content:attr(data-language-name);
  display: inline-block;
  position: absolute;
  top: 0;
  right: 0;
  padding: 4px 10px 2px;
  background-color: #e6e6e6;
  border-bottom: 1px solid #dddddd;
  border-left: 1px solid #dddddd;
  border-bottom-left-radius: 6px;
  font-size: 0.75em;
}

results in:

fhemberger commented 2 years ago

Not sure this is possible to inject as an "advanced option" instead, as preAttributes only allows static attributes.

zachleat commented 2 years ago

Rather than a hardcoded option here, we are shipping #50 that will allow you to specify your own callbacks for any attribute name!

zachleat commented 2 years ago

You’ll want something like this to replicate what you have in this PR:

preAttributes: {
  "data-language-name": ({language}) => language
}
fhemberger commented 2 years ago

Great, thank you! Much cleaner solution.