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

Added new Not all plugin #2074

Merged
merged 13 commits into from
Dec 2, 2019
Merged

Conversation

RunDevelopment
Copy link
Member

This adds a new plugin Not all with allows to filter out certain elements the highlightAll and highlightAllUnder methods query.

This adds a new filter property to the env of before-highlightall which can be used to add filters. I named it filter because it very much behaves like Array#filter.

This also exposes getLanguage as Prism.util.getLanguage.


@asbjornu
My attempt to fix #2068.

@asbjornu
Copy link

Thanks for this, @RunDevelopment! Much appreciated! 🙏

@asbjornu
Copy link

I just thought that it would be completely awesome if this was possible to configure in a data- attribute on the <script> element, so no custom JavaScript was necessary and the data-manual attribute could be removed.

@RunDevelopment
Copy link
Member Author

Done. Now you can do the following:

<script src="prism.js" data-exclude-css=".no-highlight, .no-highlight *"></script>

This will exclude all element with a .no-highlighting class and all elements in a element with a .no-highlighting class.

As for the original issue: You can either use filterKnown:

<script src="prism.js" data-filter-known></script>

Or define a filter function:

<script src="prism.js"></script>
<script>
Prism.plugins.notAll.filter(({ language }) => language !== 'mermaid');
</script>

@asbjornu
Copy link

@RunDevelopment, Fantastic! 🎉 Thank you so much! 🙏

@RunDevelopment RunDevelopment added this to the 1.18.0 milestone Oct 25, 2019
components.json Outdated Show resolved Hide resolved
@mAAdhaTTah
Copy link
Member

Sorry I took so long to get to this. Thanks for your patience!

@mAAdhaTTah
Copy link
Member

Just need to bikeshed some naming here but the code itself is great! Thanks for your patience.

@RunDevelopment
Copy link
Member Author

Should be good to go now.

Copy link
Member

@mAAdhaTTah mAAdhaTTah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That took some massaging, but this looks good to me! Thanks for the work on this. One more PR to go for this release...

@RunDevelopment RunDevelopment merged commit a7f7009 into PrismJS:master Dec 2, 2019
@RunDevelopment RunDevelopment deleted the not-all branch December 2, 2019 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude certain languages from highlighting altogether
3 participants