Skip to content

Make the line numbers of the source code clickable #20092

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

Merged
merged 2 commits into from
Jan 6, 2015

Conversation

barosl
Copy link
Contributor

@barosl barosl commented Dec 21, 2014

While talking on IRC, someone wanted to post a link to the Rust source code, but while the lines of the rendered source code do have anchors (<span id="[line number]">), there is no convenient way to make links as they are not clickable. This PR makes them clickable.

Also, a minor fix of the FAQ is included.

@rust-highfive
Copy link
Contributor

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@barosl barosl changed the title Rustdoc line number clickable Make the line numbers of the source code clickable Dec 21, 2014
@barosl barosl force-pushed the rustdoc-line-number-clickable branch from 76c1437 to 9dc1e1c Compare December 21, 2014 01:36
@@ -17,7 +17,7 @@ Some examples that demonstrate different aspects of the language:
* [sprocketnes], an NES emulator with no GC, using modern Rust conventions
* The language's general-purpose [hash] function, SipHash-2-4. Bit twiddling, OO, macros
* The standard library's [HashMap], a sendable hash map in an OO style
* The extra library's [json] module. Enums and pattern matching
* The standard library's [json] module. Enums and pattern matching
Copy link
Member

Choose a reason for hiding this comment

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

This change, while good, is totally unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was in worry of opening another PR to handle such a minor change. (It felt like spamming.) May I open a new one anyways?

@Gankra
Copy link
Contributor

Gankra commented Dec 21, 2014

Our actual highlighting script supports ranges: http://doc.rust-lang.org/src/core/slice.rs.html#456-470, which Github's UI supports through shift-clicking line numbers.

Possible?

@barosl barosl force-pushed the rustdoc-line-number-clickable branch from 9dc1e1c to 2169702 Compare December 21, 2014 04:04
@barosl
Copy link
Contributor Author

barosl commented Dec 21, 2014

@gankro Challenge accepted. I've pushed a new implementation. Currently running tests.

@barosl barosl force-pushed the rustdoc-line-number-clickable branch 2 times, most recently from 6374597 to 5bce14b Compare December 21, 2014 04:35
@huonw
Copy link
Member

huonw commented Dec 21, 2014

This is cool! Would it be possible to publish an example somewhere so we can experiment?

(If you don't have an alternative, you can use github pages: e.g. commit a generated copy to a gh-pages branch in your rust repo and push that, and they'll appear as barosl.github.io/rust/path/to/docs.)

@alexcrichton
Copy link
Member

Awesome! Could you also put the new JS wad into main.js instead of inline as well?

@barosl barosl force-pushed the rustdoc-line-number-clickable branch 4 times, most recently from 01ea47e to a5617b6 Compare December 21, 2014 19:00
@barosl
Copy link
Contributor Author

barosl commented Dec 21, 2014

@huonw I've uploaded them to https://barosl.com/tmp/rust/doc/src/std/lib.rs.html

@alexcrichton Oops, sorry. I should have considered that. It is fixed now.

@barosl
Copy link
Contributor Author

barosl commented Dec 21, 2014

I've changed a bit more, using the HTML5 history API(pushState) if the browser supports it. This prevents the page from being scrolled.

Also, I also removed the unused :target style in main.css, which caused color inconsistency when highlighting was triggered by loading a page.

@barosl barosl force-pushed the rustdoc-line-number-clickable branch from a5617b6 to 9bf309a Compare December 21, 2014 19:06
@@ -464,8 +473,6 @@ h1 .stability {
.summary.Stable { background-color: #54A759; }
.summary.Unmarked { background-color: #BBBBBB; }

:target { background: #FDFFD3; }
Copy link
Member

Choose a reason for hiding this comment

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

I think this CSS rule was also used for clicking on headers in documentation. That may be covered elsewhere, but can you make sure that if you click on a header that it still gets highlighted?

@barosl barosl force-pushed the rustdoc-line-number-clickable branch from 9bf309a to 87d4444 Compare December 27, 2014 03:49
@barosl barosl force-pushed the rustdoc-line-number-clickable branch from 87d4444 to 739f74b Compare December 27, 2014 03:50
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 5, 2015
While talking on IRC, someone wanted to post a link to the Rust source code, but while the lines of the rendered source code do have anchors (`<span id="[line number]">`), there is no convenient way to make links as they are not clickable. This PR makes them clickable.

Also, a minor fix of the FAQ is included.
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 6, 2015
While talking on IRC, someone wanted to post a link to the Rust source code, but while the lines of the rendered source code do have anchors (`<span id="[line number]">`), there is no convenient way to make links as they are not clickable. This PR makes them clickable.

Also, a minor fix of the FAQ is included.
@bors bors merged commit 739f74b into rust-lang:master Jan 6, 2015
barosl added a commit to barosl/rust that referenced this pull request Jan 7, 2015
Due to the CSS changes done by the previous patch to make the line
numbers clickable (rust-lang#20092), the sidebar became unclickable. This commit
reverts the changes and adopts an alternative approach.
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 8, 2015
Due to the CSS changes done by the previous patch to make the line numbers clickable (rust-lang#20092), the sidebar became unclickable. This PR reverts the changes and adopts an alternative approach.

I'm very sorry for having broken things.
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.

8 participants