chore: format script code.

This commit is contained in:
jaywcjlove
2022-10-29 00:24:39 +08:00
parent bd082908d8
commit 4132a13a96
24 changed files with 471 additions and 298 deletions

View File

@ -1,15 +1,15 @@
/**
* 配置 tooltips 注释
*
*
* ```markdown
* - [超链接有 tooltips 提示](#1xx-information) _Tooltips 展示内容_ <!--rehype:tooltips-->
* ```
*
*
* 上面示例:将 “Tooltips 展示内容” 放到 前一个 `<a>` dom 节点作为子节点
*
*
* - 注释配置的,前一个节点 AA 的前一个节点 B
* - 如果 A 和 B 其中一个不存在 `tooltips` 将失效
* - 设置 B 的类名称为 tooltips
* - 设置 B 的类名称为 tooltips
*/
export function tooltips(node, index, parent) {
if (node.type === 'comment' && parent?.children.length > 2) {
@ -17,12 +17,12 @@ export function tooltips(node, index, parent) {
const result = [];
let recordPos = false; // 记录位置
let tooltipNode = null;
for(let i = childs.length; i > -1; i--) {
for (let i = childs.length; i > -1; i--) {
const node = childs[i];
// 记录 tooltip 的开始位置
if (node?.type === 'comment' && node?.value === 'rehype:tooltips') {
recordPos = true;
continue
continue;
}
// 记录 tooltip 的 node
if (recordPos && !tooltipNode) {
@ -33,24 +33,24 @@ export function tooltips(node, index, parent) {
tooltipNode = node;
tooltipNode.properties['class'] = 'tooltiptext';
delete tooltipNode.position;
continue
continue;
}
}
// 将 tooltip 节点,插入到下一个 element 节点的子节点中
if (tooltipNode) {
if (node.type === 'comment' || (node.type === 'text' && !node?.value?.replace(/\s\n/g, ''))) {
recordPos = false;
tooltipNode = null
tooltipNode = null;
}
if (tooltipNode && node?.type === 'element') {
recordPos = false;
node.properties['class'] = 'tooltip';
node.children.push(tooltipNode);
tooltipNode = null
tooltipNode = null;
}
}
if (!recordPos && node) {
result.push(node)
result.push(node);
}
}
if (parent) {
@ -59,6 +59,4 @@ export function tooltips(node, index, parent) {
}
}
export function getPreviewNode() {
}
export function getPreviewNode() {}