3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

要素のテキストノードをテキストの順番通りリストにする

3
Last updated at Posted at 2019-06-15

結論

function textNodes(node) {
	const _textnodes = (childNodes) => {
		if (childNodes.length <= 0) return []
		return Array.from(childNodes)
			.map(e => (e instanceof Text ? e : _textnodes(e.childNodes)))
			.flat()
	}
	return { node: node, textNodes: _textnodes(node.childNodes) }
}

微妙にどこをどうするのか悩んだ。

結果

スクリーンショット 2019-06-15 18.05.11.png 割と上手く行った
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?