From 6d62924be57b19b8ed7551adf35c00b65e1b7c37 Mon Sep 17 00:00:00 2001 From: brklntmhwk_w <86272619+brklntmhwk@users.noreply.github.com.> Date: Thu, 31 Oct 2024 10:46:25 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=20change=20the=20import?= =?UTF-8?q?=20path=20to=20an=20utils=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 178 +++++++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/src/index.ts b/src/index.ts index f8ac80c..479711a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,98 +5,98 @@ import type { LeafDirective } from "mdast-util-directive"; import type { Plugin } from "unified"; import { visit } from "unist-util-visit"; import { - isContainerDirective, - isImage, - isLink, - isParagraph, - isText, + isContainerDirective, + isImage, + isLink, + isParagraph, + isText, } from "./utils.js"; const remarkCard: Plugin<[], Root> = () => { - return (tree) => { - visit(tree, isContainerDirective, (node) => { - if (node.name !== "card-grid") return; - if (node.children.length === 0) return; - - node.data = { - ...node.data, - hProperties: { - class: node.attributes?.class, - }, - }; - }); - - visit(tree, isContainerDirective, (node) => { - if (node.name !== "card") return; - if (node.children.length === 0) return; - - const [firstNode, secondNode, ..._restNodes] = node.children; - if (!isParagraph(firstNode)) return; - if (firstNode.children.length === 0) return; - - let cardImageOrLink: PhrasingContent; - let cardContent: PhrasingContent[]; - let cardLabel = ""; - - const imageWrapper: LeafDirective = { - type: "leafDirective", - name: "image-wrapper", - data: { - hName: "div", - }, - children: [], - }; - - const content: LeafDirective = { - type: "leafDirective", - name: "card-content", - data: { - hName: "div", - }, - children: [], - }; - - if (firstNode.data?.directiveLabel === true) { - if (!isText(firstNode.children[0])) return; - - cardLabel = firstNode.children[0].value; - - if (!isParagraph(secondNode)) return; - const [imageOrLink, ...restContent] = secondNode.children; - cardImageOrLink = imageOrLink; - cardContent = restContent; - } else { - const [imageOrLink, ...restContent] = firstNode.children; - cardImageOrLink = imageOrLink; - cardContent = restContent; - } - - if (isImage(cardImageOrLink)) { - cardImageOrLink.alt = cardImageOrLink.alt || cardLabel; - } else if (isLink(cardImageOrLink)) { - const cardImage = cardImageOrLink.children[0]; - if (!isImage(cardImage)) return; - - cardImage.alt = cardImage.alt || cardLabel; - } else { - return; - } - - imageWrapper.children.push(cardImageOrLink); - - for (const contentElem of cardContent) { - content.children.push(contentElem); - } - - node.data = { - ...node.data, - hProperties: { - class: node.attributes?.class, - }, - }; - node.children.splice(0, Number.POSITIVE_INFINITY, imageWrapper, content); - }); - }; + return (tree) => { + visit(tree, isContainerDirective, (node) => { + if (node.name !== "card-grid") return; + if (node.children.length === 0) return; + + node.data = { + ...node.data, + hProperties: { + class: node.attributes?.class, + }, + }; + }); + + visit(tree, isContainerDirective, (node) => { + if (node.name !== "card") return; + if (node.children.length === 0) return; + + const [firstNode, secondNode, ..._restNodes] = node.children; + if (!isParagraph(firstNode)) return; + if (firstNode.children.length === 0) return; + + let cardImageOrLink: PhrasingContent; + let cardContent: PhrasingContent[]; + let cardLabel = ""; + + const imageWrapper: LeafDirective = { + type: "leafDirective", + name: "image-wrapper", + data: { + hName: "div", + }, + children: [], + }; + + const content: LeafDirective = { + type: "leafDirective", + name: "card-content", + data: { + hName: "div", + }, + children: [], + }; + + if (firstNode.data?.directiveLabel === true) { + if (!isText(firstNode.children[0])) return; + + cardLabel = firstNode.children[0].value; + + if (!isParagraph(secondNode)) return; + const [imageOrLink, ...restContent] = secondNode.children; + cardImageOrLink = imageOrLink; + cardContent = restContent; + } else { + const [imageOrLink, ...restContent] = firstNode.children; + cardImageOrLink = imageOrLink; + cardContent = restContent; + } + + if (isImage(cardImageOrLink)) { + cardImageOrLink.alt = cardImageOrLink.alt || cardLabel; + } else if (isLink(cardImageOrLink)) { + const cardImage = cardImageOrLink.children[0]; + if (!isImage(cardImage)) return; + + cardImage.alt = cardImage.alt || cardLabel; + } else { + return; + } + + imageWrapper.children.push(cardImageOrLink); + + for (const contentElem of cardContent) { + content.children.push(contentElem); + } + + node.data = { + ...node.data, + hProperties: { + class: node.attributes?.class, + }, + }; + node.children.splice(0, Number.POSITIVE_INFINITY, imageWrapper, content); + }); + }; }; export default remarkCard;