build(aio): left align code regions
This commit is contained in:
		
							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}).`; | ||||
|  | ||||
| @ -43,6 +43,17 @@ describe('regionParser service', () => { | ||||
|     expect(output.contents).toEqual(t('abc', 'def', 'ghi')); | ||||
|   }); | ||||
| 
 | ||||
|   it('should left align the text of the region', () => { | ||||
|     const output = regionParser( | ||||
|       t( | ||||
|         '/* #docregion X */', '  all', '    indented', '    by', '  two', '  spaces', '/* #enddocregion X */', | ||||
|         '/* #docregion Y */', '    first', '  line', '  indented', '    more', '  than', '  later', '  lines', '/* #enddocregion Y */', | ||||
|         '/* #docregion Z */', '  ignore', '  ', '  empty', '', '  lines', '/* #enddocregion Z */' | ||||
|       ), 'test-type'); | ||||
|     expect(output.regions['X']).toEqual(t('all', '  indented', '  by', 'two', 'spaces')); | ||||
|     expect(output.regions['Y']).toEqual(t('  first', 'line', 'indented', '  more', 'than', 'later', 'lines')); | ||||
|     expect(output.regions['Z']).toEqual(t('ignore', '', 'empty', '', 'lines')); | ||||
|   }); | ||||
| 
 | ||||
|   it('should remove doc plaster annotations from the contents', () => { | ||||
|     const output = | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user