Skip to content

Commit fab90f0

Browse files
authored
Merge pull request #12 from bit-docs/sorry-cherif
Sorry cherif
2 parents bc3d8e0 + edfa985 commit fab90f0

File tree

5 files changed

+47
-36
lines changed

5 files changed

+47
-36
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,32 @@ var getConfig = function(lineString, lineCount) {
8888
};
8989
};
9090

91-
function findPreviousSibling(el, tag) {
91+
function findPreviousSibling(start, tag) {
9292
tag = tag.toUpperCase();
9393

94-
while (el = el.previousSibling) {
95-
if (el.tagName && el.tagName.toUpperCase() === tag) {
96-
return el;
97-
}
98-
}
94+
while(start) {
95+
if(start.nodeName === tag) {
96+
return start;
97+
}
98+
if(start.querySelector) {
99+
var pre = start.querySelector(tag);
100+
if(pre) {
101+
return pre;
102+
}
103+
}
104+
105+
// needs to be previousSibling for zombie
106+
start = start.previousSibling;
107+
}
99108
}
100109

101110
module.exports = function() {
102-
var highlights = document.querySelectorAll('span[line-highlight]')
111+
var highlights = document.querySelectorAll('div[line-highlight]');
103112

104113
for (var i = 0; i < highlights.length; i++) {
105114
var highlight = highlights[i];
106115

107-
var preBlock = findPreviousSibling(highlight.parentElement, 'pre');
116+
var preBlock = findPreviousSibling(highlight, 'pre');
108117
var codeBlock = preBlock.childNodes.item(0);
109118

110119
var total = codeBlock.innerHTML.split('\n').length - 1;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"homepage": "https://github.com/bit-docs/bit-docs-html-highlight-line#readme",
2929
"dependencies": {
30-
"bit-docs-prettify": "^0.2.2-8",
30+
"bit-docs-prettify": "<2.0.0",
3131
"prismjs": "^1.11.0"
3232
},
3333
"devDependencies": {

tags.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/**
22
* @parent bit-docs-html-highlight-line/tags
33
* @module {bit-docs-process-tags/types/tag} bit-docs-html-highlight-line/tags/highlight @highlight
4-
*
4+
*
55
* Highlight the specified code lines.
6-
*
6+
*
77
* @signature `@highlight LINES[,ONLY]`
8-
*
8+
*
99
* @param {String} LINES The lines to highlight like `2-4`.
10-
*
10+
*
1111
* @param {String} [,ONLY] Collapse non-highlighted lines greater than three
1212
* lines away (useful for long code snippets).
13-
*
13+
*
1414
* @codestart javascript
1515
* /**
1616
* * ```js
@@ -24,27 +24,28 @@
2424
* * "season": "Summer",
2525
* * "awesome": "yes"
2626
* * }
27-
* * ```
27+
* * ```
2828
* *
2929
* * @highlight 2-4,only
3030
* *|
3131
* @codeend
32-
*
32+
*
3333
* Injects a `<span line-highlight="2-4,only"></span>` element to the page that
3434
* will be picked up and used by the static front-end script
3535
* [bit-docs-html-highlight-line/highlight-line.js].
3636
*/
3737
exports.highlight = {
3838
add: function(line, curData) {
39+
var space = line.substr(0, line.indexOf("@highlight"));
3940
var lines = line.replace("@highlight","").trim();
40-
var html = "<span line-highlight='"+lines+"'></span>";
41+
var html = space+"<div line-highlight='"+lines+"'></div>";
4142
var validCurData = (curData && curData.length !== 2);
4243
var useCurData = validCurData && (typeof curData.description === "string") && !curData.body;
4344

4445
if(useCurData) {
45-
curData.description += html;
46+
curData.description += "\n"+html+"\n";
4647
} else {
47-
this.body += html;
48+
this.body += html+"\n";
4849
}
4950
}
5051
};

test-demo.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Put the markup in a template. Change the `HTML` tab to the following:
101101

102102
</html>
103103
```
104-
<span line-highlight='11,68,only'/>
104+
<div line-highlight='11,68,only'/>
105105

106106
> NOTE: autofocus
107107
@@ -112,7 +112,7 @@ var template = can.stache.from("todomvc-template");
112112
var frag = template({});
113113
document.body.appendChild(frag);
114114
```
115-
<span line-highlight='1-3,only'/>
115+
<div line-highlight='1-3,only'/>
116116

117117
## Create the todos type and get items left working
118118

@@ -149,7 +149,7 @@ var template = can.stache.from("todomvc-template");
149149
var frag = template({todos: todos});
150150
document.body.appendChild(frag);
151151
```
152-
<span line-highlight='1-25,28,only'/>
152+
<div line-highlight='1-25,28,only'/>
153153

154154
Update `HTML` to:
155155

@@ -215,7 +215,7 @@ Update `HTML` to:
215215

216216
</html>
217217
```
218-
<span line-highlight='22-31,36,50,only'/>
218+
<div line-highlight='22-31,36,50,only'/>
219219

220220
Note:
221221

@@ -276,7 +276,7 @@ var template = can.stache.from("todomvc-template");
276276
var frag = template({todosPromise: Todo.getList({})});
277277
document.body.appendChild(frag);
278278
```
279-
<span line-highlight='1-15,37-43,46,only'/>
279+
<div line-highlight='1-15,37-43,46,only'/>
280280

281281
Update `HTML` to:
282282

@@ -342,7 +342,7 @@ Update `HTML` to:
342342

343343
</html>
344344
```
345-
<span line-highlight='22,36,50,only'/>
345+
<div line-highlight='22,36,50,only'/>
346346

347347
Note:
348348

@@ -415,7 +415,7 @@ Update `HTML` to:
415415
416416
</html>
417417
```
418-
<span line-highlight='23-24,28,only'/>
418+
<div line-highlight='23-24,28,only'/>
419419

420420
TODO:
421421

@@ -490,7 +490,7 @@ var template = can.stache.from("todomvc-template");
490490
var frag = template({todosPromise: Todo.getList({})});
491491
document.body.appendChild(frag);
492492
```
493-
<span line-highlight='46-59,only'/>
493+
<div line-highlight='46-59,only'/>
494494

495495
Update `HTML` to:
496496

@@ -563,7 +563,7 @@ Update `HTML` to:
563563

564564
</html>
565565
```
566-
<span line-highlight='11-16,18,22,only'/>
566+
<div line-highlight='11-16,18,22,only'/>
567567

568568
## List todos
569569

@@ -643,7 +643,7 @@ var template = can.stache.from("todomvc-template");
643643
var frag = template({todosPromise: Todo.getList({})});
644644
document.body.appendChild(frag);
645645
```
646-
<span line-highlight='60-68,only'/>
646+
<div line-highlight='60-68,only'/>
647647

648648
Update `HTML` to:
649649

@@ -720,7 +720,7 @@ Update `HTML` to:
720720

721721
</html>
722722
```
723-
<span line-highlight='18-32,43,only'/>
723+
<div line-highlight='18-32,43,only'/>
724724

725725

726726
## Edit todos
@@ -818,7 +818,7 @@ var template = can.stache.from("todomvc-template");
818818
var frag = template({todosPromise: Todo.getList({})});
819819
document.body.appendChild(frag);
820820
```
821-
<span line-highlight='62-78,only'/>
821+
<div line-highlight='62-78,only'/>
822822

823823

824824

@@ -902,7 +902,7 @@ Update `HTML` to:
902902
903903
</html>
904904
```
905-
<span line-highlight='23,26,29-32,only'/>
905+
<div line-highlight='23,26,29-32,only'/>
906906

907907
## Routing
908908

@@ -1020,7 +1020,7 @@ can.route.ready();
10201020
var frag = template(vm);
10211021
document.body.appendChild(frag);
10221022
```
1023-
<span line-highlight='87-109,only'/>
1023+
<div line-highlight='87-109,only'/>
10241024

10251025
Update `HTML` to:
10261026

@@ -1104,7 +1104,7 @@ Update `HTML` to:
11041104
11051105
</html>
11061106
```
1107-
<span line-highlight='55-56,59-60,63-64,only'/>
1107+
<div line-highlight='55-56,59-60,63-64,only'/>
11081108
11091109
11101110
## Check all and clear completed
@@ -1259,7 +1259,7 @@ can.route.ready();
12591259
var frag = template(vm);
12601260
document.body.appendChild(frag);
12611261
```
1262-
<span line-highlight='40-57,128-135,only'/>
1262+
<div line-highlight='40-57,128-135,only'/>
12631263
12641264
Update `HTML` to:
12651265
@@ -1346,4 +1346,4 @@ Update `HTML` to:
13461346
13471347
</html>
13481348
```
1349-
<span line-highlight='45-47,69-70,only'/>
1349+
<div line-highlight='45-47,69-70,only'/>

0 commit comments

Comments
 (0)