build(aio): left align code regions

This commit is contained in:
Peter Bacon Darwin
2017-03-27 08:57:23 +01:00
committed by Pete Bacon Darwin
parent 5e3ef775d5
commit 52ea193638
2 changed files with 23 additions and 1 deletions

View File

@ -103,7 +103,7 @@ function regionParserImpl(contents, fileType) {
}
return {
contents: lines.join('\n'),
regions: mapObject(regionMap, (regionName, region) => region.lines.join('\n'))
regions: mapObject(regionMap, (regionName, region) => leftAlign(region.lines).join('\n'))
};
} else {
return {contents, regions: {}};
@ -119,6 +119,17 @@ function removeLast(array, item) {
array.splice(index, 1);
}
function leftAlign(lines) {
let indent = Number.MAX_VALUE;
lines.forEach(line => {
const lineIndent = line.search(/\S/);
if (lineIndent !== -1) {
indent = Math.min(lineIndent, indent);
}
});
return lines.map(line => line.substr(indent));
}
function RegionParserError(message, index) {
const lineNum = index + 1;
this.message = `regionParser: ${message} (at line ${lineNum}).`;