diff --git a/.eleventy.js b/.eleventy.js index 392b2c3..07e0378 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -7,7 +7,8 @@ const markdownPrismJs = require("./src/markdownSyntaxHighlightOptions"); module.exports = { initArguments: { Prism }, configFunction: function(eleventyConfig, options = {}) { - options = Object.assign({ alwaysWrapLineHighlights: false }, options); + options = Object.assign({ alwaysWrapLineHighlights: false, + showLineNumbers: false}, options); // TODO hbs? if( hasTemplateFormat(options.templateFormats, "liquid") ) { @@ -26,6 +27,9 @@ module.exports = { }); } + // this is where the plugin code gets hooked up + // in the default md's highlighter + if( hasTemplateFormat(options.templateFormats, "md") ) { eleventyConfig.addMarkdownHighlighter(markdownPrismJs(options)); } diff --git a/README.md b/README.md index ca5b52c..e75be6c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,19 @@ # eleventy-plugin-syntaxhighlight +To show line numbers, set the `showLineNumbers` option to true. +This is a global setting. + +``` +module.exports = function(eleventyConfig) { + eleventyConfig.addPlugin(syntaxHighlight, { + alwaysWrapLineHighlights: true, + showLineNumbers: false + }); + + eleventyConfig.setTemplateFormats("njk,liquid,md,css"); +}; +``` + A pack of [Eleventy](https://github.com/11ty/eleventy) plugins for syntax highlighting. No browser/client JavaScript here, these highlight transformations are all done at build-time. ## Read the [Full Documentation on 11ty.dev](https://www.11ty.dev/docs/plugins/syntaxhighlight/) diff --git a/demo/eleventy-config.js b/demo/eleventy-config.js index ba2cbe7..d17ec49 100644 --- a/demo/eleventy-config.js +++ b/demo/eleventy-config.js @@ -2,7 +2,8 @@ const syntaxHighlight = require("../.eleventy.js"); module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(syntaxHighlight, { - // alwaysWrapLineHighlights: true + alwaysWrapLineHighlights: true, + showLineNumbers: false }); eleventyConfig.setTemplateFormats("njk,liquid,md,css"); diff --git a/demo/line-numbers.css b/demo/line-numbers.css new file mode 100644 index 0000000..43e47d1 --- /dev/null +++ b/demo/line-numbers.css @@ -0,0 +1,54 @@ +/*** + * LINE NUMBERS + * https://raw.githubusercontent.com/PrismJS/prism/master/plugins/line-numbers/prism-line-numbers.css + ***/ + + pre[class*="language-"].line-numbers { + position: relative; + padding-left: 3.8em; + counter-reset: linenumber; +} + +pre[class*="language-"].line-numbers > code { + position: relative; + white-space: inherit; +} + +.line-numbers .line-numbers-rows { + position: absolute; + pointer-events: none; + top: -4px; /* hack to get numbers to line up with text */ + font-size: 100%; + left: -3.8em; + width: 3em; /* works for line-numbers below 1000 lines */ + letter-spacing: -1px; + border-right: 1px solid #999; + + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + +} + +.line-numbers-rows > span { + pointer-events: none; + display: block; + counter-increment: linenumber; +} + +.line-numbers-rows > span:before { + content: counter(linenumber); + color: #999; + display: block; + padding-right: 0.8em; + text-align: right; +} + +.highlight-line-add { + background-color: rgb(197, 234, 197); +} + +.highlight-line-remove { + background-color: rgb(253, 204, 204); +} diff --git a/demo/test-markdown.md b/demo/test-markdown.md index 2dda09c..ed93463 100644 --- a/demo/test-markdown.md +++ b/demo/test-markdown.md @@ -5,26 +5,35 @@