@songtonyli/dsh-cli 0.1.95 → 0.1.97

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.
Files changed (68) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-agent-preset/skills/cordis-composition-reference/references/packages.md +1 -0
  4. package/node_modules/@deepseek-ai/dsh-client-modules/lib/index.js +1 -1
  5. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  6. package/node_modules/@deepseek-ai/dsh-cordis-client-runner/lib/client.js +0 -4
  7. package/node_modules/@deepseek-ai/dsh-ptc-runtime-node/README.i18n.yaml +2 -2
  8. package/node_modules/@deepseek-ai/dsh-ptc-runtime-node/README.md +1 -1
  9. package/node_modules/@deepseek-ai/dsh-ptc-runtime-node/README.zh.md +1 -1
  10. package/node_modules/@deepseek-ai/dsh-ptc-runtime-node/lib/index.js +41 -16
  11. package/node_modules/@deepseek-ai/dsh-sandbox/README.i18n.yaml +5 -2
  12. package/node_modules/@deepseek-ai/dsh-sandbox/README.md +4 -0
  13. package/node_modules/@deepseek-ai/dsh-sandbox/README.zh.md +4 -0
  14. package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +23 -3
  15. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +17 -14
  16. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +12 -6
  17. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +12 -6
  18. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/exec-shim.js +3 -1
  19. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +54 -9
  20. package/node_modules/@deepseek-ai/dsh-sandbox-local/README.i18n.yaml +2 -2
  21. package/node_modules/@deepseek-ai/dsh-sandbox-local/README.md +2 -0
  22. package/node_modules/@deepseek-ai/dsh-sandbox-local/README.zh.md +2 -0
  23. package/node_modules/@deepseek-ai/dsh-sandbox-local/lib/index.js +74 -18
  24. package/node_modules/@deepseek-ai/dsh-session-continuation/README.i18n.yaml +15 -6
  25. package/node_modules/@deepseek-ai/dsh-session-continuation/README.md +10 -2
  26. package/node_modules/@deepseek-ai/dsh-session-continuation/README.zh.md +11 -3
  27. package/node_modules/@deepseek-ai/dsh-session-continuation/lib/index.js +4 -1
  28. package/node_modules/@deepseek-ai/dsh-session-continuation/lib/types/index.js +5 -2
  29. package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +11 -1
  30. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +10 -10
  31. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +9 -3
  32. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +9 -3
  33. package/node_modules/@deepseek-ai/dsh-tui-app/cordis.patch.yml +0 -5
  34. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +38 -9
  35. package/node_modules/@swc/helpers/cjs/_ts_add_disposable_resource.cjs +41 -1
  36. package/node_modules/@swc/helpers/cjs/_ts_decorate.cjs +15 -1
  37. package/node_modules/@swc/helpers/cjs/_ts_dispose_resources.cjs +44 -1
  38. package/node_modules/@swc/helpers/cjs/_ts_metadata.cjs +7 -1
  39. package/node_modules/@swc/helpers/cjs/_ts_param.cjs +7 -1
  40. package/node_modules/@swc/helpers/cjs/_ts_rewrite_relative_import_extension.cjs +10 -1
  41. package/node_modules/@swc/helpers/cjs/_ts_values.cjs +19 -1
  42. package/node_modules/@swc/helpers/cjs/_unsupported_iterable_to_array.cjs +1 -1
  43. package/node_modules/@swc/helpers/cjs/index.cjs +0 -4
  44. package/node_modules/@swc/helpers/esm/_ts_add_disposable_resource.js +41 -1
  45. package/node_modules/@swc/helpers/esm/_ts_decorate.js +15 -1
  46. package/node_modules/@swc/helpers/esm/_ts_dispose_resources.js +44 -1
  47. package/node_modules/@swc/helpers/esm/_ts_metadata.js +7 -1
  48. package/node_modules/@swc/helpers/esm/_ts_param.js +7 -1
  49. package/node_modules/@swc/helpers/esm/_ts_rewrite_relative_import_extension.js +10 -1
  50. package/node_modules/@swc/helpers/esm/_ts_values.js +19 -1
  51. package/node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js +1 -1
  52. package/node_modules/@swc/helpers/esm/index.js +0 -1
  53. package/node_modules/@swc/helpers/package.json +2 -11
  54. package/node_modules/@swc/helpers/scripts/ast_grep.js +5 -25
  55. package/node_modules/@swc/helpers/scripts/build.js +2 -1
  56. package/node_modules/turndown/dist/turndown.js +18 -15
  57. package/node_modules/turndown/lib/turndown.browser.cjs.js +18 -15
  58. package/node_modules/turndown/lib/turndown.browser.es.js +18 -15
  59. package/node_modules/turndown/lib/turndown.browser.umd.js +18 -15
  60. package/node_modules/turndown/lib/turndown.cjs.js +18 -15
  61. package/node_modules/turndown/lib/turndown.es.js +18 -15
  62. package/node_modules/turndown/lib/turndown.umd.js +18 -15
  63. package/node_modules/turndown/package.json +4 -3
  64. package/package.json +3 -3
  65. package/node_modules/@swc/helpers/_/_jsx/package.json +0 -4
  66. package/node_modules/@swc/helpers/cjs/_jsx.cjs +0 -28
  67. package/node_modules/@swc/helpers/esm/_jsx.js +0 -26
  68. package/node_modules/@swc/helpers/src/_jsx.mjs +0 -1
@@ -23,7 +23,7 @@ function prepend(node, text) {
23
23
  }
24
24
 
25
25
  export function ast_grep() {
26
- const task_queue = [];
26
+ const write_tasks = [];
27
27
 
28
28
  const task = parseFiles([root("esm")], (err, tree) => {
29
29
  const filename = path.basename(tree.filename(), ".js");
@@ -36,25 +36,6 @@ export function ast_grep() {
36
36
 
37
37
  edits.push(prepend(root_node, `"use strict";\n\n`));
38
38
 
39
- // We have forked _ts_generator from tslib
40
- if (filename.startsWith("_ts") && filename !== "_ts_generator") {
41
- const match = root_node.find(`export { $NAME as _ } from "tslib"`);
42
- if (match) {
43
- const name = match.getMatch("NAME").text();
44
- edits.push(
45
- match.replace(`exports._ = require("tslib").${name};`),
46
- );
47
- task_queue.push(
48
- fs.writeFile(root("cjs", `${filename}.cjs`), root_node.commitEdits(edits), {
49
- encoding: "utf-8",
50
- }),
51
- );
52
- } else {
53
- report_noexport(tree.filename());
54
- }
55
- return;
56
- }
57
-
58
39
  // rewrite export named function
59
40
  const match = root_node.find({
60
41
  rule: {
@@ -129,16 +110,15 @@ export function ast_grep() {
129
110
  });
130
111
  });
131
112
 
132
- task_queue.push(
113
+ write_tasks.push(
133
114
  fs.writeFile(root("cjs", `${filename}.cjs`), root_node.commitEdits(edits), {
134
115
  encoding: "utf-8",
135
116
  }),
136
117
  );
137
- });
138
-
139
- task_queue.push(task);
118
+ })
119
+ .then(() => Promise.all(write_tasks));
140
120
 
141
- return task_queue;
121
+ return [task];
142
122
  }
143
123
 
144
124
  /**
@@ -125,7 +125,8 @@ if (errors.length > 0) {
125
125
  } else {
126
126
  $.cwd = root(".");
127
127
  await $`dprint fmt`;
128
- await $`dprint fmt "scripts/*.js" -c scripts/.dprint.json`;
128
+ $.cwd = root("scripts");
129
+ await $`dprint fmt -c .dprint.json`;
129
130
  }
130
131
 
131
132
  function re_export_esm(importBinding) {
@@ -714,8 +714,8 @@ var TurndownService = (function () {
714
714
  * Reduces a DOM node down to its Markdown string equivalent
715
715
  * @private
716
716
  * @param {HTMLElement} parentNode The node to convert
717
- * @returns A Markdown representation of the node
718
- * @type String
717
+ * @returns Accumulator with Markdown representation parts of the node
718
+ * @type Array
719
719
  */
720
720
 
721
721
  function process(parentNode) {
@@ -728,14 +728,15 @@ var TurndownService = (function () {
728
728
  } else if (node.nodeType === 1) {
729
729
  replacement = replacementForNode.call(self, node);
730
730
  }
731
- return join(output, replacement);
732
- }, '');
731
+ join(output, replacement);
732
+ return output;
733
+ }, []);
733
734
  }
734
735
 
735
736
  /**
736
737
  * Appends strings as each rule requires and trims the output
737
738
  * @private
738
- * @param {String} output The conversion output
739
+ * @param {Array} output The conversion output accumulator
739
740
  * @returns A trimmed version of the ouput
740
741
  * @type String
741
742
  */
@@ -744,10 +745,10 @@ var TurndownService = (function () {
744
745
  var self = this;
745
746
  this.rules.forEach(function (rule) {
746
747
  if (typeof rule.append === 'function') {
747
- output = join(output, rule.append(self.options));
748
+ join(output, rule.append(self.options));
748
749
  }
749
750
  });
750
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
751
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
751
752
  }
752
753
 
753
754
  /**
@@ -760,27 +761,29 @@ var TurndownService = (function () {
760
761
 
761
762
  function replacementForNode(node) {
762
763
  var rule = this.rules.forNode(node);
763
- var content = process.call(this, node);
764
+ var content = process.call(this, node).join('');
764
765
  var whitespace = node.flankingWhitespace;
765
766
  if (whitespace.leading || whitespace.trailing) content = content.trim();
766
767
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
767
768
  }
768
769
 
769
770
  /**
770
- * Joins replacement to the current output with appropriate number of new lines
771
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
772
+ * (makes sure the only trailing whitespace will be in the last array element)
771
773
  * @private
772
- * @param {String} output The current conversion output
774
+ * @param {String} output The current conversion output accumulator
773
775
  * @param {String} replacement The string to append to the output
774
- * @returns Joined output
775
- * @type String
776
776
  */
777
777
 
778
778
  function join(output, replacement) {
779
- var s1 = trimTrailingNewlines(output);
779
+ var tail = output.pop() || '';
780
+ var s1 = trimTrailingNewlines(tail);
780
781
  var s2 = trimLeadingNewlines(replacement);
781
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
782
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
782
783
  var separator = '\n\n'.substring(0, nls);
783
- return s1 + separator + s2;
784
+ if (s1) output.push(s1);
785
+ if (separator) output.push(separator);
786
+ if (s2) output.push(s2);
784
787
  }
785
788
 
786
789
  /**
@@ -713,8 +713,8 @@ TurndownService.prototype = {
713
713
  * Reduces a DOM node down to its Markdown string equivalent
714
714
  * @private
715
715
  * @param {HTMLElement} parentNode The node to convert
716
- * @returns A Markdown representation of the node
717
- * @type String
716
+ * @returns Accumulator with Markdown representation parts of the node
717
+ * @type Array
718
718
  */
719
719
 
720
720
  function process(parentNode) {
@@ -727,14 +727,15 @@ function process(parentNode) {
727
727
  } else if (node.nodeType === 1) {
728
728
  replacement = replacementForNode.call(self, node);
729
729
  }
730
- return join(output, replacement);
731
- }, '');
730
+ join(output, replacement);
731
+ return output;
732
+ }, []);
732
733
  }
733
734
 
734
735
  /**
735
736
  * Appends strings as each rule requires and trims the output
736
737
  * @private
737
- * @param {String} output The conversion output
738
+ * @param {Array} output The conversion output accumulator
738
739
  * @returns A trimmed version of the ouput
739
740
  * @type String
740
741
  */
@@ -743,10 +744,10 @@ function postProcess(output) {
743
744
  var self = this;
744
745
  this.rules.forEach(function (rule) {
745
746
  if (typeof rule.append === 'function') {
746
- output = join(output, rule.append(self.options));
747
+ join(output, rule.append(self.options));
747
748
  }
748
749
  });
749
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
750
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
750
751
  }
751
752
 
752
753
  /**
@@ -759,27 +760,29 @@ function postProcess(output) {
759
760
 
760
761
  function replacementForNode(node) {
761
762
  var rule = this.rules.forNode(node);
762
- var content = process.call(this, node);
763
+ var content = process.call(this, node).join('');
763
764
  var whitespace = node.flankingWhitespace;
764
765
  if (whitespace.leading || whitespace.trailing) content = content.trim();
765
766
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
766
767
  }
767
768
 
768
769
  /**
769
- * Joins replacement to the current output with appropriate number of new lines
770
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
771
+ * (makes sure the only trailing whitespace will be in the last array element)
770
772
  * @private
771
- * @param {String} output The current conversion output
773
+ * @param {String} output The current conversion output accumulator
772
774
  * @param {String} replacement The string to append to the output
773
- * @returns Joined output
774
- * @type String
775
775
  */
776
776
 
777
777
  function join(output, replacement) {
778
- var s1 = trimTrailingNewlines(output);
778
+ var tail = output.pop() || '';
779
+ var s1 = trimTrailingNewlines(tail);
779
780
  var s2 = trimLeadingNewlines(replacement);
780
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
781
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
781
782
  var separator = '\n\n'.substring(0, nls);
782
- return s1 + separator + s2;
783
+ if (s1) output.push(s1);
784
+ if (separator) output.push(separator);
785
+ if (s2) output.push(s2);
783
786
  }
784
787
 
785
788
  /**
@@ -711,8 +711,8 @@ TurndownService.prototype = {
711
711
  * Reduces a DOM node down to its Markdown string equivalent
712
712
  * @private
713
713
  * @param {HTMLElement} parentNode The node to convert
714
- * @returns A Markdown representation of the node
715
- * @type String
714
+ * @returns Accumulator with Markdown representation parts of the node
715
+ * @type Array
716
716
  */
717
717
 
718
718
  function process(parentNode) {
@@ -725,14 +725,15 @@ function process(parentNode) {
725
725
  } else if (node.nodeType === 1) {
726
726
  replacement = replacementForNode.call(self, node);
727
727
  }
728
- return join(output, replacement);
729
- }, '');
728
+ join(output, replacement);
729
+ return output;
730
+ }, []);
730
731
  }
731
732
 
732
733
  /**
733
734
  * Appends strings as each rule requires and trims the output
734
735
  * @private
735
- * @param {String} output The conversion output
736
+ * @param {Array} output The conversion output accumulator
736
737
  * @returns A trimmed version of the ouput
737
738
  * @type String
738
739
  */
@@ -741,10 +742,10 @@ function postProcess(output) {
741
742
  var self = this;
742
743
  this.rules.forEach(function (rule) {
743
744
  if (typeof rule.append === 'function') {
744
- output = join(output, rule.append(self.options));
745
+ join(output, rule.append(self.options));
745
746
  }
746
747
  });
747
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
748
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
748
749
  }
749
750
 
750
751
  /**
@@ -757,27 +758,29 @@ function postProcess(output) {
757
758
 
758
759
  function replacementForNode(node) {
759
760
  var rule = this.rules.forNode(node);
760
- var content = process.call(this, node);
761
+ var content = process.call(this, node).join('');
761
762
  var whitespace = node.flankingWhitespace;
762
763
  if (whitespace.leading || whitespace.trailing) content = content.trim();
763
764
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
764
765
  }
765
766
 
766
767
  /**
767
- * Joins replacement to the current output with appropriate number of new lines
768
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
769
+ * (makes sure the only trailing whitespace will be in the last array element)
768
770
  * @private
769
- * @param {String} output The current conversion output
771
+ * @param {String} output The current conversion output accumulator
770
772
  * @param {String} replacement The string to append to the output
771
- * @returns Joined output
772
- * @type String
773
773
  */
774
774
 
775
775
  function join(output, replacement) {
776
- var s1 = trimTrailingNewlines(output);
776
+ var tail = output.pop() || '';
777
+ var s1 = trimTrailingNewlines(tail);
777
778
  var s2 = trimLeadingNewlines(replacement);
778
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
779
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
779
780
  var separator = '\n\n'.substring(0, nls);
780
- return s1 + separator + s2;
781
+ if (s1) output.push(s1);
782
+ if (separator) output.push(separator);
783
+ if (s2) output.push(s2);
781
784
  }
782
785
 
783
786
  /**
@@ -717,8 +717,8 @@
717
717
  * Reduces a DOM node down to its Markdown string equivalent
718
718
  * @private
719
719
  * @param {HTMLElement} parentNode The node to convert
720
- * @returns A Markdown representation of the node
721
- * @type String
720
+ * @returns Accumulator with Markdown representation parts of the node
721
+ * @type Array
722
722
  */
723
723
 
724
724
  function process(parentNode) {
@@ -731,14 +731,15 @@
731
731
  } else if (node.nodeType === 1) {
732
732
  replacement = replacementForNode.call(self, node);
733
733
  }
734
- return join(output, replacement);
735
- }, '');
734
+ join(output, replacement);
735
+ return output;
736
+ }, []);
736
737
  }
737
738
 
738
739
  /**
739
740
  * Appends strings as each rule requires and trims the output
740
741
  * @private
741
- * @param {String} output The conversion output
742
+ * @param {Array} output The conversion output accumulator
742
743
  * @returns A trimmed version of the ouput
743
744
  * @type String
744
745
  */
@@ -747,10 +748,10 @@
747
748
  var self = this;
748
749
  this.rules.forEach(function (rule) {
749
750
  if (typeof rule.append === 'function') {
750
- output = join(output, rule.append(self.options));
751
+ join(output, rule.append(self.options));
751
752
  }
752
753
  });
753
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
754
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
754
755
  }
755
756
 
756
757
  /**
@@ -763,27 +764,29 @@
763
764
 
764
765
  function replacementForNode(node) {
765
766
  var rule = this.rules.forNode(node);
766
- var content = process.call(this, node);
767
+ var content = process.call(this, node).join('');
767
768
  var whitespace = node.flankingWhitespace;
768
769
  if (whitespace.leading || whitespace.trailing) content = content.trim();
769
770
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
770
771
  }
771
772
 
772
773
  /**
773
- * Joins replacement to the current output with appropriate number of new lines
774
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
775
+ * (makes sure the only trailing whitespace will be in the last array element)
774
776
  * @private
775
- * @param {String} output The current conversion output
777
+ * @param {String} output The current conversion output accumulator
776
778
  * @param {String} replacement The string to append to the output
777
- * @returns Joined output
778
- * @type String
779
779
  */
780
780
 
781
781
  function join(output, replacement) {
782
- var s1 = trimTrailingNewlines(output);
782
+ var tail = output.pop() || '';
783
+ var s1 = trimTrailingNewlines(tail);
783
784
  var s2 = trimLeadingNewlines(replacement);
784
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
785
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
785
786
  var separator = '\n\n'.substring(0, nls);
786
- return s1 + separator + s2;
787
+ if (s1) output.push(s1);
788
+ if (separator) output.push(separator);
789
+ if (s2) output.push(s2);
787
790
  }
788
791
 
789
792
  /**
@@ -690,8 +690,8 @@ TurndownService.prototype = {
690
690
  * Reduces a DOM node down to its Markdown string equivalent
691
691
  * @private
692
692
  * @param {HTMLElement} parentNode The node to convert
693
- * @returns A Markdown representation of the node
694
- * @type String
693
+ * @returns Accumulator with Markdown representation parts of the node
694
+ * @type Array
695
695
  */
696
696
 
697
697
  function process(parentNode) {
@@ -704,14 +704,15 @@ function process(parentNode) {
704
704
  } else if (node.nodeType === 1) {
705
705
  replacement = replacementForNode.call(self, node);
706
706
  }
707
- return join(output, replacement);
708
- }, '');
707
+ join(output, replacement);
708
+ return output;
709
+ }, []);
709
710
  }
710
711
 
711
712
  /**
712
713
  * Appends strings as each rule requires and trims the output
713
714
  * @private
714
- * @param {String} output The conversion output
715
+ * @param {Array} output The conversion output accumulator
715
716
  * @returns A trimmed version of the ouput
716
717
  * @type String
717
718
  */
@@ -720,10 +721,10 @@ function postProcess(output) {
720
721
  var self = this;
721
722
  this.rules.forEach(function (rule) {
722
723
  if (typeof rule.append === 'function') {
723
- output = join(output, rule.append(self.options));
724
+ join(output, rule.append(self.options));
724
725
  }
725
726
  });
726
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
727
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
727
728
  }
728
729
 
729
730
  /**
@@ -736,27 +737,29 @@ function postProcess(output) {
736
737
 
737
738
  function replacementForNode(node) {
738
739
  var rule = this.rules.forNode(node);
739
- var content = process.call(this, node);
740
+ var content = process.call(this, node).join('');
740
741
  var whitespace = node.flankingWhitespace;
741
742
  if (whitespace.leading || whitespace.trailing) content = content.trim();
742
743
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
743
744
  }
744
745
 
745
746
  /**
746
- * Joins replacement to the current output with appropriate number of new lines
747
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
748
+ * (makes sure the only trailing whitespace will be in the last array element)
747
749
  * @private
748
- * @param {String} output The current conversion output
750
+ * @param {String} output The current conversion output accumulator
749
751
  * @param {String} replacement The string to append to the output
750
- * @returns Joined output
751
- * @type String
752
752
  */
753
753
 
754
754
  function join(output, replacement) {
755
- var s1 = trimTrailingNewlines(output);
755
+ var tail = output.pop() || '';
756
+ var s1 = trimTrailingNewlines(tail);
756
757
  var s2 = trimLeadingNewlines(replacement);
757
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
758
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
758
759
  var separator = '\n\n'.substring(0, nls);
759
- return s1 + separator + s2;
760
+ if (s1) output.push(s1);
761
+ if (separator) output.push(separator);
762
+ if (s2) output.push(s2);
760
763
  }
761
764
 
762
765
  /**
@@ -688,8 +688,8 @@ TurndownService.prototype = {
688
688
  * Reduces a DOM node down to its Markdown string equivalent
689
689
  * @private
690
690
  * @param {HTMLElement} parentNode The node to convert
691
- * @returns A Markdown representation of the node
692
- * @type String
691
+ * @returns Accumulator with Markdown representation parts of the node
692
+ * @type Array
693
693
  */
694
694
 
695
695
  function process(parentNode) {
@@ -702,14 +702,15 @@ function process(parentNode) {
702
702
  } else if (node.nodeType === 1) {
703
703
  replacement = replacementForNode.call(self, node);
704
704
  }
705
- return join(output, replacement);
706
- }, '');
705
+ join(output, replacement);
706
+ return output;
707
+ }, []);
707
708
  }
708
709
 
709
710
  /**
710
711
  * Appends strings as each rule requires and trims the output
711
712
  * @private
712
- * @param {String} output The conversion output
713
+ * @param {Array} output The conversion output accumulator
713
714
  * @returns A trimmed version of the ouput
714
715
  * @type String
715
716
  */
@@ -718,10 +719,10 @@ function postProcess(output) {
718
719
  var self = this;
719
720
  this.rules.forEach(function (rule) {
720
721
  if (typeof rule.append === 'function') {
721
- output = join(output, rule.append(self.options));
722
+ join(output, rule.append(self.options));
722
723
  }
723
724
  });
724
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
725
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
725
726
  }
726
727
 
727
728
  /**
@@ -734,27 +735,29 @@ function postProcess(output) {
734
735
 
735
736
  function replacementForNode(node) {
736
737
  var rule = this.rules.forNode(node);
737
- var content = process.call(this, node);
738
+ var content = process.call(this, node).join('');
738
739
  var whitespace = node.flankingWhitespace;
739
740
  if (whitespace.leading || whitespace.trailing) content = content.trim();
740
741
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
741
742
  }
742
743
 
743
744
  /**
744
- * Joins replacement to the current output with appropriate number of new lines
745
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
746
+ * (makes sure the only trailing whitespace will be in the last array element)
745
747
  * @private
746
- * @param {String} output The current conversion output
748
+ * @param {String} output The current conversion output accumulator
747
749
  * @param {String} replacement The string to append to the output
748
- * @returns Joined output
749
- * @type String
750
750
  */
751
751
 
752
752
  function join(output, replacement) {
753
- var s1 = trimTrailingNewlines(output);
753
+ var tail = output.pop() || '';
754
+ var s1 = trimTrailingNewlines(tail);
754
755
  var s2 = trimLeadingNewlines(replacement);
755
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
756
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
756
757
  var separator = '\n\n'.substring(0, nls);
757
- return s1 + separator + s2;
758
+ if (s1) output.push(s1);
759
+ if (separator) output.push(separator);
760
+ if (s2) output.push(s2);
758
761
  }
759
762
 
760
763
  /**
@@ -694,8 +694,8 @@
694
694
  * Reduces a DOM node down to its Markdown string equivalent
695
695
  * @private
696
696
  * @param {HTMLElement} parentNode The node to convert
697
- * @returns A Markdown representation of the node
698
- * @type String
697
+ * @returns Accumulator with Markdown representation parts of the node
698
+ * @type Array
699
699
  */
700
700
 
701
701
  function process(parentNode) {
@@ -708,14 +708,15 @@
708
708
  } else if (node.nodeType === 1) {
709
709
  replacement = replacementForNode.call(self, node);
710
710
  }
711
- return join(output, replacement);
712
- }, '');
711
+ join(output, replacement);
712
+ return output;
713
+ }, []);
713
714
  }
714
715
 
715
716
  /**
716
717
  * Appends strings as each rule requires and trims the output
717
718
  * @private
718
- * @param {String} output The conversion output
719
+ * @param {Array} output The conversion output accumulator
719
720
  * @returns A trimmed version of the ouput
720
721
  * @type String
721
722
  */
@@ -724,10 +725,10 @@
724
725
  var self = this;
725
726
  this.rules.forEach(function (rule) {
726
727
  if (typeof rule.append === 'function') {
727
- output = join(output, rule.append(self.options));
728
+ join(output, rule.append(self.options));
728
729
  }
729
730
  });
730
- return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
731
+ return output.join('').replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '');
731
732
  }
732
733
 
733
734
  /**
@@ -740,27 +741,29 @@
740
741
 
741
742
  function replacementForNode(node) {
742
743
  var rule = this.rules.forNode(node);
743
- var content = process.call(this, node);
744
+ var content = process.call(this, node).join('');
744
745
  var whitespace = node.flankingWhitespace;
745
746
  if (whitespace.leading || whitespace.trailing) content = content.trim();
746
747
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
747
748
  }
748
749
 
749
750
  /**
750
- * Joins replacement to the current output with appropriate number of new lines
751
+ * Joins replacement with the current output accumulator using the appropriate number of new lines
752
+ * (makes sure the only trailing whitespace will be in the last array element)
751
753
  * @private
752
- * @param {String} output The current conversion output
754
+ * @param {String} output The current conversion output accumulator
753
755
  * @param {String} replacement The string to append to the output
754
- * @returns Joined output
755
- * @type String
756
756
  */
757
757
 
758
758
  function join(output, replacement) {
759
- var s1 = trimTrailingNewlines(output);
759
+ var tail = output.pop() || '';
760
+ var s1 = trimTrailingNewlines(tail);
760
761
  var s2 = trimLeadingNewlines(replacement);
761
- var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
762
+ var nls = Math.max(tail.length - s1.length, replacement.length - s2.length);
762
763
  var separator = '\n\n'.substring(0, nls);
763
- return s1 + separator + s2;
764
+ if (s1) output.push(s1);
765
+ if (separator) output.push(separator);
766
+ if (s2) output.push(s2);
764
767
  }
765
768
 
766
769
  /**
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "turndown",
3
3
  "description": "A library that converts HTML to Markdown",
4
- "version": "7.2.4",
4
+ "version": "7.2.5",
5
5
  "author": "Dom Christie",
6
6
  "main": "lib/turndown.cjs.js",
7
7
  "module": "lib/turndown.es.js",
@@ -23,10 +23,11 @@
23
23
  "@rollup/plugin-commonjs": "^29.0.0",
24
24
  "@rollup/plugin-node-resolve": "^16.0.3",
25
25
  "@rollup/plugin-replace": "^6.0.3",
26
- "rewire": "^6.0.0",
26
+ "rewire": "^9.0.1",
27
27
  "rollup": "^4.59.0",
28
28
  "standard": "^17.0.0",
29
- "turndown-attendant": "0.0.3"
29
+ "turndown-attendant": "0.0.3",
30
+ "turndown-baseline": "npm:turndown@7.2.4"
30
31
  },
31
32
  "engines": {
32
33
  "node": ">=18",