Closed
Description
We had to disable classes on code
tags because you could use arbitrary classes to do arbitrary things. So for now, syntax highlighting in readmes is disabled.
I've filed an issue with Ammonia to request being able to specify allowed values for attributes (or at least classes); these are the classes that marky-markdown (used by npm) allows for their README rendering.
Instructions for implementing:
- We've already updated to ammonia 0.7.0, which now has support for this!
- Add the
allowed_classes
field to the ammonia configuration struct with a hash map that contains the tag name"code"
and a value of aHashSet
containing all the languages we want to support highlighting prefixed bylanguage-
, solanguage-bash
,language-clike
, etc. - Add a test in here like these tests that calls
markdown_to_html
with a code block that should get syntax highlighting, and assert that thecode
tag hasclass="language-whatever"
- Add another test in there that tries to add classes that aren't allowed to a
code
element, or other classes to other elements, and assert that they aren't in the rendered HTML - BONUS: I'm happy to test this for real, but if you're feeling ambitious, publish a crate that has a README with some code in it to your local crates.io instance with the code change (instructions on publishing to your own instance are here) and make sure it is highlighted.