Comparing version 0.0.12-alpha to 0.0.13-alpha
{ | ||
"name": "glob-docs", | ||
"version": "0.0.12-alpha", | ||
"version": "0.0.13-alpha", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,2 +18,3 @@ /*! | ||
CODE: require('./doctags/code'), | ||
BLOCK: require('./doctags/block'), | ||
OPT: require('./doctags/option'), | ||
@@ -20,0 +21,0 @@ OPTION: require('./doctags/option'), |
@@ -29,3 +29,50 @@ function createLink(childTag, label, options) { | ||
OPT: OPTION, // options alias | ||
BLOCK: ({ options, docTag }) => { | ||
let fileLink = ''; | ||
if (options.code.showSourceFile && docTag.options.showSourceFile) { | ||
let sourceLabel = [ | ||
docTag.node.relativeFilepath, | ||
docTag.node.lineNum | ||
].join(':'); | ||
fileLink = `<sub>File: ${createLink(docTag, sourceLabel, options)}</sub>\n`; | ||
} | ||
if (docTag.options.autoIndent) { | ||
let sourceLines = docTag.metatags.codeSource.split('\n'); | ||
let count = 0; | ||
let stripIndentCount = null; | ||
for(const lineIndex in sourceLines) { | ||
const sourceLine = sourceLines[lineIndex]; | ||
// no point to iterate white lines | ||
if (sourceLine.trim() === "") { | ||
continue; | ||
}; | ||
for (const charIndex in sourceLine) { | ||
const character = sourceLine[charIndex]; | ||
if (character === " ") { | ||
count++; | ||
} else { | ||
break; | ||
} | ||
} | ||
if (stripIndentCount === null || count < stripIndentCount) { | ||
stripIndentCount = count; | ||
} | ||
} | ||
const newLines = []; | ||
for(const lineIndex in sourceLines) { | ||
const sourceLine = sourceLines[lineIndex]; | ||
newLines.push(sourceLine.slice(stripIndentCount, sourceLine.length)); | ||
} | ||
docTag.metatags.codeSource = newLines.join('\n'); | ||
} | ||
return fileLink + [ | ||
docTag.metatags.codeSource, | ||
].join('\n'); | ||
}, | ||
/*** | ||
@@ -97,3 +144,3 @@ * It renders syntax highligh code. | ||
let todoLine = `- ${splitted[0]}] - [${splitted[1]}](${sourceLink}#L${docTag.node.lineNum})`; | ||
let todoLine = `- ${splitted[0]}] - [${splitted[1]}](${sourceLink}#lines-${docTag.node.lineNum})`; | ||
todoLine = todoLine.replace('[]', '[ ]'); // normalize brackets | ||
@@ -100,0 +147,0 @@ return todoLine; |
45400
26
957