@discord/markdown-react 0.1.2 → 0.1.3
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 +3 -3
- package/src/index.d.ts +2 -0
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsx as e,Fragment as r}from"react/jsx-runtime";import{parse as t}from"@discord/markdown-wasm";import{memo as n,useMemo as o,createContext as l,useContext as s}from"react";let i=l(null);export function useAst(){return s(i)}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:t}){let n=t[r.type];if(!function(e,r){if(null==e)throw Error(`Attempted to render "${r}" but no renderer was provided`)}(n,r.type),Array.isArray(r.value))return e(n,{children:e(NodeList,{nodes:r.value,renderers:t})});switch(r.type){case"mention":case"timestamp":case"emoji":case"code_block":return e(n,{...r.value});case"link":let o=r.value,l=null;if("normal"===o.type){let{value:{text:r,url:n}}=o;l=r?e(NodeList,{nodes:r,renderers:t}):n}return e(n,{...r.value,children:l});case"text":case"code":return e(n,{children:r.value});case"heading":return e(n,{level:r.value.level,children:e(NodeList,{nodes:r.value.content,renderers:t})});case"list":let s=t.listItem??"li";return e(n,{...r.value,children:r.value.items.map((r,n)=>e(s,{children:e(NodeList,{nodes:r.content,renderers:t})},n))});case"empty":return e(n,{});case"small":return e(n,{children:e(NodeList,{nodes:r.value.content,renderers:t})});default:throw TypeError(`Unknown node type "${r.type}"`)}}export const NodeList=n(function({nodes:t,renderers:n}){return e(r,{children:t.map((r,t)=>e(Node,{node:r,renderers:n},t))})});export default function d({content:r,renderers:n}){let l=o(()=>{let e=Object.keys(n).filter(e=>RULES.has(e));return e.length>0?e:null},[n]),s=o(()=>t(r,l),[r,l]);return e(i.Provider,{value:s,children:e(NodeList,{nodes:s,renderers:n})})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/markdown-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React library for parsing and rendering Discord Markdown",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"react": "^18.3.1",
|
|
17
|
-
"@discord/markdown-wasm": "0.1.
|
|
17
|
+
"@discord/markdown-wasm": "0.1.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@swc/cli": "^0.5.2",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"vite": "^5.4.0",
|
|
27
27
|
"vite-plugin-wasm": "^3.3.0",
|
|
28
28
|
"vitest": "^2.0.3",
|
|
29
|
-
"@discord/markdown-types": "0.1.
|
|
29
|
+
"@discord/markdown-types": "0.1.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"test": "vitest run",
|
package/src/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Mention,
|
|
9
9
|
Link,
|
|
10
10
|
List,
|
|
11
|
+
Block,
|
|
11
12
|
} from "@discord/markdown-types";
|
|
12
13
|
|
|
13
14
|
type NodeRenderProps<P = {}> = React.PropsWithChildren<P>;
|
|
@@ -111,6 +112,7 @@ export type MarkdownProps = {
|
|
|
111
112
|
export const INLINE_RULES: string[];
|
|
112
113
|
export const BLOCK_RULES: string[];
|
|
113
114
|
|
|
115
|
+
export function useAst(): Block[];
|
|
114
116
|
export function Node(props: NodeProps): React.ReactNode;
|
|
115
117
|
export function NodeList(props: NodeListProps): React.ReactNode;
|
|
116
118
|
export default function Markdown(props: MarkdownProps): React.ReactNode;
|