extensions/emmet/src/util.ts/getHtmlFlatNode
export function getHtmlFlatNode(documentText: string, root: FlatNode | undefined, offset: number, includeNodeBoundary: boolean): HtmlFlatNode | undefined {
	let currentNode: HtmlFlatNode | undefined = <HtmlFlatNode | undefined>getFlatNode(root, offset, includeNodeBoundary);
	if (!currentNode) { return; }

	// If the currentNode is a script one, first set up its subtree and then find HTML node.
	if (currentNode.name === 'script' && currentNode.children.length === 0) {
		const scriptNodeBody = setupScriptNodeSubtree(documentText, currentNode);
		if (scriptNodeBody) {
			currentNode = getHtmlFlatNode(scriptNodeBody, currentNode, offset, includeNodeBoundary) ?? currentNode;
		}
	}
	else if (currentNode.type === 'cdata') {
		const cdataBody = setupCdataNodeSubtree(documentText, currentNode);
		currentNode = getHtmlFlatNode(cdataBody, currentNode, offset, includeNodeBoundary) ?? currentNode;
	}
	return currentNode;
}