Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pug template support #34

Closed
brettinternet opened this issue Sep 16, 2020 · 1 comment
Closed

Pug template support #34

brettinternet opened this issue Sep 16, 2020 · 1 comment

Comments

@brettinternet
Copy link

The Pug template option is not currently supported. Given Pug's popularity, it would be nice to support it.

@brettinternet
Copy link
Author

brettinternet commented Sep 19, 2020

I have found that the pug markdown filter is very easy to extend. Perhaps the "pug way" to accomplish syntax highlighting is much better without any intervention from this library.

We can however make use of src/HighlightPairedShortcode.js and its abstraction of PrismJS as it's implemented for the Nunjucks shortcode.

Here's an example of what that looks like:

.eleventy.js:

const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const {
  pairedShortcode: eleventyHighlighter,
} = require('@11ty/eleventy-plugin-syntaxhighlight')

const highlight = (content, args) => {
  if (args) {
    const [lang, ...highlightNumbers] = args.split(' ')
    return eleventyHighlighter(content, lang, highlightNumbers.join(' '))
  }
}

const markdown = markdownIt({
  html: true,
  linkify: true,
  typographer: true,
  highlight,
})
  .use(markdownItAnchor)
  .disable('code')

module.exports = (config) => {
  config.setPugOptions({
    filters: {
      markdown: (text, options) =>
        markdown.set(options).set({ highlight }).render(text),
    },
  })
}

index.pug:

:markdown
  # Markdown

  Markdown document with http://links.com and

  ```js
  var codeBlocks;
  ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant