@discord/markdown-react 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.js +1 -1
- package/package.json +7 -8
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,Fragment as r}from"react/jsx-runtime";import{parse as n}from"@discord/markdown-wasm";import{createContext as t,useContext as o,useMemo as l}from"react";let d=t(null);export function useAst(){return o(d)}export const RULES=new Set(["bold","italic","underline","strikethrough","spoiler","emoji","timestamp","mention","link","code","code_block","heading","list","quote","small"]);export function Node({node:r,renderers:n,...t}){let o=n[r.type];if(!function(e,r){if(null==e)throw Error(`Attempted to render "${r}" but no renderer was provided`)}(o,r.type),Array.isArray(r.value))return e(o,{node:r,...t,children:e(NodeList,{nodes:r.value,renderers:n})});switch(r.type){case"mention":case"timestamp":case"emoji":case"code_block":return e(o,{node:r,...r.value,...t});case"link":{let l=r.value,d=null;if("normal"===l.type){let{value:{text:r,url:t}}=l;d=r?e(NodeList,{nodes:r,renderers:n}):t}return e(o,{node:r,...r.value,...t,children:d})}case"text":case"code":return e(o,{node:r,...t,children:r.value});case"heading":return e(o,{node:r,level:r.value.level,...t,children:e(NodeList,{nodes:r.value.content,renderers:n})});case"list":{let l=n.listItem??"li";return e(o,{node:r,...r.value,...t,children:r.value.items.map((t,o)=>e(l,{node:t,siblings:r.value.items,index:o,children:e(NodeList,{nodes:t.content,renderers:n})},o))})}case"empty":return e(o,{...t});case"small":return e(o,{node:r,...t,children:e(NodeList,{nodes:r.value.content,renderers:n})});default:throw TypeError(`Unknown node type "${r.type}"`)}}export function NodeList({nodes:n,renderers:t}){return e(r,{children:n.map((r,o)=>e(Node,{node:r,renderers:t,siblings:n,index:o},o))})}export default function i({content:r,renderers:t}){let o=l(()=>{let e=Object.keys(t).filter(e=>RULES.has(e));return e.length>0?e:null},[t]),i=l(()=>n(r,o),[r,o]);return e(d.Provider,{value:i,children:e(NodeList,{nodes:i,renderers:t})})}
|
|
1
|
+
import{jsx as e,Fragment as r}from"react/jsx-runtime";import{parse as n}from"@discord/markdown-wasm/sync";import{createContext as t,useContext as o,useMemo as l}from"react";let d=t(null);export function useAst(){return o(d)}export const RULES=new Set(["bold","italic","underline","strikethrough","spoiler","emoji","timestamp","mention","link","code","code_block","heading","list","quote","small"]);export function Node({node:r,renderers:n,...t}){let o=n[r.type];if(!function(e,r){if(null==e)throw Error(`Attempted to render "${r}" but no renderer was provided`)}(o,r.type),Array.isArray(r.value))return e(o,{node:r,...t,children:e(NodeList,{nodes:r.value,renderers:n})});switch(r.type){case"mention":case"timestamp":case"emoji":case"code_block":return e(o,{node:r,...r.value,...t});case"link":{let l=r.value,d=null;if("normal"===l.type){let{value:{text:r,url:t}}=l;d=r?e(NodeList,{nodes:r,renderers:n}):t}return e(o,{node:r,...r.value,...t,children:d})}case"text":case"code":return e(o,{node:r,...t,children:r.value});case"heading":return e(o,{node:r,level:r.value.level,...t,children:e(NodeList,{nodes:r.value.content,renderers:n})});case"list":{let l=n.listItem??"li";return e(o,{node:r,...r.value,...t,children:r.value.items.map((t,o)=>e(l,{node:t,siblings:r.value.items,index:o,children:e(NodeList,{nodes:t.content,renderers:n})},o))})}case"empty":return e(o,{...t});case"small":return e(o,{node:r,...t,children:e(NodeList,{nodes:r.value.content,renderers:n})});default:throw TypeError(`Unknown node type "${r.type}"`)}}export function NodeList({nodes:n,renderers:t}){return e(r,{children:n.map((r,o)=>e(Node,{node:r,renderers:t,siblings:n,index:o},o))})}export default function i({content:r,renderers:t}){let o=l(()=>{let e=Object.keys(t).filter(e=>RULES.has(e));return e.length>0?e:null},[t]),i=l(()=>n(r,o),[r,o]);return e(d.Provider,{value:i,children:e(NodeList,{nodes:i,renderers:t})})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/markdown-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React library for parsing and rendering Discord Markdown",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -13,20 +13,19 @@
|
|
|
13
13
|
"src/index.d.ts"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@discord/markdown-wasm": "0.
|
|
16
|
+
"@discord/markdown-wasm": "0.2.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@swc/cli": "^0.5.2",
|
|
20
20
|
"@swc/core": "^1.10.1",
|
|
21
|
-
"@testing-library/jest-dom": "^6.4.8",
|
|
22
21
|
"@testing-library/react": "^16.0.0",
|
|
23
22
|
"@types/react": "^18",
|
|
24
|
-
"
|
|
23
|
+
"@vitest/browser-playwright": "^4.1.4",
|
|
24
|
+
"playwright": "^1.59.1",
|
|
25
25
|
"react": "^18.3.1",
|
|
26
|
-
"vite": "
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"@discord/markdown-types": "0.1.4"
|
|
26
|
+
"vite": "6",
|
|
27
|
+
"vitest": "^4.1.4",
|
|
28
|
+
"@discord/markdown-types": "0.2.0"
|
|
30
29
|
},
|
|
31
30
|
"peerDependencies": {
|
|
32
31
|
"react": "17 - 19"
|