Expand description
Basic syntax highlighting functionality.
This module uses librustc_astβs lexer to provide token-based highlighting for the HTML documentation generated by rustdoc.
Use the render_with_highlighting to highlight some rust code.
StructsΒ§
- Classifier πProcesses program tokens, classifying strings of text by highlighting category (
Class). - DecorationInfo πDecorations are represented as a map from CSS class to vector of character ranges. Each range will be wrapped in a span with that class.
- Decorations πCustom spans inserted into the source. Eg βscrape-examples uses this to highlight function calls
- HrefContext πThis type is needed in case we want to render links on items to allow to go to their definition.
- PeekIter πThis iterator comes from the same idea than βPeekableβ except that it allows to βpeekβ more than just the next item by using
peek_next. Thepeekmethod always returns the next item after the current one whereaspeek_nextwill return the next item after the last one peeked. - TokenHandler πThis type is used as a conveniency to prevent having to pass all its fields as arguments into the various functions (which became its methods).
- TokenIter π
EnumsΒ§
- Class πHow a span of text is classified. Mostly corresponds to token kinds.
- Highlight π
- Tooltip π
FunctionsΒ§
- can_merge πCheck if two
Classcan be merged together. In the following rules, βunclassifiedβ meansNonebasically (since itβsOption<Class>). The following rules apply: - enter_span πCalled when we start processing a span of text that should be highlighted. The
Classargument specifies how it should be highlighted. - exit_span πCalled at the end of a span of highlighted text.
- get_real_ident_class πClassifies into identifier class; returns
Noneif this is a non-keyword identifier. - Highlights
srcas an inline example, returning the HTML output. - Highlights
srcas an item-decl, returning the HTML output. - string πCalled for a span of text. If the text should be highlighted differently from the surrounding text, then the
Classargument will be a value other thanNone. - This function writes
textintooutwith some modifications depending onklass: - write_code πConvert the given
srcsource code into HTML by adding classes for highlighting. - write_footer π
- write_header π