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

rustdoc: Add syntax highlighting #12416

Merged
merged 1 commit into from Feb 23, 2014
Merged

Conversation

alexcrichton
Copy link
Member

This adds simple syntax highlighting based off libsyntax's lexer to be sure to
stay up to date with rust's grammar. Some of the highlighting is a bit ad-hoc,
but it definitely seems to get the job done!

This currently doesn't highlight rustdoc-rendered function signatures and
structs that are emitted to each page because the colors already signify what's
clickable and I think we'd have to figure out a different scheme before
colorizing them. This does, however, colorize all code examples and source code.

Closes #11393

@alexcrichton
Copy link
Member Author

Preview: http://www.contrib.andrew.cmu.edu/~acrichto/doc/std/index.html

I just picked the color scheme out of my terminal, no attachment to it!

loop {
let next = lexer.next_token();
let test = if next.tok == t::EOF {lexer.pos.get()} else {next.sp.lo};
if test > last {
Copy link
Member

Choose a reason for hiding this comment

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

This is testing if there's a gap between two tokens, and then checking if that gap contains a comment, right?

Copy link
Member

Choose a reason for hiding this comment

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

(Could you add a comment?)

@alexcrichton
Copy link
Member Author

Pushed with comments addressed.

@@ -1231,7 +1232,7 @@ fn render_method(w: &mut Writer, meth: &clean::Item) -> fmt::Result {

fn item_struct(w: &mut Writer, it: &clean::Item,
s: &clean::Struct) -> fmt::Result {
try!(write!(w, "<pre class='struct'>"));
try!(write!(w, "<pre class='rtry struct'>"));
Copy link
Member

Choose a reason for hiding this comment

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

Something got mangled?

@huonw
Copy link
Member

huonw commented Feb 21, 2014

r=me with comments addressed.

@emberian
Copy link
Member

This is awesome. The colors suck, but that's an easy fix for later.

@alexcrichton
Copy link
Member Author

The colors suck

I like my terminal's colors :(

That's also why I'd never get hired as a designer!

This adds simple syntax highlighting based off libsyntax's lexer to be sure to
stay up to date with rust's grammar. Some of the highlighting is a bit ad-hoc,
but it definitely seems to get the job done!

This currently doesn't highlight rustdoc-rendered function signatures and
structs that are emitted to each page because the colors already signify what's
clickable and I think we'd have to figure out a different scheme before
colorizing them. This does, however, colorize all code examples and source code.

Closes rust-lang#11393
bors added a commit that referenced this pull request Feb 23, 2014
This adds simple syntax highlighting based off libsyntax's lexer to be sure to
stay up to date with rust's grammar. Some of the highlighting is a bit ad-hoc,
but it definitely seems to get the job done!

This currently doesn't highlight rustdoc-rendered function signatures and
structs that are emitted to each page because the colors already signify what's
clickable and I think we'd have to figure out a different scheme before
colorizing them. This does, however, colorize all code examples and source code.

Closes #11393
@bors bors closed this Feb 23, 2014
@bors bors merged commit ad9e26d into rust-lang:master Feb 23, 2014
@alexcrichton alexcrichton deleted the highlight branch February 23, 2014 21:14
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 7, 2024
Add missing header for `manual_is_variant_and`

Noticed this while generating our lint completions failed in rust-analyzer (separate PR from rust-lang/rust-clippy#12415 as I made these via the github interface quickly)
changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Teach rustdoc to syntax highlight
4 participants