Comparing version 0.0.6-alpha to 0.0.7-alpha
{ | ||
"name": "glob-docs", | ||
"version": "0.0.6-alpha", | ||
"version": "0.0.7-alpha", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,2 +19,3 @@ const utils = require('./utils'); | ||
showSourceFile: true, | ||
autoIndent: true, | ||
...utils.parseTagParams(value) | ||
@@ -21,0 +22,0 @@ }; |
@@ -41,2 +41,36 @@ function createLink(childTag, label, options) { | ||
if (docTag.options.params.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 + [ | ||
@@ -43,0 +77,0 @@ `\`\`\`${docTag.options.params.lang}`, |
29956
841