@react-email/render 0.0.11-canary.0 → 0.0.12-canary.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/index.d.mts +20 -8
- package/dist/index.d.ts +20 -8
- package/dist/index.js +23 -21
- package/dist/index.mjs +22 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
2
4
|
pretty?: boolean;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
} & ({
|
|
6
|
+
plainText?: false;
|
|
7
|
+
} | {
|
|
8
|
+
plainText?: true;
|
|
9
|
+
/**
|
|
10
|
+
* These are options you can pass down directly to the library we use for
|
|
11
|
+
* converting the rendered email's HTML into plain text.
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/html-to-text/node-html-to-text
|
|
14
|
+
*/
|
|
15
|
+
htmlToTextOptions?: HtmlToTextOptions;
|
|
16
|
+
});
|
|
17
|
+
|
|
5
18
|
declare const render: (component: React.ReactElement, options?: Options) => string;
|
|
6
19
|
|
|
7
|
-
declare const renderAsync: (component: React.ReactElement, options?:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}) => Promise<string>;
|
|
20
|
+
declare const renderAsync: (component: React.ReactElement, options?: Options) => Promise<string>;
|
|
21
|
+
|
|
22
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
11
23
|
|
|
12
|
-
export { Options, render, renderAsync };
|
|
24
|
+
export { Options, plainTextSelectors, render, renderAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
2
4
|
pretty?: boolean;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
} & ({
|
|
6
|
+
plainText?: false;
|
|
7
|
+
} | {
|
|
8
|
+
plainText?: true;
|
|
9
|
+
/**
|
|
10
|
+
* These are options you can pass down directly to the library we use for
|
|
11
|
+
* converting the rendered email's HTML into plain text.
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/html-to-text/node-html-to-text
|
|
14
|
+
*/
|
|
15
|
+
htmlToTextOptions?: HtmlToTextOptions;
|
|
16
|
+
});
|
|
17
|
+
|
|
5
18
|
declare const render: (component: React.ReactElement, options?: Options) => string;
|
|
6
19
|
|
|
7
|
-
declare const renderAsync: (component: React.ReactElement, options?:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}) => Promise<string>;
|
|
20
|
+
declare const renderAsync: (component: React.ReactElement, options?: Options) => Promise<string>;
|
|
21
|
+
|
|
22
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
11
23
|
|
|
12
|
-
export { Options, render, renderAsync };
|
|
24
|
+
export { Options, plainTextSelectors, render, renderAsync };
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
70
70
|
// src/index.ts
|
|
71
71
|
var src_exports = {};
|
|
72
72
|
__export(src_exports, {
|
|
73
|
+
plainTextSelectors: () => plainTextSelectors,
|
|
73
74
|
render: () => render,
|
|
74
75
|
renderAsync: () => renderAsync
|
|
75
76
|
});
|
|
@@ -80,7 +81,7 @@ var ReactDomServer = __toESM(require("react-dom/server"));
|
|
|
80
81
|
var import_html_to_text = require("html-to-text");
|
|
81
82
|
|
|
82
83
|
// src/utils/pretty.ts
|
|
83
|
-
var import_js_beautify = require("js-beautify");
|
|
84
|
+
var import_js_beautify = __toESM(require("js-beautify"));
|
|
84
85
|
var defaults = {
|
|
85
86
|
unformatted: ["code", "pre", "em", "strong", "span"],
|
|
86
87
|
indent_inner_html: true,
|
|
@@ -89,9 +90,19 @@ var defaults = {
|
|
|
89
90
|
sep: "\n"
|
|
90
91
|
};
|
|
91
92
|
var pretty = (str, options = {}) => {
|
|
92
|
-
return
|
|
93
|
+
return import_js_beautify.default.html(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
93
94
|
};
|
|
94
95
|
|
|
96
|
+
// src/plain-text-selectors.ts
|
|
97
|
+
var plainTextSelectors = [
|
|
98
|
+
{ selector: "img", format: "skip" },
|
|
99
|
+
{ selector: "#__react-email-preview", format: "skip" },
|
|
100
|
+
{
|
|
101
|
+
selector: "a",
|
|
102
|
+
options: { linkBrackets: false }
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
|
|
95
106
|
// src/render.ts
|
|
96
107
|
var render = (component, options) => {
|
|
97
108
|
if (options == null ? void 0 : options.plainText) {
|
|
@@ -105,17 +116,10 @@ var render = (component, options) => {
|
|
|
105
116
|
}
|
|
106
117
|
return document;
|
|
107
118
|
};
|
|
108
|
-
var renderAsPlainText = (component,
|
|
109
|
-
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), {
|
|
110
|
-
selectors:
|
|
111
|
-
|
|
112
|
-
{ selector: "#__react-email-preview", format: "skip" },
|
|
113
|
-
{
|
|
114
|
-
selector: "a",
|
|
115
|
-
options: { linkBrackets: false }
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
});
|
|
119
|
+
var renderAsPlainText = (component, options) => {
|
|
120
|
+
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), __spreadValues({
|
|
121
|
+
selectors: plainTextSelectors
|
|
122
|
+
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
|
|
119
123
|
};
|
|
120
124
|
|
|
121
125
|
// src/render-async.ts
|
|
@@ -157,16 +161,13 @@ var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
|
157
161
|
const renderToStream = (_a = reactDOMServer.renderToReadableStream) != null ? _a : reactDOMServer.renderToStaticNodeStream;
|
|
158
162
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
159
163
|
const htmlOrReadableStream = yield renderToStream(component);
|
|
160
|
-
const
|
|
164
|
+
const html = typeof htmlOrReadableStream === "string" ? htmlOrReadableStream : yield readStream(htmlOrReadableStream);
|
|
161
165
|
if (options == null ? void 0 : options.plainText) {
|
|
162
|
-
return (0, import_html_to_text2.convert)(
|
|
163
|
-
selectors:
|
|
164
|
-
|
|
165
|
-
{ selector: "#__react-email-preview", format: "skip" }
|
|
166
|
-
]
|
|
167
|
-
});
|
|
166
|
+
return (0, import_html_to_text2.convert)(html, __spreadValues({
|
|
167
|
+
selectors: plainTextSelectors
|
|
168
|
+
}, options.htmlToTextOptions));
|
|
168
169
|
}
|
|
169
|
-
const document = `${doctype}${
|
|
170
|
+
const document = `${doctype}${html}`;
|
|
170
171
|
if (options == null ? void 0 : options.pretty) {
|
|
171
172
|
return pretty(document);
|
|
172
173
|
}
|
|
@@ -174,6 +175,7 @@ var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
|
174
175
|
});
|
|
175
176
|
// Annotate the CommonJS export names for ESM import in node:
|
|
176
177
|
0 && (module.exports = {
|
|
178
|
+
plainTextSelectors,
|
|
177
179
|
render,
|
|
178
180
|
renderAsync
|
|
179
181
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -46,7 +46,7 @@ import * as ReactDomServer from "react-dom/server";
|
|
|
46
46
|
import { convert } from "html-to-text";
|
|
47
47
|
|
|
48
48
|
// src/utils/pretty.ts
|
|
49
|
-
import
|
|
49
|
+
import jsBeautify from "js-beautify";
|
|
50
50
|
var defaults = {
|
|
51
51
|
unformatted: ["code", "pre", "em", "strong", "span"],
|
|
52
52
|
indent_inner_html: true,
|
|
@@ -55,9 +55,19 @@ var defaults = {
|
|
|
55
55
|
sep: "\n"
|
|
56
56
|
};
|
|
57
57
|
var pretty = (str, options = {}) => {
|
|
58
|
-
return html(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
58
|
+
return jsBeautify.html(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
// src/plain-text-selectors.ts
|
|
62
|
+
var plainTextSelectors = [
|
|
63
|
+
{ selector: "img", format: "skip" },
|
|
64
|
+
{ selector: "#__react-email-preview", format: "skip" },
|
|
65
|
+
{
|
|
66
|
+
selector: "a",
|
|
67
|
+
options: { linkBrackets: false }
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
|
|
61
71
|
// src/render.ts
|
|
62
72
|
var render = (component, options) => {
|
|
63
73
|
if (options == null ? void 0 : options.plainText) {
|
|
@@ -71,17 +81,10 @@ var render = (component, options) => {
|
|
|
71
81
|
}
|
|
72
82
|
return document;
|
|
73
83
|
};
|
|
74
|
-
var renderAsPlainText = (component,
|
|
75
|
-
return convert(ReactDomServer.renderToStaticMarkup(component), {
|
|
76
|
-
selectors:
|
|
77
|
-
|
|
78
|
-
{ selector: "#__react-email-preview", format: "skip" },
|
|
79
|
-
{
|
|
80
|
-
selector: "a",
|
|
81
|
-
options: { linkBrackets: false }
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
});
|
|
84
|
+
var renderAsPlainText = (component, options) => {
|
|
85
|
+
return convert(ReactDomServer.renderToStaticMarkup(component), __spreadValues({
|
|
86
|
+
selectors: plainTextSelectors
|
|
87
|
+
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
|
|
85
88
|
};
|
|
86
89
|
|
|
87
90
|
// src/render-async.ts
|
|
@@ -123,22 +126,20 @@ var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
|
123
126
|
const renderToStream = (_a = reactDOMServer.renderToReadableStream) != null ? _a : reactDOMServer.renderToStaticNodeStream;
|
|
124
127
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
125
128
|
const htmlOrReadableStream = yield renderToStream(component);
|
|
126
|
-
const
|
|
129
|
+
const html = typeof htmlOrReadableStream === "string" ? htmlOrReadableStream : yield readStream(htmlOrReadableStream);
|
|
127
130
|
if (options == null ? void 0 : options.plainText) {
|
|
128
|
-
return convert2(
|
|
129
|
-
selectors:
|
|
130
|
-
|
|
131
|
-
{ selector: "#__react-email-preview", format: "skip" }
|
|
132
|
-
]
|
|
133
|
-
});
|
|
131
|
+
return convert2(html, __spreadValues({
|
|
132
|
+
selectors: plainTextSelectors
|
|
133
|
+
}, options.htmlToTextOptions));
|
|
134
134
|
}
|
|
135
|
-
const document = `${doctype}${
|
|
135
|
+
const document = `${doctype}${html}`;
|
|
136
136
|
if (options == null ? void 0 : options.pretty) {
|
|
137
137
|
return pretty(document);
|
|
138
138
|
}
|
|
139
139
|
return document;
|
|
140
140
|
});
|
|
141
141
|
export {
|
|
142
|
+
plainTextSelectors,
|
|
142
143
|
render,
|
|
143
144
|
renderAsync
|
|
144
145
|
};
|