prism-remote 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/example.html CHANGED
@@ -9,8 +9,8 @@
9
9
  <body>
10
10
  <h2>Github source with limited line range</h2>
11
11
  <prism-remote src="https://github.com/Fingel/prism-remote/blob/main/prism-remote.js"
12
- start="1"
13
- end="10"
12
+ start="6"
13
+ end="13"
14
14
  lang="javascript"
15
15
  ></prism-remote>
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prism-remote",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "description": "A custom element for displaying remote code blocks with syntax highlighting provided by Prism",
6
6
  "main": "prism-remote.js",
package/prism-remote.js CHANGED
@@ -40,12 +40,18 @@ export class PrismRemote extends HTMLElement {
40
40
 
41
41
  let code = await this.fetchSrc(rawUrl);
42
42
  let codeLines = code.split("\n");
43
- const start = this.hasAttribute("start")
44
- ? this.getAttribute("start")
45
- : 1;
46
- const end = this.hasAttribute("end")
47
- ? this.getAttribute("end")
48
- : codeLines.length;
43
+ let start = 1;
44
+ if (this.hasAttribute("start")) {
45
+ start = this.getAttribute("start");
46
+ srcUrl = `${srcUrl}#L${start}`;
47
+ }
48
+ let end = codeLines.length + 1;
49
+ if (this.hasAttribute("end")) {
50
+ end = this.getAttribute("end");
51
+ if (this.hasAttribute("start")) {
52
+ srcUrl = `${srcUrl}-L${end}`;
53
+ }
54
+ }
49
55
  codeLines = codeLines.splice(start - 1, end - start + 1);
50
56
  code = codeLines.join("\n");
51
57