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

Provide a | highlight filter as well? #15

Open
mirisuzanne opened this issue Sep 14, 2019 · 6 comments
Open

Provide a | highlight filter as well? #15

mirisuzanne opened this issue Sep 14, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@mirisuzanne
Copy link

The paired shortcode is great when I know that an entire block rendered in my template will be code - but sometimes I'm rendering arbitrary markdown that might have code blocks nested inside. In that case, I'd love to do something like:

{{ data | markdown | highlight | safe }}

For now, I'll try importing prism as a stand-alone in addition to eleventy-plugin-syntaxhighlight - and use it to generate a custom filter (or tag along on my markdown filter).

@zachleat zachleat added the enhancement New feature or request label Jan 3, 2020
@schneyra
Copy link

schneyra commented May 1, 2020

I'd love this, too. I'm using a CMS as source for my blogposts and it delivers pre-rendered HTML where code is embedded.

<pre class="language-css"><code>[...]</code><pre>

I hope I haven't overlooked anything, but I'd like to do something like {{ article.content | highlight | safe }}.

@jinsupark
Copy link

Just ran into this problem! This would be super helpful indeed.

@zachleat
Copy link
Member

You can DIY this with something like:

const { pairedShortcode } = require("@11ty/eleventy-plugin-syntaxhighlight");

module.exports = function(eleventyConfig) {
  eleventyConfig.addFilter("highlight", function(content, language) {
    return pairedShortcode(content, language);
  });
};

@mirisuzanne
Copy link
Author

@zachleat I don't think that quite solves the initial issue here - which is that only some of the content might involve fenced code, and only that code should be highlighted. If I understand this right, it would turn the entire content into a code-block instead.

@stillingdesign
Copy link

Just wanted to check-in on this and see if anyone has found a good solution? Running into this same problem.

@Snapstromegon
Copy link
Member

Even though I didn't take a closer look at this plugin, IMO it should be possible to do this.

I personally switched away to using shiki as a highlighter and wrote a short blogpost on how to do it:
https://www.hoeser.dev/blog/2023-02-07-eleventy-shiki-simple/

The code from the TLDR should be possible to adapt to also allow for a highlight filter too.

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

No branches or pull requests

6 participants