@readme/markdown 7.4.3 → 7.5.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 +8 -0
- package/dist/lib/mdx.d.ts +1 -1
- package/dist/main.js +51 -33
- package/dist/main.node.js +51 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,14 @@ A module ([`RMDXModule`](#rmdxmodule)) of renderable components
|
|
|
50
50
|
|
|
51
51
|
Compiles an ast to mdx.
|
|
52
52
|
|
|
53
|
+
###### Parameters
|
|
54
|
+
|
|
55
|
+
Extends [`remark-stringify` options](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options).
|
|
56
|
+
|
|
57
|
+
###### Returns
|
|
58
|
+
|
|
59
|
+
An mdx string.
|
|
60
|
+
|
|
53
61
|
#### `mdast`
|
|
54
62
|
|
|
55
63
|
Parses mdx to an mdast.
|
package/dist/lib/mdx.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -47933,6 +47933,9 @@ const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
|
|
|
47933
47933
|
if (typeof attr.value === 'string') {
|
|
47934
47934
|
memo[attr.name] = attr.value;
|
|
47935
47935
|
}
|
|
47936
|
+
else if (attr.value === null) {
|
|
47937
|
+
memo[attr.name] = true;
|
|
47938
|
+
}
|
|
47936
47939
|
else if (attr.value.value !== 'undefined') {
|
|
47937
47940
|
memo[attr.name] = JSON.parse(attr.value.value);
|
|
47938
47941
|
}
|
|
@@ -48007,15 +48010,15 @@ const reformatHTML = (html, indent = 2) => {
|
|
|
48007
48010
|
const toAttributes = (object, keys = []) => {
|
|
48008
48011
|
let attributes = [];
|
|
48009
48012
|
Object.entries(object).forEach(([name, v]) => {
|
|
48010
|
-
if (
|
|
48013
|
+
if (keys.length > 0 && !keys.includes(name))
|
|
48011
48014
|
return;
|
|
48012
48015
|
let value;
|
|
48013
|
-
if (typeof v === '
|
|
48014
|
-
value = v;
|
|
48015
|
-
}
|
|
48016
|
-
else if (typeof v === 'undefined') {
|
|
48016
|
+
if (typeof v === 'undefined' || v === null || v === '') {
|
|
48017
48017
|
return;
|
|
48018
48018
|
}
|
|
48019
|
+
else if (typeof v === 'string') {
|
|
48020
|
+
value = v;
|
|
48021
|
+
}
|
|
48019
48022
|
else {
|
|
48020
48023
|
/* values can be null, undefined, string, or a expression, eg:
|
|
48021
48024
|
*
|
|
@@ -48057,18 +48060,21 @@ const imageTransformer = () => (tree) => {
|
|
|
48057
48060
|
if (parent.type !== 'root' || ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || node.children[0].type !== 'image')
|
|
48058
48061
|
return;
|
|
48059
48062
|
const [{ alt, url, title }] = node.children;
|
|
48060
|
-
const
|
|
48061
|
-
type: NodeTypes.imageBlock,
|
|
48063
|
+
const attrs = {
|
|
48062
48064
|
alt,
|
|
48063
48065
|
title,
|
|
48064
|
-
url,
|
|
48065
48066
|
children: [],
|
|
48067
|
+
src: url,
|
|
48068
|
+
};
|
|
48069
|
+
const newNode = Object.assign(Object.assign({ type: NodeTypes.imageBlock }, attrs), {
|
|
48070
|
+
/*
|
|
48071
|
+
* @note: Using data.hName here means that we don't have to transform
|
|
48072
|
+
* this to an MdxJsxFlowElement, and rehype will transform it correctly
|
|
48073
|
+
*/
|
|
48066
48074
|
data: {
|
|
48067
48075
|
hName: 'img',
|
|
48068
|
-
hProperties:
|
|
48069
|
-
},
|
|
48070
|
-
position: node.position,
|
|
48071
|
-
};
|
|
48076
|
+
hProperties: attrs,
|
|
48077
|
+
}, position: node.position });
|
|
48072
48078
|
parent.children.splice(i, 1, newNode);
|
|
48073
48079
|
});
|
|
48074
48080
|
const isImage = (node) => node.name === 'Image';
|
|
@@ -65163,20 +65169,12 @@ const coerceJsxToMd = ({ components = {}, html = false } = {}) => (node, index,
|
|
|
65163
65169
|
}
|
|
65164
65170
|
else if (node.name === 'Image') {
|
|
65165
65171
|
const { position } = node;
|
|
65166
|
-
const { alt = '',
|
|
65167
|
-
const attrs =
|
|
65168
|
-
const mdNode = {
|
|
65169
|
-
alt,
|
|
65170
|
-
position,
|
|
65171
|
-
children: attrs.caption ? lib_mdast(attrs.caption).children : node.children,
|
|
65172
|
-
title,
|
|
65173
|
-
type: NodeTypes.imageBlock,
|
|
65174
|
-
url: url || attrs.src,
|
|
65175
|
-
data: {
|
|
65172
|
+
const { alt = '', align, border, caption, title = null, width, src, } = getAttrs(node);
|
|
65173
|
+
const attrs = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (align && { align })), (border && { border })), (src && { src })), (width && { width })), { alt, children: caption ? lib_mdast(caption).children : node.children, title });
|
|
65174
|
+
const mdNode = Object.assign(Object.assign({}, attrs), { position, type: NodeTypes.imageBlock, data: {
|
|
65176
65175
|
hName: 'img',
|
|
65177
65176
|
hProperties: attrs,
|
|
65178
|
-
}
|
|
65179
|
-
};
|
|
65177
|
+
} });
|
|
65180
65178
|
parent.children[index] = mdNode;
|
|
65181
65179
|
}
|
|
65182
65180
|
else if (node.name === 'HTMLBlock') {
|
|
@@ -65330,15 +65328,23 @@ const readmeToMdx = () => tree => {
|
|
|
65330
65328
|
});
|
|
65331
65329
|
}
|
|
65332
65330
|
else {
|
|
65333
|
-
parent.children.splice(index, 1, {
|
|
65334
|
-
type: 'image',
|
|
65335
|
-
children: [],
|
|
65336
|
-
url: image.url,
|
|
65337
|
-
title: image.title,
|
|
65338
|
-
alt: image.alt,
|
|
65339
|
-
});
|
|
65331
|
+
parent.children.splice(index, 1, Object.assign(Object.assign(Object.assign({ type: 'image', children: [] }, (image.src && { url: image.src })), (image.title && { title: image.title })), (image.alt && { alt: image.alt })));
|
|
65340
65332
|
}
|
|
65341
65333
|
});
|
|
65334
|
+
visit(tree, 'html', (node, index, parent) => {
|
|
65335
|
+
const html = node.value;
|
|
65336
|
+
const isScriptOrStyleTag = [!!html.match(/^<(?:style|script)/i), !!html.match(/<\/(?:style|script)>$/i)];
|
|
65337
|
+
if (!isScriptOrStyleTag.includes(true))
|
|
65338
|
+
return;
|
|
65339
|
+
parent.children.splice(index, 1, {
|
|
65340
|
+
type: 'html-block',
|
|
65341
|
+
children: [{ type: 'text', value: html }],
|
|
65342
|
+
data: {
|
|
65343
|
+
hName: 'html-block',
|
|
65344
|
+
hProperties: { html },
|
|
65345
|
+
},
|
|
65346
|
+
});
|
|
65347
|
+
});
|
|
65342
65348
|
return tree;
|
|
65343
65349
|
};
|
|
65344
65350
|
/* harmony default export */ const readme_to_mdx = (readmeToMdx);
|
|
@@ -93982,6 +93988,17 @@ function compilers() {
|
|
|
93982
93988
|
/* harmony default export */ const processor_compile = (compilers);
|
|
93983
93989
|
|
|
93984
93990
|
;// CONCATENATED MODULE: ./lib/mdx.ts
|
|
93991
|
+
var mdx_rest = (undefined && undefined.__rest) || function (s, e) {
|
|
93992
|
+
var t = {};
|
|
93993
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
93994
|
+
t[p] = s[p];
|
|
93995
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
93996
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
93997
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
93998
|
+
t[p[i]] = s[p[i]];
|
|
93999
|
+
}
|
|
94000
|
+
return t;
|
|
94001
|
+
};
|
|
93985
94002
|
|
|
93986
94003
|
|
|
93987
94004
|
|
|
@@ -93989,7 +94006,8 @@ function compilers() {
|
|
|
93989
94006
|
|
|
93990
94007
|
|
|
93991
94008
|
|
|
93992
|
-
const mdx_mdx = (tree,
|
|
94009
|
+
const mdx_mdx = (tree, _a = {}) => {
|
|
94010
|
+
var { hast = false } = _a, opts = mdx_rest(_a, ["hast"]);
|
|
93993
94011
|
const processor = unified()
|
|
93994
94012
|
.use(hast ? rehypeRemark : undefined)
|
|
93995
94013
|
.use(remarkMdx)
|
|
@@ -93998,7 +94016,7 @@ const mdx_mdx = (tree, { hast = false } = {}) => {
|
|
|
93998
94016
|
.use(readme_to_mdx)
|
|
93999
94017
|
.use(tables_to_jsx)
|
|
94000
94018
|
.use(processor_compile)
|
|
94001
|
-
.use(remarkStringify);
|
|
94019
|
+
.use(remarkStringify, opts);
|
|
94002
94020
|
return processor.stringify(processor.runSync(tree));
|
|
94003
94021
|
};
|
|
94004
94022
|
/* harmony default export */ const lib_mdx = (mdx_mdx);
|
package/dist/main.node.js
CHANGED
|
@@ -48920,6 +48920,9 @@ const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
|
|
|
48920
48920
|
if (typeof attr.value === 'string') {
|
|
48921
48921
|
memo[attr.name] = attr.value;
|
|
48922
48922
|
}
|
|
48923
|
+
else if (attr.value === null) {
|
|
48924
|
+
memo[attr.name] = true;
|
|
48925
|
+
}
|
|
48923
48926
|
else if (attr.value.value !== 'undefined') {
|
|
48924
48927
|
memo[attr.name] = JSON.parse(attr.value.value);
|
|
48925
48928
|
}
|
|
@@ -48994,15 +48997,15 @@ const reformatHTML = (html, indent = 2) => {
|
|
|
48994
48997
|
const toAttributes = (object, keys = []) => {
|
|
48995
48998
|
let attributes = [];
|
|
48996
48999
|
Object.entries(object).forEach(([name, v]) => {
|
|
48997
|
-
if (
|
|
49000
|
+
if (keys.length > 0 && !keys.includes(name))
|
|
48998
49001
|
return;
|
|
48999
49002
|
let value;
|
|
49000
|
-
if (typeof v === '
|
|
49001
|
-
value = v;
|
|
49002
|
-
}
|
|
49003
|
-
else if (typeof v === 'undefined') {
|
|
49003
|
+
if (typeof v === 'undefined' || v === null || v === '') {
|
|
49004
49004
|
return;
|
|
49005
49005
|
}
|
|
49006
|
+
else if (typeof v === 'string') {
|
|
49007
|
+
value = v;
|
|
49008
|
+
}
|
|
49006
49009
|
else {
|
|
49007
49010
|
/* values can be null, undefined, string, or a expression, eg:
|
|
49008
49011
|
*
|
|
@@ -49044,18 +49047,21 @@ const imageTransformer = () => (tree) => {
|
|
|
49044
49047
|
if (parent.type !== 'root' || ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || node.children[0].type !== 'image')
|
|
49045
49048
|
return;
|
|
49046
49049
|
const [{ alt, url, title }] = node.children;
|
|
49047
|
-
const
|
|
49048
|
-
type: NodeTypes.imageBlock,
|
|
49050
|
+
const attrs = {
|
|
49049
49051
|
alt,
|
|
49050
49052
|
title,
|
|
49051
|
-
url,
|
|
49052
49053
|
children: [],
|
|
49054
|
+
src: url,
|
|
49055
|
+
};
|
|
49056
|
+
const newNode = Object.assign(Object.assign({ type: NodeTypes.imageBlock }, attrs), {
|
|
49057
|
+
/*
|
|
49058
|
+
* @note: Using data.hName here means that we don't have to transform
|
|
49059
|
+
* this to an MdxJsxFlowElement, and rehype will transform it correctly
|
|
49060
|
+
*/
|
|
49053
49061
|
data: {
|
|
49054
49062
|
hName: 'img',
|
|
49055
|
-
hProperties:
|
|
49056
|
-
},
|
|
49057
|
-
position: node.position,
|
|
49058
|
-
};
|
|
49063
|
+
hProperties: attrs,
|
|
49064
|
+
}, position: node.position });
|
|
49059
49065
|
parent.children.splice(i, 1, newNode);
|
|
49060
49066
|
});
|
|
49061
49067
|
const isImage = (node) => node.name === 'Image';
|
|
@@ -66150,20 +66156,12 @@ const coerceJsxToMd = ({ components = {}, html = false } = {}) => (node, index,
|
|
|
66150
66156
|
}
|
|
66151
66157
|
else if (node.name === 'Image') {
|
|
66152
66158
|
const { position } = node;
|
|
66153
|
-
const { alt = '',
|
|
66154
|
-
const attrs =
|
|
66155
|
-
const mdNode = {
|
|
66156
|
-
alt,
|
|
66157
|
-
position,
|
|
66158
|
-
children: attrs.caption ? lib_mdast(attrs.caption).children : node.children,
|
|
66159
|
-
title,
|
|
66160
|
-
type: NodeTypes.imageBlock,
|
|
66161
|
-
url: url || attrs.src,
|
|
66162
|
-
data: {
|
|
66159
|
+
const { alt = '', align, border, caption, title = null, width, src, } = getAttrs(node);
|
|
66160
|
+
const attrs = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (align && { align })), (border && { border })), (src && { src })), (width && { width })), { alt, children: caption ? lib_mdast(caption).children : node.children, title });
|
|
66161
|
+
const mdNode = Object.assign(Object.assign({}, attrs), { position, type: NodeTypes.imageBlock, data: {
|
|
66163
66162
|
hName: 'img',
|
|
66164
66163
|
hProperties: attrs,
|
|
66165
|
-
}
|
|
66166
|
-
};
|
|
66164
|
+
} });
|
|
66167
66165
|
parent.children[index] = mdNode;
|
|
66168
66166
|
}
|
|
66169
66167
|
else if (node.name === 'HTMLBlock') {
|
|
@@ -66317,15 +66315,23 @@ const readmeToMdx = () => tree => {
|
|
|
66317
66315
|
});
|
|
66318
66316
|
}
|
|
66319
66317
|
else {
|
|
66320
|
-
parent.children.splice(index, 1, {
|
|
66321
|
-
type: 'image',
|
|
66322
|
-
children: [],
|
|
66323
|
-
url: image.url,
|
|
66324
|
-
title: image.title,
|
|
66325
|
-
alt: image.alt,
|
|
66326
|
-
});
|
|
66318
|
+
parent.children.splice(index, 1, Object.assign(Object.assign(Object.assign({ type: 'image', children: [] }, (image.src && { url: image.src })), (image.title && { title: image.title })), (image.alt && { alt: image.alt })));
|
|
66327
66319
|
}
|
|
66328
66320
|
});
|
|
66321
|
+
visit(tree, 'html', (node, index, parent) => {
|
|
66322
|
+
const html = node.value;
|
|
66323
|
+
const isScriptOrStyleTag = [!!html.match(/^<(?:style|script)/i), !!html.match(/<\/(?:style|script)>$/i)];
|
|
66324
|
+
if (!isScriptOrStyleTag.includes(true))
|
|
66325
|
+
return;
|
|
66326
|
+
parent.children.splice(index, 1, {
|
|
66327
|
+
type: 'html-block',
|
|
66328
|
+
children: [{ type: 'text', value: html }],
|
|
66329
|
+
data: {
|
|
66330
|
+
hName: 'html-block',
|
|
66331
|
+
hProperties: { html },
|
|
66332
|
+
},
|
|
66333
|
+
});
|
|
66334
|
+
});
|
|
66329
66335
|
return tree;
|
|
66330
66336
|
};
|
|
66331
66337
|
/* harmony default export */ const readme_to_mdx = (readmeToMdx);
|
|
@@ -94969,6 +94975,17 @@ function compilers() {
|
|
|
94969
94975
|
/* harmony default export */ const processor_compile = (compilers);
|
|
94970
94976
|
|
|
94971
94977
|
;// CONCATENATED MODULE: ./lib/mdx.ts
|
|
94978
|
+
var mdx_rest = (undefined && undefined.__rest) || function (s, e) {
|
|
94979
|
+
var t = {};
|
|
94980
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
94981
|
+
t[p] = s[p];
|
|
94982
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
94983
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
94984
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
94985
|
+
t[p[i]] = s[p[i]];
|
|
94986
|
+
}
|
|
94987
|
+
return t;
|
|
94988
|
+
};
|
|
94972
94989
|
|
|
94973
94990
|
|
|
94974
94991
|
|
|
@@ -94976,7 +94993,8 @@ function compilers() {
|
|
|
94976
94993
|
|
|
94977
94994
|
|
|
94978
94995
|
|
|
94979
|
-
const mdx_mdx = (tree,
|
|
94996
|
+
const mdx_mdx = (tree, _a = {}) => {
|
|
94997
|
+
var { hast = false } = _a, opts = mdx_rest(_a, ["hast"]);
|
|
94980
94998
|
const processor = unified()
|
|
94981
94999
|
.use(hast ? rehypeRemark : undefined)
|
|
94982
95000
|
.use(remarkMdx)
|
|
@@ -94985,7 +95003,7 @@ const mdx_mdx = (tree, { hast = false } = {}) => {
|
|
|
94985
95003
|
.use(readme_to_mdx)
|
|
94986
95004
|
.use(tables_to_jsx)
|
|
94987
95005
|
.use(processor_compile)
|
|
94988
|
-
.use(remarkStringify);
|
|
95006
|
+
.use(remarkStringify, opts);
|
|
94989
95007
|
return processor.stringify(processor.runSync(tree));
|
|
94990
95008
|
};
|
|
94991
95009
|
/* harmony default export */ const lib_mdx = (mdx_mdx);
|
package/package.json
CHANGED