tiptap-parser
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
## 0.2.4 (2024-10-09) | ||
## 0.2.5 (2024-10-12) | ||
@@ -1,2 +0,2 @@ | ||
import { ReactNode } from "react"; | ||
import { ReactNode } from 'react'; | ||
/** | ||
@@ -3,0 +3,0 @@ * |
@@ -13,3 +13,3 @@ "use strict"; | ||
const CodeBlockWithCopy = ({ children }) => { | ||
const [copied, setCopied] = (0, react_1.useState)(false); | ||
const [isCopied, setIsCopied] = (0, react_1.useState)(false); | ||
const copyToClipboard = () => { | ||
@@ -20,8 +20,8 @@ const codeContent = (0, utils_1.childrenToString)(children); | ||
navigator.clipboard.writeText(codeContent).then(() => { | ||
setCopied(true); | ||
setTimeout(() => setCopied(false), 2000); // "Copied!" message for 2 seconds | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 2000); // "Copied!" message for 2 seconds | ||
}); | ||
}; | ||
return ((0, jsx_runtime_1.jsxs)("div", { className: "pre-container", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", onClick: copyToClipboard, children: copied ? (0, jsx_runtime_1.jsx)(Check_1.default, {}) : (0, jsx_runtime_1.jsx)(Copy_1.default, {}) }), (0, jsx_runtime_1.jsx)("pre", { children: children })] })); | ||
return ((0, jsx_runtime_1.jsxs)("div", { className: "pre-container", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", onClick: copyToClipboard, children: isCopied ? (0, jsx_runtime_1.jsx)(Check_1.default, {}) : (0, jsx_runtime_1.jsx)(Copy_1.default, {}) }), (0, jsx_runtime_1.jsx)("pre", { children: children })] })); | ||
}; | ||
exports.default = CodeBlockWithCopy; |
@@ -5,4 +5,4 @@ "use strict"; | ||
const Check = () => { | ||
return ((0, jsx_runtime_1.jsx)("svg", { stroke: "currentColor", fill: "none", strokeWidth: "2", viewBox: "0 0 24 24", strokeLinecap: "round", strokeLinejoin: "round", height: "1em", width: "1em", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("polyline", { points: "20 6 9 17 4 12" }) })); | ||
return ((0, jsx_runtime_1.jsx)("svg", { fill: "none", height: "1em", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", width: "1em", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("polyline", { points: "20 6 9 17 4 12" }) })); | ||
}; | ||
exports.default = Check; |
@@ -5,4 +5,4 @@ "use strict"; | ||
const Copy = () => { | ||
return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2" }), (0, jsx_runtime_1.jsx)("path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" })] })); | ||
return ((0, jsx_runtime_1.jsxs)("svg", { fill: "none", height: "24", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", width: "24", xmlns: "http://www.w3.org/2000/svg", children: [(0, jsx_runtime_1.jsx)("rect", { height: "14", rx: "2", ry: "2", width: "14", x: "8", y: "8" }), (0, jsx_runtime_1.jsx)("path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" })] })); | ||
}; | ||
exports.default = Copy; |
@@ -1,2 +0,2 @@ | ||
import { ReactNode } from "react"; | ||
import { ReactNode } from 'react'; | ||
/** | ||
@@ -3,0 +3,0 @@ * |
'use client'; | ||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { useState } from "react"; | ||
import Check from "./icons/Check.js"; | ||
import Copy from "./icons/Copy.js"; | ||
import { childrenToString } from "../utils/utils.js"; | ||
import { useState } from 'react'; | ||
import Check from './icons/Check.js'; | ||
import Copy from './icons/Copy.js'; | ||
import { childrenToString } from '../utils/utils.js'; | ||
const CodeBlockWithCopy = ({ children }) => { | ||
const [copied, setCopied] = useState(false); | ||
const [isCopied, setIsCopied] = useState(false); | ||
const copyToClipboard = () => { | ||
@@ -14,8 +14,8 @@ const codeContent = childrenToString(children); | ||
navigator.clipboard.writeText(codeContent).then(() => { | ||
setCopied(true); | ||
setTimeout(() => setCopied(false), 2000); // "Copied!" message for 2 seconds | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 2000); // "Copied!" message for 2 seconds | ||
}); | ||
}; | ||
return (_jsxs("div", { className: "pre-container", children: [_jsx("button", { type: "button", onClick: copyToClipboard, children: copied ? _jsx(Check, {}) : _jsx(Copy, {}) }), _jsx("pre", { children: children })] })); | ||
return (_jsxs("div", { className: "pre-container", children: [_jsx("button", { type: "button", onClick: copyToClipboard, children: isCopied ? _jsx(Check, {}) : _jsx(Copy, {}) }), _jsx("pre", { children: children })] })); | ||
}; | ||
export default CodeBlockWithCopy; |
import { jsx as _jsx } from "react/jsx-runtime"; | ||
const Check = () => { | ||
return (_jsx("svg", { stroke: "currentColor", fill: "none", strokeWidth: "2", viewBox: "0 0 24 24", strokeLinecap: "round", strokeLinejoin: "round", height: "1em", width: "1em", xmlns: "http://www.w3.org/2000/svg", children: _jsx("polyline", { points: "20 6 9 17 4 12" }) })); | ||
return (_jsx("svg", { fill: "none", height: "1em", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", width: "1em", xmlns: "http://www.w3.org/2000/svg", children: _jsx("polyline", { points: "20 6 9 17 4 12" }) })); | ||
}; | ||
export default Check; |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
const Copy = () => { | ||
return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2" }), _jsx("path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" })] })); | ||
return (_jsxs("svg", { fill: "none", height: "24", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", width: "24", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("rect", { height: "14", rx: "2", ry: "2", width: "14", x: "8", y: "8" }), _jsx("path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" })] })); | ||
}; | ||
export default Copy; |
@@ -12,3 +12,3 @@ import { jsx as _jsx } from "react/jsx-runtime"; | ||
*/ | ||
import parse, { attributesToProps, domToReact } from 'html-react-parser'; | ||
import parse, { attributesToProps, domToReact, } from 'html-react-parser'; | ||
import { common, createLowlight } from 'lowlight'; | ||
@@ -45,4 +45,6 @@ import { toHtml } from 'hast-util-to-html'; | ||
const props = attributesToProps(attribs); | ||
// do not replace the `<pre>` tag | ||
// if (name === 'pre') return | ||
/* | ||
* do not replace the `<pre>` tag | ||
* if (name === 'pre') return | ||
*/ | ||
if (name === 'pre') { | ||
@@ -76,5 +78,5 @@ return ( | ||
/* | ||
* If the `<code>` tag is not found in the html string content | ||
* it means that there are no code snippets to be highlighted. | ||
*/ | ||
* If the `<code>` tag is not found in the html string content | ||
* it means that there are no code snippets to be highlighted. | ||
*/ | ||
return parse(text, { ...defaultOptions, ...options }); | ||
@@ -81,0 +83,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { ReactNode } from 'react'; | ||
/** | ||
@@ -6,2 +7,2 @@ * transform the children array to a string | ||
*/ | ||
export declare const childrenToString: (children: React.ReactNode) => string; | ||
export declare const childrenToString: (children: ReactNode) => string; |
@@ -1,2 +0,2 @@ | ||
import { Children, isValidElement } from "react"; | ||
import { Children, isValidElement } from 'react'; | ||
/** | ||
@@ -3,0 +3,0 @@ * transform the children array to a string |
@@ -83,4 +83,6 @@ "use strict"; | ||
const props = (0, html_react_parser_1.attributesToProps)(attribs); | ||
// do not replace the `<pre>` tag | ||
// if (name === 'pre') return | ||
/* | ||
* do not replace the `<pre>` tag | ||
* if (name === 'pre') return | ||
*/ | ||
if (name === 'pre') { | ||
@@ -114,5 +116,5 @@ return ( | ||
/* | ||
* If the `<code>` tag is not found in the html string content | ||
* it means that there are no code snippets to be highlighted. | ||
*/ | ||
* If the `<code>` tag is not found in the html string content | ||
* it means that there are no code snippets to be highlighted. | ||
*/ | ||
return (0, html_react_parser_1.default)(text, Object.assign(Object.assign({}, defaultOptions), options)); | ||
@@ -119,0 +121,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { ReactNode } from 'react'; | ||
/** | ||
@@ -6,2 +7,2 @@ * transform the children array to a string | ||
*/ | ||
export declare const childrenToString: (children: React.ReactNode) => string; | ||
export declare const childrenToString: (children: ReactNode) => string; |
{ | ||
"name": "tiptap-parser", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "HTML parser to React component built on the top of html-react-parser with code syntax highlighting", | ||
@@ -50,3 +50,4 @@ "keywords": [ | ||
"build": "yarn clean && tsc --project tsconfig.build.json && tsc --project tsconfig.build-esm.json && yarn copy-files && yarn copy-files-esm && yarn fixImportExtension", | ||
"prepare": "npm run build", | ||
"prepare": "husky", | ||
"lint-staged": "lint-staged", | ||
"preview": "vite preview", | ||
@@ -82,2 +83,4 @@ "type:check": "tsc --noEmit", | ||
"@eslint/js": "^9.12.0", | ||
"@stylistic/eslint-plugin": "^2.9.0", | ||
"@types/eslint-plugin-jsx-a11y": "^6", | ||
"@types/eslint__js": "^8.42.3", | ||
@@ -91,7 +94,6 @@ "@types/react": "^18.2.43", | ||
"eslint": "^9.12.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-airbnb-typescript": "^17.1.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-import-resolver-babel-module": "^5.3.2", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-jsx-a11y": "^6.10.0", | ||
"eslint-plugin-prefer-arrow-functions": "^3.2.4", | ||
@@ -102,2 +104,4 @@ "eslint-plugin-prettier": "^5.2.1", | ||
"globals": "^15.11.0", | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.10", | ||
"markdown-link-check": "^3.12.1", | ||
@@ -104,0 +108,0 @@ "prettier": "^3.3.3", |
32127
0.92%571
1.06%36
9.09%