build(aio): left align code regions
This commit is contained in:

committed by
Pete Bacon Darwin

parent
5e3ef775d5
commit
52ea193638
@ -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}).`;
|
||||
|
Reference in New Issue
Block a user