Closed andria-dev closed 3 years ago
Going to merge this but I wonder if we should also change tabindex="0"
to be added by default? Maybe in the next major version
I’ll probably also remove the string support as I think the object literal support is probably sufficient (if you disagree please chime in!)
Filed the tabindex question at #49
This is fantastic! I added PR #50 to enable dynamic attributes to be generated based on context data — this will for example allow the language to be provided directly as an attribute (see #22 use-case, solved with example below). I hope this isn't already available with this PR as I couldn't get it to work, but please let me know if I'm wrong.
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
preAttributes: {
'data-lang': function (context) { return context.language.toUpperCase(); }
}
});
Fixes #22
I created a function,
getAttributes(attributes)
, that takes either a string or an object of strings or numbers and outputs a string of HTML attributes. This function is then used to allow the use of the followingoptions
:preAttributes
andcodeAttributes
. Usage is as follows:This will add
tabindex="0"
to the<pre>
tag — allowing code blocks with scrollbars to be keyboard accessible — like so: