Skip to content

Commit 8f05e71

Browse files
committed
include indentation and find elements more nicely
1 parent 160a7f4 commit 8f05e71

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,23 @@ var getConfig = function(lineString, lineCount) {
8585
};
8686
};
8787

88-
function findPreviousSibling(el, tag) {
88+
function findPreviousSibling(start, tag) {
8989
tag = tag.toUpperCase();
9090

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

98107
module.exports = function() {

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+"<span line-highlight='"+lines+"'></span>";
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
};

0 commit comments

Comments
 (0)