(element: Element)
| 16 | |
| 17 | /** Determines the indentation of child elements for the given Parse5 element. */ |
| 18 | export function getChildElementIndentation(element: Element) { |
| 19 | const childElement = element.childNodes.find(node => (node as Element).tagName) as Element | null; |
| 20 | |
| 21 | if ((childElement && !childElement.sourceCodeLocation) || !element.sourceCodeLocation) { |
| 22 | throw new SchematicsException( |
| 23 | 'Cannot determine child element indentation because the ' + |
| 24 | 'specified Parse5 element does not have any source code location metadata.', |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | const startColumns = childElement |
| 29 | ? // In case there are child elements inside of the element, we assume that their |
| 30 | // indentation is also applicable for other child elements. |
| 31 | childElement.sourceCodeLocation!.startCol |
| 32 | : // In case there is no child element, we just assume that child elements should be indented |
| 33 | // by two spaces. |
| 34 | element.sourceCodeLocation!.startCol + 2; |
| 35 | |
| 36 | // Since Parse5 does not set the `startCol` properties as zero-based, we need to subtract |
| 37 | // one column in order to have a proper zero-based offset for the indentation. |
| 38 | return startColumns - 1; |
| 39 | } |
no outgoing calls
no test coverage detected