Skip to content

When ammonia supports allowing only certain values for attributes, re-enable syntax highlighting #1008

Closed
@carols10cents

Description

@carols10cents

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 a HashSet containing all the languages we want to support highlighting prefixed by language-, so language-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 the code tag has class="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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions