From f1a44937cdbdbc4d4fb4acc0088be38b18260ffe Mon Sep 17 00:00:00 2001 From: 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> Date: Thu, 25 Jan 2024 21:25:17 +0900 Subject: ファイル名変更 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rehype/admonition-title-to-heading.js | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 src/rehype/admonition-title-to-heading.js (limited to 'src/rehype/admonition-title-to-heading.js') diff --git a/src/rehype/admonition-title-to-heading.js b/src/rehype/admonition-title-to-heading.js deleted file mode 100644 index d84b27b2..00000000 --- a/src/rehype/admonition-title-to-heading.js +++ /dev/null @@ -1,31 +0,0 @@ -import {visit} from 'unist-util-visit'; - -const plugin = (options) => { - const transformer = async (ast) => { - let hId = null; - let hContent = null; - visit(ast, 'element', (node, index, parent) => { - if (/^h[2-6]$/.test(node.tagName) && node.properties && node.properties.id) { - // h2~h6のタグを見つけたら - hId = node.properties.id; - hContent = node.children && node.children[0] ? node.children[0].value : ''; - // h3~h6タグの隣にあるdivタグを探す - const nextNode = parent.children[index + 1]; - if (nextNode && nextNode.tagName === 'admonition') { - // 該当のdiv要素を見つけたらHタグの内容とline-5の#以降の文字列が一致した場合 - const contentAfterHash = nextNode.properties.title ? nextNode.properties.title.replace(/^#+/, '').trim() : ''; - - if (contentAfterHash === hContent.trim()) { - // Hタグのidを取得しそれをdivのidに設定 - nextNode.properties.id = hId; - // Hタグを削除 - parent.children.splice(index, 1); - } - } - } - }); - }; - return transformer; -}; - -export default plugin; \ No newline at end of file -- cgit v1.2.3-54-g00ecf