@readme/markdown 11.5.2 → 11.6.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.ts CHANGED
@@ -6,7 +6,7 @@ declare const utils: {
6
6
  getHref: typeof getHref;
7
7
  calloutIcons: {};
8
8
  };
9
- export { compile, exports, hast, run, mdast, mdastV6, mdx, migrate, plain, remarkPlugins, tags } from './lib';
9
+ export { compile, exports, hast, run, mdast, mdastV6, mdx, migrate, plain, remarkPlugins, stripComments, tags } from './lib';
10
10
  export { default as Owlmoji } from './lib/owlmoji';
11
11
  export { Components, utils };
12
12
  export { tailwindCompiler } from './utils/tailwind-compiler';
@@ -10,3 +10,4 @@ export { default as migrate } from './migrate';
10
10
  export { default as plain } from './plain';
11
11
  export { default as run } from './run';
12
12
  export { default as tags } from './tags';
13
+ export { default as stripComments } from './stripComments';
@@ -0,0 +1,8 @@
1
+ interface Opts {
2
+ mdx?: boolean;
3
+ }
4
+ /**
5
+ * Removes Markdown and MDX comments.
6
+ */
7
+ declare function stripComments(doc: string, { mdx }?: Opts): Promise<string>;
8
+ export default stripComments;
package/dist/main.js CHANGED
@@ -8720,6 +8720,7 @@ __webpack_require__.d(__webpack_exports__, {
8720
8720
  plain: () => (/* reexport */ lib_plain),
8721
8721
  remarkPlugins: () => (/* reexport */ remarkPlugins),
8722
8722
  run: () => (/* reexport */ lib_run),
8723
+ stripComments: () => (/* reexport */ lib_stripComments),
8723
8724
  tags: () => (/* reexport */ lib_tags),
8724
8725
  tailwindCompiler: () => (/* reexport */ tailwindCompiler),
8725
8726
  utils: () => (/* binding */ utils)
@@ -87982,6 +87983,66 @@ const tags = (doc) => {
87982
87983
  };
87983
87984
  /* harmony default export */ const lib_tags = (tags);
87984
87985
 
87986
+ ;// ./processor/transform/stripComments.ts
87987
+
87988
+ const HTML_COMMENT_REGEX = /<!--[\s\S]*?-->/g;
87989
+ const MDX_COMMENT_REGEX = /\/\*[\s\S]*?\*\//g;
87990
+ /**
87991
+ * A remark plugin to remove comments from Markdown and MDX.
87992
+ */
87993
+ const stripCommentsTransformer = () => {
87994
+ return (tree) => {
87995
+ visit(tree, ['html', 'mdxFlowExpression', 'mdxTextExpression'], (node, index, parent) => {
87996
+ if (parent && typeof index === 'number') {
87997
+ // Remove HTML comments
87998
+ if (node.type === 'html' && HTML_COMMENT_REGEX.test(node.value)) {
87999
+ const newValue = node.value.replace(HTML_COMMENT_REGEX, '').trim();
88000
+ if (newValue) {
88001
+ node.value = newValue;
88002
+ }
88003
+ else {
88004
+ parent.children.splice(index, 1);
88005
+ return [SKIP, index];
88006
+ }
88007
+ }
88008
+ // Remove MDX comments
88009
+ if ((node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') &&
88010
+ MDX_COMMENT_REGEX.test(node.value)) {
88011
+ const newValue = node.value.replace(MDX_COMMENT_REGEX, '').trim();
88012
+ if (newValue) {
88013
+ node.value = newValue;
88014
+ }
88015
+ else {
88016
+ parent.children.splice(index, 1);
88017
+ return [SKIP, index];
88018
+ }
88019
+ }
88020
+ }
88021
+ return undefined;
88022
+ });
88023
+ };
88024
+ };
88025
+
88026
+ ;// ./lib/stripComments.ts
88027
+
88028
+
88029
+
88030
+
88031
+
88032
+ /**
88033
+ * Removes Markdown and MDX comments.
88034
+ */
88035
+ async function stripComments(doc, { mdx } = {}) {
88036
+ const processor = unified()
88037
+ .use(remarkParse)
88038
+ .use(mdx ? remarkMdx : undefined)
88039
+ .use(stripCommentsTransformer)
88040
+ .use(remarkStringify);
88041
+ const file = await processor.process(doc);
88042
+ return String(file);
88043
+ }
88044
+ /* harmony default export */ const lib_stripComments = (stripComments);
88045
+
87985
88046
  ;// ./lib/index.ts
87986
88047
 
87987
88048
 
@@ -87995,6 +88056,7 @@ const tags = (doc) => {
87995
88056
 
87996
88057
 
87997
88058
 
88059
+
87998
88060
  ;// ./index.tsx
87999
88061
 
88000
88062
 
package/dist/main.node.js CHANGED
@@ -16389,6 +16389,7 @@ __webpack_require__.d(__webpack_exports__, {
16389
16389
  plain: () => (/* reexport */ lib_plain),
16390
16390
  remarkPlugins: () => (/* reexport */ remarkPlugins),
16391
16391
  run: () => (/* reexport */ lib_run),
16392
+ stripComments: () => (/* reexport */ lib_stripComments),
16392
16393
  tags: () => (/* reexport */ lib_tags),
16393
16394
  tailwindCompiler: () => (/* reexport */ tailwindCompiler),
16394
16395
  utils: () => (/* binding */ utils)
@@ -108193,6 +108194,66 @@ const tags = (doc) => {
108193
108194
  };
108194
108195
  /* harmony default export */ const lib_tags = (tags);
108195
108196
 
108197
+ ;// ./processor/transform/stripComments.ts
108198
+
108199
+ const HTML_COMMENT_REGEX = /<!--[\s\S]*?-->/g;
108200
+ const MDX_COMMENT_REGEX = /\/\*[\s\S]*?\*\//g;
108201
+ /**
108202
+ * A remark plugin to remove comments from Markdown and MDX.
108203
+ */
108204
+ const stripCommentsTransformer = () => {
108205
+ return (tree) => {
108206
+ visit(tree, ['html', 'mdxFlowExpression', 'mdxTextExpression'], (node, index, parent) => {
108207
+ if (parent && typeof index === 'number') {
108208
+ // Remove HTML comments
108209
+ if (node.type === 'html' && HTML_COMMENT_REGEX.test(node.value)) {
108210
+ const newValue = node.value.replace(HTML_COMMENT_REGEX, '').trim();
108211
+ if (newValue) {
108212
+ node.value = newValue;
108213
+ }
108214
+ else {
108215
+ parent.children.splice(index, 1);
108216
+ return [SKIP, index];
108217
+ }
108218
+ }
108219
+ // Remove MDX comments
108220
+ if ((node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') &&
108221
+ MDX_COMMENT_REGEX.test(node.value)) {
108222
+ const newValue = node.value.replace(MDX_COMMENT_REGEX, '').trim();
108223
+ if (newValue) {
108224
+ node.value = newValue;
108225
+ }
108226
+ else {
108227
+ parent.children.splice(index, 1);
108228
+ return [SKIP, index];
108229
+ }
108230
+ }
108231
+ }
108232
+ return undefined;
108233
+ });
108234
+ };
108235
+ };
108236
+
108237
+ ;// ./lib/stripComments.ts
108238
+
108239
+
108240
+
108241
+
108242
+
108243
+ /**
108244
+ * Removes Markdown and MDX comments.
108245
+ */
108246
+ async function stripComments(doc, { mdx } = {}) {
108247
+ const processor = unified()
108248
+ .use(remarkParse)
108249
+ .use(mdx ? remarkMdx : undefined)
108250
+ .use(stripCommentsTransformer)
108251
+ .use(remarkStringify);
108252
+ const file = await processor.process(doc);
108253
+ return String(file);
108254
+ }
108255
+ /* harmony default export */ const lib_stripComments = (stripComments);
108256
+
108196
108257
  ;// ./lib/index.ts
108197
108258
 
108198
108259
 
@@ -108206,6 +108267,7 @@ const tags = (doc) => {
108206
108267
 
108207
108268
 
108208
108269
 
108270
+
108209
108271
  ;// ./index.tsx
108210
108272
 
108211
108273