Skip to content

Commit 1596267

Browse files
committed
Allow starting line numbering at an offset
Also remove the offset when looking for a line within a section for consistency Also allow the regex to be empty to get the first line within a section to determine which line number to start with more consistently
1 parent eac739d commit 1596267

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

js/linenos.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// This is done as JS so as to occur *after* `highlight.js` inserts its `<span>`s
22

3+
let linenoRegex = /^start=([0-9]+)$/;
4+
35
for (let element of document.querySelectorAll('pre > code.linenos')) {
46
let text = element.innerHTML;
57
element.textContent = ''; // Remove all the code
@@ -18,4 +20,12 @@ for (let element of document.querySelectorAll('pre > code.linenos')) {
1820
node.innerHTML = line + '\n';
1921
element.appendChild(node);
2022
});
23+
24+
25+
for (let className of element.classList) {
26+
let match = linenoRegex.exec(className);
27+
if (match) {
28+
element.style.setProperty('counter-reset', 'lineno ' + (parseInt(match[1]) - 1));
29+
}
30+
}
2131
}

preproc/src/links.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl<'a> Link<'a> {
135135
// Section start
136136
sect_regex.1 = &ANCHOR_END;
137137
try_matching = true;
138-
line_no = 0;
139138
} else {
140139
// Section end
141140
break;
@@ -211,14 +210,14 @@ impl<'a> Iterator for LinkIter<'a> {
211210

212211
fn find_links(contents: &str) -> LinkIter<'_> {
213212
// lazily compute the following regex:
214-
// r#"\{\{#line_no_of\s*"([^"]+)"\s+([^}]+)\}\}"#)?;
213+
// r#"\{\{#line_no_of\s*"([^"]*)"\s+([^}]+)\}\}"#)?;
215214
lazy_static! {
216215
static ref RE: Regex = Regex::new(
217216
r#"(?x) # insignificant whitespace mode
218217
\{\{\s* # link opening parens and whitespace
219218
\#line_no_of # link type
220219
\s+ # separating whitespace
221-
"([^"]+)" # regex being searched for
220+
"([^"]*)" # regex being searched for
222221
\s+ # separating whitespace
223222
([^}]+) # path to search
224223
\}\} # link closing parens"#

src/part1/jumps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Don't worry, we will see later why it's required.
4343
Now to the *really* interesting part.
4444
Let's examine the loop responsible for copying tiles:
4545

46-
```rgbasm,linenos
46+
```rgbasm,linenos,start={{#line_no_of "" ../assets/hello-world.asm:memcpy}}
4747
{{#include ../assets/hello-world.asm:memcpy}}
4848
```
4949

src/part1/memory.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ It functions as `[hl]`, but `hl` is *incremented* just after memory is accessed.
119119

120120
## An example
121121

122-
So, if we look at the first two instructions of `.copyTiles`:
122+
So, if we look at the first two instructions of `CopyTiles`:
123123

124-
```rgbasm
124+
```rgbasm,linenos,start={{#line_no_of "" ../assets/hello-world.asm:memcpy_first_two}}
125125
{{#include ../assets/hello-world.asm:memcpy_first_two}}
126126
```
127127

0 commit comments

Comments
 (0)