@readme/markdown 14.1.4 → 14.2.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.
@@ -2,8 +2,9 @@ import type { CompileOptions } from '@mdx-js/mdx';
2
2
  export type CompileOpts = CompileOptions & {
3
3
  components?: Record<string, string>;
4
4
  copyButtons?: boolean;
5
+ hardBreaks?: boolean;
5
6
  missingComponents?: 'ignore' | 'throw';
6
7
  useTailwind?: boolean;
7
8
  };
8
- declare const compile: (text: string, { components, missingComponents, copyButtons, useTailwind, ...opts }?: CompileOpts) => string;
9
+ declare const compile: (text: string, { components, missingComponents, copyButtons, useTailwind, hardBreaks, ...opts }?: CompileOpts) => string;
9
10
  export default compile;
package/dist/main.js CHANGED
@@ -53325,9 +53325,16 @@ function formatHtmlForMdxish(html) {
53325
53325
  }
53326
53326
  // Removes the leading/trailing newlines
53327
53327
  let cleaned = processed.replace(/^\s*\n|\n\s*$/g, '');
53328
- // Convert literal \n sequences to actual newlines BEFORE processing backticks
53329
- // This prevents the backtick unescaping regex from incorrectly matching \n sequences
53330
- cleaned = cleaned.replace(/\\n/g, '\n');
53328
+ // Convert literal \n sequences to actual newlines only inside <pre> and <code>.
53329
+ // Because <pre> needs to respect the newline visual and
53330
+ // escape characters should be processed in the <code> tag.
53331
+ //
53332
+ // We don't want to unescape every \n because it might break the HTML & cause errors
53333
+ // Example: <script>console.log("\n");</script>
53334
+ // Would get turned into: <script>console.log("
53335
+ // ");</script>
53336
+ // which is invalid javascript and will cause error
53337
+ cleaned = cleaned.replace(/(<(pre|code)\b[^>]*>)([\s\S]*?)(<\/\2>)/gi, (_m, open, _tag, inner, close) => open + inner.replace(/\\n/g, '\n') + close);
53331
53338
  // Unescape backticks: \` -> ` (users escape backticks in template literals)
53332
53339
  // Handle both cases: \` (adjacent) and \ followed by ` (split by markdown parser)
53333
53340
  cleaned = cleaned.replace(/\\`/g, '`');
@@ -84802,6 +84809,63 @@ function rehypeSanitize(options) {
84802
84809
  }
84803
84810
  }
84804
84811
 
84812
+ ;// ./node_modules/mdast-util-newline-to-break/lib/index.js
84813
+ /**
84814
+ * @typedef {import('mdast').Nodes} Nodes
84815
+ * @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
84816
+ */
84817
+
84818
+
84819
+
84820
+ /**
84821
+ * Turn normal line endings into hard breaks.
84822
+ *
84823
+ * @param {Nodes} tree
84824
+ * Tree to change.
84825
+ * @returns {undefined}
84826
+ * Nothing.
84827
+ */
84828
+ function newlineToBreak(tree) {
84829
+ findAndReplace(tree, [/\r?\n|\r/g, lib_replace])
84830
+ }
84831
+
84832
+ /**
84833
+ * Replace line endings.
84834
+ *
84835
+ * @type {ReplaceFunction}
84836
+ */
84837
+ function lib_replace() {
84838
+ return {type: 'break'}
84839
+ }
84840
+
84841
+ ;// ./node_modules/remark-breaks/lib/index.js
84842
+ /**
84843
+ * @typedef {import('mdast').Root} Root
84844
+ */
84845
+
84846
+
84847
+
84848
+ /**
84849
+ * Support hard breaks without needing spaces or escapes (turns enters into
84850
+ * `<br>`s).
84851
+ *
84852
+ * @returns
84853
+ * Transform.
84854
+ */
84855
+ function remarkBreaks() {
84856
+ /**
84857
+ * Transform.
84858
+ *
84859
+ * @param {Root} tree
84860
+ * Tree.
84861
+ * @returns {undefined}
84862
+ * Nothing.
84863
+ */
84864
+ return function (tree) {
84865
+ newlineToBreak(tree)
84866
+ }
84867
+ }
84868
+
84805
84869
  ;// ./errors/mdx-syntax-error.ts
84806
84870
  class MdxSyntaxError extends SyntaxError {
84807
84871
  original = null;
@@ -87607,6 +87671,7 @@ const tocHastToMdx = (toc, components, variables) => {
87607
87671
 
87608
87672
 
87609
87673
 
87674
+
87610
87675
  const sanitizeSchema = cjs_default()(defaultSchema, {
87611
87676
  attributes: {
87612
87677
  a: ['target'],
@@ -87615,12 +87680,13 @@ const sanitizeSchema = cjs_default()(defaultSchema, {
87615
87680
  href: ['doc', 'ref', 'blog', 'changelog', 'page'],
87616
87681
  },
87617
87682
  });
87618
- const compile_compile = (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
87683
+ const compile_compile = (text, { components = {}, missingComponents, copyButtons, useTailwind, hardBreaks, ...opts } = {}) => {
87619
87684
  // Destructure at runtime to avoid circular dependency issues
87620
87685
  const { codeTabsTransformer, ...transforms } = defaultTransforms;
87621
87686
  const remarkPlugins = [
87622
87687
  remarkFrontmatter,
87623
87688
  remarkGfm,
87689
+ ...(hardBreaks ? [remarkBreaks] : []),
87624
87690
  ...Object.values(transforms),
87625
87691
  [codeTabsTransformer, { copyButtons }],
87626
87692
  [
@@ -94026,63 +94092,6 @@ function rehypeStringify(options) {
94026
94092
  }
94027
94093
  }
94028
94094
 
94029
- ;// ./node_modules/mdast-util-newline-to-break/lib/index.js
94030
- /**
94031
- * @typedef {import('mdast').Nodes} Nodes
94032
- * @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
94033
- */
94034
-
94035
-
94036
-
94037
- /**
94038
- * Turn normal line endings into hard breaks.
94039
- *
94040
- * @param {Nodes} tree
94041
- * Tree to change.
94042
- * @returns {undefined}
94043
- * Nothing.
94044
- */
94045
- function newlineToBreak(tree) {
94046
- findAndReplace(tree, [/\r?\n|\r/g, lib_replace])
94047
- }
94048
-
94049
- /**
94050
- * Replace line endings.
94051
- *
94052
- * @type {ReplaceFunction}
94053
- */
94054
- function lib_replace() {
94055
- return {type: 'break'}
94056
- }
94057
-
94058
- ;// ./node_modules/remark-breaks/lib/index.js
94059
- /**
94060
- * @typedef {import('mdast').Root} Root
94061
- */
94062
-
94063
-
94064
-
94065
- /**
94066
- * Support hard breaks without needing spaces or escapes (turns enters into
94067
- * `<br>`s).
94068
- *
94069
- * @returns
94070
- * Transform.
94071
- */
94072
- function remarkBreaks() {
94073
- /**
94074
- * Transform.
94075
- *
94076
- * @param {Root} tree
94077
- * Tree.
94078
- * @returns {undefined}
94079
- * Nothing.
94080
- */
94081
- return function (tree) {
94082
- newlineToBreak(tree)
94083
- }
94084
- }
94085
-
94086
94095
  ;// ./processor/plugin/flatten-table-cell-paragraphs.ts
94087
94096
 
94088
94097
  /** List elements that cause margin issues when adjacent to paragraphs */
package/dist/main.node.js CHANGED
@@ -73519,9 +73519,16 @@ function formatHtmlForMdxish(html) {
73519
73519
  }
73520
73520
  // Removes the leading/trailing newlines
73521
73521
  let cleaned = processed.replace(/^\s*\n|\n\s*$/g, '');
73522
- // Convert literal \n sequences to actual newlines BEFORE processing backticks
73523
- // This prevents the backtick unescaping regex from incorrectly matching \n sequences
73524
- cleaned = cleaned.replace(/\\n/g, '\n');
73522
+ // Convert literal \n sequences to actual newlines only inside <pre> and <code>.
73523
+ // Because <pre> needs to respect the newline visual and
73524
+ // escape characters should be processed in the <code> tag.
73525
+ //
73526
+ // We don't want to unescape every \n because it might break the HTML & cause errors
73527
+ // Example: <script>console.log("\n");</script>
73528
+ // Would get turned into: <script>console.log("
73529
+ // ");</script>
73530
+ // which is invalid javascript and will cause error
73531
+ cleaned = cleaned.replace(/(<(pre|code)\b[^>]*>)([\s\S]*?)(<\/\2>)/gi, (_m, open, _tag, inner, close) => open + inner.replace(/\\n/g, '\n') + close);
73525
73532
  // Unescape backticks: \` -> ` (users escape backticks in template literals)
73526
73533
  // Handle both cases: \` (adjacent) and \ followed by ` (split by markdown parser)
73527
73534
  cleaned = cleaned.replace(/\\`/g, '`');
@@ -104996,6 +105003,63 @@ function rehypeSanitize(options) {
104996
105003
  }
104997
105004
  }
104998
105005
 
105006
+ ;// ./node_modules/mdast-util-newline-to-break/lib/index.js
105007
+ /**
105008
+ * @typedef {import('mdast').Nodes} Nodes
105009
+ * @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
105010
+ */
105011
+
105012
+
105013
+
105014
+ /**
105015
+ * Turn normal line endings into hard breaks.
105016
+ *
105017
+ * @param {Nodes} tree
105018
+ * Tree to change.
105019
+ * @returns {undefined}
105020
+ * Nothing.
105021
+ */
105022
+ function newlineToBreak(tree) {
105023
+ findAndReplace(tree, [/\r?\n|\r/g, lib_replace])
105024
+ }
105025
+
105026
+ /**
105027
+ * Replace line endings.
105028
+ *
105029
+ * @type {ReplaceFunction}
105030
+ */
105031
+ function lib_replace() {
105032
+ return {type: 'break'}
105033
+ }
105034
+
105035
+ ;// ./node_modules/remark-breaks/lib/index.js
105036
+ /**
105037
+ * @typedef {import('mdast').Root} Root
105038
+ */
105039
+
105040
+
105041
+
105042
+ /**
105043
+ * Support hard breaks without needing spaces or escapes (turns enters into
105044
+ * `<br>`s).
105045
+ *
105046
+ * @returns
105047
+ * Transform.
105048
+ */
105049
+ function remarkBreaks() {
105050
+ /**
105051
+ * Transform.
105052
+ *
105053
+ * @param {Root} tree
105054
+ * Tree.
105055
+ * @returns {undefined}
105056
+ * Nothing.
105057
+ */
105058
+ return function (tree) {
105059
+ newlineToBreak(tree)
105060
+ }
105061
+ }
105062
+
104999
105063
  ;// ./errors/mdx-syntax-error.ts
105000
105064
  class MdxSyntaxError extends SyntaxError {
105001
105065
  original = null;
@@ -107801,6 +107865,7 @@ const tocHastToMdx = (toc, components, variables) => {
107801
107865
 
107802
107866
 
107803
107867
 
107868
+
107804
107869
  const sanitizeSchema = cjs_default()(defaultSchema, {
107805
107870
  attributes: {
107806
107871
  a: ['target'],
@@ -107809,12 +107874,13 @@ const sanitizeSchema = cjs_default()(defaultSchema, {
107809
107874
  href: ['doc', 'ref', 'blog', 'changelog', 'page'],
107810
107875
  },
107811
107876
  });
107812
- const compile_compile = (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
107877
+ const compile_compile = (text, { components = {}, missingComponents, copyButtons, useTailwind, hardBreaks, ...opts } = {}) => {
107813
107878
  // Destructure at runtime to avoid circular dependency issues
107814
107879
  const { codeTabsTransformer, ...transforms } = defaultTransforms;
107815
107880
  const remarkPlugins = [
107816
107881
  remarkFrontmatter,
107817
107882
  remarkGfm,
107883
+ ...(hardBreaks ? [remarkBreaks] : []),
107818
107884
  ...Object.values(transforms),
107819
107885
  [codeTabsTransformer, { copyButtons }],
107820
107886
  [
@@ -114220,63 +114286,6 @@ function rehypeStringify(options) {
114220
114286
  }
114221
114287
  }
114222
114288
 
114223
- ;// ./node_modules/mdast-util-newline-to-break/lib/index.js
114224
- /**
114225
- * @typedef {import('mdast').Nodes} Nodes
114226
- * @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
114227
- */
114228
-
114229
-
114230
-
114231
- /**
114232
- * Turn normal line endings into hard breaks.
114233
- *
114234
- * @param {Nodes} tree
114235
- * Tree to change.
114236
- * @returns {undefined}
114237
- * Nothing.
114238
- */
114239
- function newlineToBreak(tree) {
114240
- findAndReplace(tree, [/\r?\n|\r/g, lib_replace])
114241
- }
114242
-
114243
- /**
114244
- * Replace line endings.
114245
- *
114246
- * @type {ReplaceFunction}
114247
- */
114248
- function lib_replace() {
114249
- return {type: 'break'}
114250
- }
114251
-
114252
- ;// ./node_modules/remark-breaks/lib/index.js
114253
- /**
114254
- * @typedef {import('mdast').Root} Root
114255
- */
114256
-
114257
-
114258
-
114259
- /**
114260
- * Support hard breaks without needing spaces or escapes (turns enters into
114261
- * `<br>`s).
114262
- *
114263
- * @returns
114264
- * Transform.
114265
- */
114266
- function remarkBreaks() {
114267
- /**
114268
- * Transform.
114269
- *
114270
- * @param {Root} tree
114271
- * Tree.
114272
- * @returns {undefined}
114273
- * Nothing.
114274
- */
114275
- return function (tree) {
114276
- newlineToBreak(tree)
114277
- }
114278
- }
114279
-
114280
114289
  ;// ./processor/plugin/flatten-table-cell-paragraphs.ts
114281
114290
 
114282
114291
  /** List elements that cause margin issues when adjacent to paragraphs */