rustdoc: give .line-number
/ .line-numbers
meaningful names
This commit is contained in:
parent
e1d7dec558
commit
0b97831af7
12 changed files with 47 additions and 47 deletions
|
@ -274,7 +274,7 @@ pub(crate) fn print_src(
|
|||
) {
|
||||
let lines = s.lines().count();
|
||||
let mut line_numbers = Buffer::empty_from(buf);
|
||||
line_numbers.write_str("<pre class=\"line-numbers\">");
|
||||
line_numbers.write_str("<pre class=\"src-line-numbers\">");
|
||||
match source_context {
|
||||
SourceContext::Standalone => {
|
||||
for line in 1..=lines {
|
||||
|
|
|
@ -578,7 +578,7 @@ h2.location a {
|
|||
position: relative;
|
||||
}
|
||||
|
||||
.example-wrap > pre.line-number {
|
||||
.example-wrap > pre.example-line-numbers {
|
||||
overflow: initial;
|
||||
border: 1px solid;
|
||||
padding: 13px 8px;
|
||||
|
@ -591,15 +591,15 @@ h2.location a {
|
|||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.line-numbers {
|
||||
.src-line-numbers {
|
||||
text-align: right;
|
||||
}
|
||||
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
|
||||
.rustdoc:not(.source) .example-wrap > pre:not(.example-line-numbers) {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.rustdoc:not(.source) .example-wrap > pre.line-numbers {
|
||||
.rustdoc:not(.source) .example-wrap > pre.src-line-numbers {
|
||||
width: auto;
|
||||
overflow-x: visible;
|
||||
}
|
||||
|
@ -612,14 +612,14 @@ h2.location a {
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.content > .example-wrap pre.line-numbers {
|
||||
.content > .example-wrap pre.src-line-numbers {
|
||||
position: relative;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.line-numbers span {
|
||||
.src-line-numbers span {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
@ -2067,7 +2067,7 @@ in storage.js plus the media query with (min-width: 701px)
|
|||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
|
||||
.scraped-example:not(.expanded) .code-wrapper pre.src-line-numbers {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
|
@ -2113,12 +2113,12 @@ in storage.js plus the media query with (min-width: 701px)
|
|||
bottom: 0;
|
||||
}
|
||||
|
||||
.scraped-example .code-wrapper .line-numbers {
|
||||
.scraped-example .code-wrapper .src-line-numbers {
|
||||
margin: 0;
|
||||
padding: 14px 0;
|
||||
}
|
||||
|
||||
.scraped-example .code-wrapper .line-numbers span {
|
||||
.scraped-example .code-wrapper .src-line-numbers span {
|
||||
padding: 0 14px;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ pre, .rustdoc.source .example-wrap {
|
|||
color: #ff7733;
|
||||
}
|
||||
|
||||
.line-numbers span { color: #5c6773; }
|
||||
.line-numbers .line-highlighted {
|
||||
.src-line-numbers span { color: #5c6773; }
|
||||
.src-line-numbers .line-highlighted {
|
||||
color: #708090;
|
||||
background-color: rgba(255, 236, 164, 0.06);
|
||||
padding-right: 4px;
|
||||
|
@ -171,7 +171,7 @@ details.rustdoc-toggle > summary::before {
|
|||
color: #788797;
|
||||
}
|
||||
|
||||
.line-numbers :target { background-color: transparent; }
|
||||
.src-line-numbers :target { background-color: transparent; }
|
||||
|
||||
/* Code highlighting */
|
||||
pre.rust .number, pre.rust .string { color: #b8cc52; }
|
||||
|
@ -190,7 +190,7 @@ pre.rust .attribute {
|
|||
color: #e6e1cf;
|
||||
}
|
||||
|
||||
.example-wrap > pre.line-number {
|
||||
.example-wrap > pre.example-line-numbers {
|
||||
color: #5c67736e;
|
||||
border: none;
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ input:focus + .slider {
|
|||
background: #444;
|
||||
}
|
||||
|
||||
.line-numbers span { color: #3B91E2; }
|
||||
.line-numbers .line-highlighted {
|
||||
.src-line-numbers span { color: #3B91E2; }
|
||||
.src-line-numbers .line-highlighted {
|
||||
background-color: #0a042f !important;
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ details.rustdoc-toggle > summary::before {
|
|||
background: none;
|
||||
}
|
||||
|
||||
.line-numbers :target { background-color: transparent; }
|
||||
.src-line-numbers :target { background-color: transparent; }
|
||||
|
||||
/* Code highlighting */
|
||||
pre.rust .kw { color: #ab8ac1; }
|
||||
|
@ -155,7 +155,7 @@ pre.rust .question-mark {
|
|||
color: #ff9011;
|
||||
}
|
||||
|
||||
.example-wrap > pre.line-number {
|
||||
.example-wrap > pre.example-line-numbers {
|
||||
border-color: #4a4949;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ input:focus + .slider {
|
|||
background-color: #fff;
|
||||
}
|
||||
|
||||
.line-numbers span { color: #c67e2d; }
|
||||
.line-numbers .line-highlighted {
|
||||
.src-line-numbers span { color: #c67e2d; }
|
||||
.src-line-numbers .line-highlighted {
|
||||
background-color: #FDFFD3 !important;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ body.source .example-wrap pre.rust a {
|
|||
.stab { background: #FFF5D6; border-color: #FFC600; }
|
||||
.stab.portability > code { background: none; }
|
||||
|
||||
.line-numbers :target { background-color: transparent; }
|
||||
.src-line-numbers :target { background-color: transparent; }
|
||||
|
||||
/* Code highlighting */
|
||||
pre.rust .kw { color: #8959A8; }
|
||||
|
@ -141,7 +141,7 @@ pre.rust .question-mark {
|
|||
color: #ff9011;
|
||||
}
|
||||
|
||||
.example-wrap > pre.line-number {
|
||||
.example-wrap > pre.example-line-numbers {
|
||||
border-color: #c7c7c7;
|
||||
}
|
||||
|
||||
|
|
|
@ -699,7 +699,7 @@ function loadCss(cssFileName) {
|
|||
window.rustdoc_add_line_numbers_to_examples = () => {
|
||||
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
||||
const parent = x.parentNode;
|
||||
const line_numbers = parent.querySelectorAll(".line-number");
|
||||
const line_numbers = parent.querySelectorAll(".example-line-numbers");
|
||||
if (line_numbers.length > 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -709,7 +709,7 @@ function loadCss(cssFileName) {
|
|||
elems.push(i + 1);
|
||||
}
|
||||
const node = document.createElement("pre");
|
||||
addClass(node, "line-number");
|
||||
addClass(node, "example-line-numbers");
|
||||
node.innerHTML = elems.join("\n");
|
||||
parent.insertBefore(node, x);
|
||||
});
|
||||
|
@ -718,7 +718,7 @@ function loadCss(cssFileName) {
|
|||
window.rustdoc_remove_line_numbers_from_examples = () => {
|
||||
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
||||
const parent = x.parentNode;
|
||||
const line_numbers = parent.querySelectorAll(".line-number");
|
||||
const line_numbers = parent.querySelectorAll(".example-line-numbers");
|
||||
for (const node of line_numbers) {
|
||||
parent.removeChild(node);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
// Scroll code block to the given code location
|
||||
function scrollToLoc(elt, loc) {
|
||||
const lines = elt.querySelector(".line-numbers");
|
||||
const lines = elt.querySelector(".src-line-numbers");
|
||||
let scrollOffset;
|
||||
|
||||
// If the block is greater than the size of the viewer,
|
||||
|
|
|
@ -183,7 +183,7 @@ function highlightSourceLines(match) {
|
|||
if (x) {
|
||||
x.scrollIntoView();
|
||||
}
|
||||
onEachLazy(document.getElementsByClassName("line-numbers"), e => {
|
||||
onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
|
||||
onEachLazy(e.getElementsByTagName("span"), i_e => {
|
||||
removeClass(i_e, "line-highlighted");
|
||||
});
|
||||
|
@ -245,7 +245,7 @@ window.addEventListener("hashchange", () => {
|
|||
}
|
||||
});
|
||||
|
||||
onEachLazy(document.getElementsByClassName("line-numbers"), el => {
|
||||
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
|
||||
el.addEventListener("click", handleSourceHighlight);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Scraped example should only include line numbers for items b and c in ex.rs
|
||||
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14'
|
||||
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15'
|
||||
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21'
|
||||
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22'
|
||||
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '14'
|
||||
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '15'
|
||||
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '21'
|
||||
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '22'
|
||||
|
||||
pub fn f() {}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
goto: file://|DOC_PATH|/test_docs/index.html
|
||||
click: ".srclink"
|
||||
assert-count: (".line-numbers", 1)
|
||||
assert-count: (".src-line-numbers", 1)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
goto: file://|DOC_PATH|/test_docs/fn.foo.html
|
||||
|
||||
// We check that without this setting, there is no line number displayed.
|
||||
assert-false: "pre.line-number"
|
||||
assert-false: "pre.example-line-numbers"
|
||||
|
||||
// We now set the setting to show the line numbers on code examples.
|
||||
local-storage: {"rustdoc-line-numbers": "true" }
|
||||
|
@ -10,16 +10,16 @@ local-storage: {"rustdoc-line-numbers": "true" }
|
|||
reload:
|
||||
|
||||
// We wait for them to be added into the DOM by the JS...
|
||||
wait-for: "pre.line-number"
|
||||
wait-for: "pre.example-line-numbers"
|
||||
// If the test didn't fail, it means that it was found!
|
||||
// Let's now check some CSS properties...
|
||||
assert-css: ("pre.line-number", {
|
||||
assert-css: ("pre.example-line-numbers", {
|
||||
"margin": "0px",
|
||||
"padding": "13px 8px",
|
||||
"text-align": "right",
|
||||
})
|
||||
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
|
||||
assert-text: ("pre.line-number", "1\n2")
|
||||
assert-text: ("pre.example-line-numbers", "1\n2")
|
||||
|
||||
// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
|
||||
// and make sure it goes away.
|
||||
|
@ -32,8 +32,8 @@ assert-css: ("#settings", {"display": "block"})
|
|||
// Then, click the toggle button.
|
||||
click: "input#line-numbers + .slider"
|
||||
wait-for: 100 // wait-for-false does not exist
|
||||
assert-false: "pre.line-number"
|
||||
assert-false: "pre.example-line-numbers"
|
||||
|
||||
// Finally, turn it on again.
|
||||
click: "input#line-numbers + .slider"
|
||||
wait-for: "pre.line-number"
|
||||
wait-for: "pre.example-line-numbers"
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
// Checks that the interactions with the source code pages are working as expected.
|
||||
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
|
||||
// Check that we can click on the line number.
|
||||
click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
|
||||
click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
|
||||
// Ensure that the page URL was updated.
|
||||
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
|
||||
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
|
||||
// We now check that the good spans are highlighted
|
||||
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6
|
||||
assert-attribute-false: (".line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
|
||||
assert-attribute: (".line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
|
||||
assert-attribute: (".line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
|
||||
assert-attribute: (".line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
|
||||
assert-attribute-false: (".line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
|
||||
assert-attribute-false: (".src-line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
|
||||
assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
|
||||
assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
|
||||
assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
|
||||
assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
|
||||
// This is to ensure that the content is correctly align with the line numbers.
|
||||
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
|
||||
|
||||
// Assert that the line numbers text is aligned to the right.
|
||||
assert-css: (".line-numbers", {"text-align": "right"})
|
||||
assert-css: (".src-line-numbers", {"text-align": "right"})
|
||||
|
||||
// Now let's check that clicking on something else than the line number doesn't
|
||||
// do anything (and certainly not add a `#NaN` to the URL!).
|
||||
|
@ -24,7 +24,7 @@ show-text: true
|
|||
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
|
||||
// We use this assert-position to know where we will click.
|
||||
assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
|
||||
// We click on the left of the "1" span but still in the "line-number" `<pre>`.
|
||||
// We click on the left of the "1" span but still in the "src-line-number" `<pre>`.
|
||||
click: (103, 103)
|
||||
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue