writr 6.0.1 → 6.1.1
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/README.md +10 -2
- package/dist/writr.d.ts +2 -0
- package/dist/writr.js +40 -4
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* Github Flavor Markdown (remark-gfm).
|
|
23
23
|
* Emoji Support (remark-emoji).
|
|
24
24
|
* MDX Support (remark-mdx).
|
|
25
|
+
* Raw HTML Passthrough (rehype-raw).
|
|
25
26
|
* Built in Hooks for adding code to render pipeline.
|
|
26
27
|
* AI-powered metadata generation, SEO, and translation via the [Vercel AI SDK](https://sdk.vercel.ai).
|
|
27
28
|
|
|
@@ -118,6 +119,7 @@ const writrOptions = {
|
|
|
118
119
|
gfm: true,
|
|
119
120
|
math: true,
|
|
120
121
|
mdx: true,
|
|
122
|
+
rawHtml: false,
|
|
121
123
|
caching: true,
|
|
122
124
|
}
|
|
123
125
|
};
|
|
@@ -142,6 +144,7 @@ const writrOptions = {
|
|
|
142
144
|
gfm: true,
|
|
143
145
|
math: true,
|
|
144
146
|
mdx: true,
|
|
147
|
+
rawHtml: false,
|
|
145
148
|
caching: true,
|
|
146
149
|
}
|
|
147
150
|
};
|
|
@@ -190,14 +193,19 @@ Accessing the default options for this instance of Writr. Here is the default se
|
|
|
190
193
|
gfm: true,
|
|
191
194
|
math: true,
|
|
192
195
|
mdx: false,
|
|
196
|
+
rawHtml: false,
|
|
193
197
|
caching: true,
|
|
194
198
|
}
|
|
195
199
|
}
|
|
196
200
|
```
|
|
197
201
|
|
|
202
|
+
By default, raw HTML in markdown (such as `<iframe>`, `<video>`, or `<div>` tags) is stripped during rendering. Set `rawHtml: true` to preserve raw HTML elements and their attributes in the rendered output. This is useful for embedding videos, widgets, or custom HTML in your markdown content.
|
|
203
|
+
|
|
204
|
+
**Note:** Setting `mdx: true` also enables raw HTML passthrough as part of the MDX specification. The `rawHtml` option is for enabling raw HTML in standard markdown without using MDX.
|
|
205
|
+
|
|
198
206
|
## `.frontmatter`
|
|
199
207
|
|
|
200
|
-
Accessing the frontmatter for this instance of Writr. This is a `Record
|
|
208
|
+
Accessing the frontmatter for this instance of Writr. This is a `Record<string, any>` and can be set via the `.content` property.
|
|
201
209
|
|
|
202
210
|
```javascript
|
|
203
211
|
import { Writr } from 'writr';
|
|
@@ -247,7 +255,7 @@ const html = await writr.render(options); // <h1>Hello World ::-):</h1><p>This i
|
|
|
247
255
|
|
|
248
256
|
## `.engine`
|
|
249
257
|
|
|
250
|
-
Accessing the underlying engine for this instance of Writr. This is a `Processor
|
|
258
|
+
Accessing the underlying engine for this instance of Writr. This is a `Processor<Root, Root, Root, undefined, undefined>` from the core [`unified`](https://github.com/unifiedjs/unified) project and uses the familiar `.use()` plugin pattern. You can chain additional unified plugins on this processor to customize the render pipeline. Learn more about the unified engine at [unifiedjs.com](https://unifiedjs.com/) and check out the [getting started guide](https://unifiedjs.com/learn/guide/using-unified/) for examples.
|
|
251
259
|
|
|
252
260
|
|
|
253
261
|
## `.render(options?: RenderOptions)`
|
package/dist/writr.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ type WritrOptions = {
|
|
|
26
26
|
* @property {boolean} [gfm] - Github flavor markdown (default: true)
|
|
27
27
|
* @property {boolean} [math] - Math support (default: true)
|
|
28
28
|
* @property {boolean} [mdx] - MDX support (default: false)
|
|
29
|
+
* @property {boolean} [rawHtml] - Raw HTML passthrough (default: false)
|
|
29
30
|
* @property {boolean} [caching] - Caching (default: true)
|
|
30
31
|
*/
|
|
31
32
|
type RenderOptions = {
|
|
@@ -36,6 +37,7 @@ type RenderOptions = {
|
|
|
36
37
|
gfm?: boolean;
|
|
37
38
|
math?: boolean;
|
|
38
39
|
mdx?: boolean;
|
|
40
|
+
rawHtml?: boolean;
|
|
39
41
|
caching?: boolean;
|
|
40
42
|
};
|
|
41
43
|
/**
|
package/dist/writr.js
CHANGED
|
@@ -6,6 +6,7 @@ import parse from "html-react-parser";
|
|
|
6
6
|
import * as yaml from "js-yaml";
|
|
7
7
|
import rehypeHighlight from "rehype-highlight";
|
|
8
8
|
import rehypeKatex from "rehype-katex";
|
|
9
|
+
import rehypeRaw from "rehype-raw";
|
|
9
10
|
import rehypeSlug from "rehype-slug";
|
|
10
11
|
import rehypeStringify from "rehype-stringify";
|
|
11
12
|
import remarkEmoji from "remark-emoji";
|
|
@@ -461,6 +462,7 @@ var Writr = class extends Hookified {
|
|
|
461
462
|
gfm: true,
|
|
462
463
|
math: true,
|
|
463
464
|
mdx: false,
|
|
465
|
+
rawHtml: false,
|
|
464
466
|
caching: true
|
|
465
467
|
}
|
|
466
468
|
};
|
|
@@ -942,7 +944,23 @@ ${yamlString}---
|
|
|
942
944
|
if (options.emoji) {
|
|
943
945
|
processor.use(remarkEmoji);
|
|
944
946
|
}
|
|
945
|
-
|
|
947
|
+
if (options.mdx) {
|
|
948
|
+
processor.use(remarkMDX);
|
|
949
|
+
}
|
|
950
|
+
const rehypeOptions = {};
|
|
951
|
+
if (options.rawHtml) {
|
|
952
|
+
rehypeOptions.allowDangerousHtml = true;
|
|
953
|
+
}
|
|
954
|
+
if (options.mdx) {
|
|
955
|
+
rehypeOptions.handlers = {
|
|
956
|
+
mdxJsxFlowElement: mdxJsxHandler,
|
|
957
|
+
mdxJsxTextElement: mdxJsxHandler
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
processor.use(remarkRehype, rehypeOptions);
|
|
961
|
+
if (options.rawHtml) {
|
|
962
|
+
processor.use(rehypeRaw);
|
|
963
|
+
}
|
|
946
964
|
if (options.slug) {
|
|
947
965
|
processor.use(rehypeSlug);
|
|
948
966
|
}
|
|
@@ -952,9 +970,6 @@ ${yamlString}---
|
|
|
952
970
|
if (options.math) {
|
|
953
971
|
processor.use(remarkMath).use(rehypeKatex);
|
|
954
972
|
}
|
|
955
|
-
if (options.mdx) {
|
|
956
|
-
processor.use(remarkMDX);
|
|
957
|
-
}
|
|
958
973
|
processor.use(rehypeStringify);
|
|
959
974
|
return processor;
|
|
960
975
|
}
|
|
@@ -980,12 +995,33 @@ ${yamlString}---
|
|
|
980
995
|
if (options.mdx !== void 0) {
|
|
981
996
|
current.mdx = options.mdx;
|
|
982
997
|
}
|
|
998
|
+
if (options.rawHtml !== void 0) {
|
|
999
|
+
current.rawHtml = options.rawHtml;
|
|
1000
|
+
}
|
|
983
1001
|
if (options.caching !== void 0) {
|
|
984
1002
|
current.caching = options.caching;
|
|
985
1003
|
}
|
|
986
1004
|
return current;
|
|
987
1005
|
}
|
|
988
1006
|
};
|
|
1007
|
+
function mdxJsxHandler(state, node) {
|
|
1008
|
+
const properties = {};
|
|
1009
|
+
for (const attr of node.attributes) {
|
|
1010
|
+
if (attr.type === "mdxJsxAttribute") {
|
|
1011
|
+
if (attr.value === null) {
|
|
1012
|
+
properties[attr.name] = true;
|
|
1013
|
+
} else if (typeof attr.value === "string") {
|
|
1014
|
+
properties[attr.name] = attr.value;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return {
|
|
1019
|
+
type: "element",
|
|
1020
|
+
tagName: node.name ?? "div",
|
|
1021
|
+
properties,
|
|
1022
|
+
children: state.all(node)
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
989
1025
|
export {
|
|
990
1026
|
Writr,
|
|
991
1027
|
WritrAI,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "writr",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Markdown Rendering Simplified",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/writr.js",
|
|
@@ -49,15 +49,16 @@
|
|
|
49
49
|
"markdown-to-react"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"ai": "^6.0.
|
|
53
|
-
"cacheable": "^2.3.
|
|
54
|
-
"hashery": "^1.5.
|
|
52
|
+
"ai": "^6.0.138",
|
|
53
|
+
"cacheable": "^2.3.4",
|
|
54
|
+
"hashery": "^1.5.1",
|
|
55
55
|
"hookified": "^2.1.0",
|
|
56
56
|
"html-react-parser": "^5.2.17",
|
|
57
57
|
"js-yaml": "^4.1.1",
|
|
58
58
|
"react": "^19.2.4",
|
|
59
59
|
"rehype-highlight": "^7.0.2",
|
|
60
60
|
"rehype-katex": "^7.0.1",
|
|
61
|
+
"rehype-raw": "^7.0.0",
|
|
61
62
|
"rehype-slug": "^6.0.0",
|
|
62
63
|
"rehype-stringify": "^10.0.1",
|
|
63
64
|
"remark-emoji": "^5.0.2",
|
|
@@ -72,26 +73,26 @@
|
|
|
72
73
|
"zod": "^4.3.6"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@ai-sdk/anthropic": "^3.0.
|
|
76
|
-
"@ai-sdk/google": "^3.0.
|
|
77
|
-
"@ai-sdk/openai": "^3.0.
|
|
78
|
-
"@biomejs/biome": "^2.4.
|
|
76
|
+
"@ai-sdk/anthropic": "^3.0.64",
|
|
77
|
+
"@ai-sdk/google": "^3.0.53",
|
|
78
|
+
"@ai-sdk/openai": "^3.0.48",
|
|
79
|
+
"@biomejs/biome": "^2.4.8",
|
|
79
80
|
"@monstermann/tinybench-pretty-printer": "^0.3.0",
|
|
80
81
|
"@types/js-yaml": "^4.0.9",
|
|
81
82
|
"@types/markdown-it": "^14.1.2",
|
|
82
83
|
"@types/node": "^25.5.0",
|
|
83
84
|
"@types/react": "^19.2.14",
|
|
84
|
-
"@vitest/coverage-v8": "^4.1.
|
|
85
|
-
"docula": "^
|
|
85
|
+
"@vitest/coverage-v8": "^4.1.1",
|
|
86
|
+
"docula": "^1.10.0",
|
|
86
87
|
"dotenv": "^17.3.1",
|
|
87
88
|
"markdown-it": "^14.1.1",
|
|
88
|
-
"marked": "^17.0.
|
|
89
|
+
"marked": "^17.0.5",
|
|
89
90
|
"rimraf": "^6.1.3",
|
|
90
91
|
"tinybench": "^6.0.0",
|
|
91
92
|
"tsup": "^8.5.1",
|
|
92
93
|
"tsx": "^4.21.0",
|
|
93
94
|
"typescript": "^5.9.3",
|
|
94
|
-
"vitest": "^4.1.
|
|
95
|
+
"vitest": "^4.1.1"
|
|
95
96
|
},
|
|
96
97
|
"files": [
|
|
97
98
|
"dist",
|
|
@@ -106,7 +107,7 @@
|
|
|
106
107
|
"test": "pnpm lint && vitest run --coverage",
|
|
107
108
|
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
|
|
108
109
|
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
109
|
-
"website:build": "rimraf ./site/README.md ./site/dist &&
|
|
110
|
-
"website:serve": "rimraf ./site/README.md ./site/dist &&
|
|
110
|
+
"website:build": "rimraf ./site/README.md ./site/dist && pnpm docula build",
|
|
111
|
+
"website:serve": "rimraf ./site/README.md ./site/dist && pnpm docula dev"
|
|
111
112
|
}
|
|
112
113
|
}
|