This repository was archived by the owner on Aug 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathanalyzer.js
More file actions
42 lines (39 loc) · 1.31 KB
/
Copy pathanalyzer.js
File metadata and controls
42 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var annotation = require('css-annotation');
exports.setModules = function (syntaxHighlighter, markdownParser) {
this.syntaxHighlighter = syntaxHighlighter;
this.markdownParser = markdownParser;
}
exports.analyze = function (root) {
var list = [];
var linkId = 0;
root.walkComments(function (comment) {
var meta = annotation.read(comment.text);
if (!meta.documents && !meta.document && !meta.docs && !meta.doc && !meta.styleguide) {
return;
}
if (comment.parent.type !== 'root') {
return;
}
var rules = [];
var rule = comment.next();
while (rule && rule.type !== 'comment') {
if (rule.type === 'rule' || rule.type === 'atrule') {
rules.push(rule.toString());
}
rule = rule.next();
}
var joined = rules.join('\n\n');
var md = comment.text.replace(/(@document|@doc|@docs|@styleguide)\s*[\r]*\n/, '');
md = md.replace(/@title\s.*[\r]*\n/, '');
list.push({
rule: this.syntaxHighlighter.highlight(joined),
html: this.markdownParser(md),
link: {
id: 'psg-link-' + linkId,
title: meta.title || null
}
});
linkId++;
}.bind(this));
return list;
}