@songtonyli/dsh-cli 0.1.95 → 0.1.96

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 (50) 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-session-continuation/README.i18n.yaml +15 -6
  8. package/node_modules/@deepseek-ai/dsh-session-continuation/README.md +10 -2
  9. package/node_modules/@deepseek-ai/dsh-session-continuation/README.zh.md +11 -3
  10. package/node_modules/@deepseek-ai/dsh-session-continuation/lib/index.js +4 -1
  11. package/node_modules/@deepseek-ai/dsh-session-continuation/lib/types/index.js +5 -2
  12. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +8 -8
  13. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +6 -2
  14. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +6 -2
  15. package/node_modules/@deepseek-ai/dsh-tui-app/cordis.patch.yml +0 -5
  16. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +18 -4
  17. package/node_modules/@swc/helpers/cjs/_ts_add_disposable_resource.cjs +41 -1
  18. package/node_modules/@swc/helpers/cjs/_ts_decorate.cjs +15 -1
  19. package/node_modules/@swc/helpers/cjs/_ts_dispose_resources.cjs +44 -1
  20. package/node_modules/@swc/helpers/cjs/_ts_metadata.cjs +7 -1
  21. package/node_modules/@swc/helpers/cjs/_ts_param.cjs +7 -1
  22. package/node_modules/@swc/helpers/cjs/_ts_rewrite_relative_import_extension.cjs +10 -1
  23. package/node_modules/@swc/helpers/cjs/_ts_values.cjs +19 -1
  24. package/node_modules/@swc/helpers/cjs/_unsupported_iterable_to_array.cjs +1 -1
  25. package/node_modules/@swc/helpers/cjs/index.cjs +0 -4
  26. package/node_modules/@swc/helpers/esm/_ts_add_disposable_resource.js +41 -1
  27. package/node_modules/@swc/helpers/esm/_ts_decorate.js +15 -1
  28. package/node_modules/@swc/helpers/esm/_ts_dispose_resources.js +44 -1
  29. package/node_modules/@swc/helpers/esm/_ts_metadata.js +7 -1
  30. package/node_modules/@swc/helpers/esm/_ts_param.js +7 -1
  31. package/node_modules/@swc/helpers/esm/_ts_rewrite_relative_import_extension.js +10 -1
  32. package/node_modules/@swc/helpers/esm/_ts_values.js +19 -1
  33. package/node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js +1 -1
  34. package/node_modules/@swc/helpers/esm/index.js +0 -1
  35. package/node_modules/@swc/helpers/package.json +2 -11
  36. package/node_modules/@swc/helpers/scripts/ast_grep.js +5 -25
  37. package/node_modules/@swc/helpers/scripts/build.js +2 -1
  38. package/node_modules/turndown/dist/turndown.js +18 -15
  39. package/node_modules/turndown/lib/turndown.browser.cjs.js +18 -15
  40. package/node_modules/turndown/lib/turndown.browser.es.js +18 -15
  41. package/node_modules/turndown/lib/turndown.browser.umd.js +18 -15
  42. package/node_modules/turndown/lib/turndown.cjs.js +18 -15
  43. package/node_modules/turndown/lib/turndown.es.js +18 -15
  44. package/node_modules/turndown/lib/turndown.umd.js +18 -15
  45. package/node_modules/turndown/package.json +4 -3
  46. package/package.json +3 -3
  47. package/node_modules/@swc/helpers/_/_jsx/package.json +0 -4
  48. package/node_modules/@swc/helpers/cjs/_jsx.cjs +0 -28
  49. package/node_modules/@swc/helpers/esm/_jsx.js +0 -26
  50. package/node_modules/@swc/helpers/src/_jsx.mjs +0 -1
@@ -70,7 +70,6 @@
70
70
  _iterable_to_array: null,
71
71
  _iterable_to_array_limit: null,
72
72
  _iterable_to_array_limit_loose: null,
73
- _jsx: null,
74
73
  _new_arrow_check: null,
75
74
  _non_iterable_rest: null,
76
75
  _non_iterable_spread: null,
@@ -310,9 +309,6 @@ module.exports = {
310
309
  get _iterable_to_array_limit_loose() {
311
310
  return require("./_iterable_to_array_limit_loose.cjs")._;
312
311
  },
313
- get _jsx() {
314
- return require("./_jsx.cjs")._;
315
- },
316
312
  get _new_arrow_check() {
317
313
  return require("./_new_arrow_check.cjs")._;
318
314
  },
@@ -1 +1,41 @@
1
- export { __addDisposableResource as _ } from "tslib";
1
+ function _ts_add_disposable_resource(env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") {
4
+ throw new TypeError("Object expected.");
5
+ }
6
+ var dispose, inner;
7
+ if (async) {
8
+ if (!Symbol.asyncDispose) {
9
+ throw new TypeError("Symbol.asyncDispose is not defined.");
10
+ }
11
+ dispose = value[Symbol.asyncDispose];
12
+ }
13
+ if (dispose === void 0) {
14
+ if (!Symbol.dispose) {
15
+ throw new TypeError("Symbol.dispose is not defined.");
16
+ }
17
+ dispose = value[Symbol.dispose];
18
+ if (async) {
19
+ inner = dispose;
20
+ }
21
+ }
22
+ if (typeof dispose !== "function") {
23
+ throw new TypeError("Object not disposable.");
24
+ }
25
+ if (inner) {
26
+ dispose = function() {
27
+ try {
28
+ inner.call(this);
29
+ } catch (e) {
30
+ return Promise.reject(e);
31
+ }
32
+ };
33
+ }
34
+ env.stack.push({ value: value, dispose: dispose, async: async });
35
+ } else if (async) {
36
+ env.stack.push({ async: true });
37
+ }
38
+ return value;
39
+ }
40
+
41
+ export { _ts_add_disposable_resource as _ };
@@ -1 +1,15 @@
1
- export { __decorate as _ } from "tslib";
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4
+ r = Reflect.decorate(decorators, target, key, desc);
5
+ } else {
6
+ for (var i = decorators.length - 1; i >= 0; i--) {
7
+ if (d = decorators[i]) {
8
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
9
+ }
10
+ }
11
+ }
12
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
13
+ }
14
+
15
+ export { _ts_decorate as _ };
@@ -1 +1,44 @@
1
- export { __disposeResources as _ } from "tslib";
1
+ var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
2
+ var e = new Error(message);
3
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4
+ };
5
+
6
+ function _ts_dispose_resources(env) {
7
+ function fail(e) {
8
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
9
+ env.hasError = true;
10
+ }
11
+ var r, s = 0;
12
+ function next() {
13
+ while (r = env.stack.pop()) {
14
+ try {
15
+ if (!r.async && s === 1) {
16
+ return s = 0, env.stack.push(r), Promise.resolve().then(next);
17
+ }
18
+ if (r.dispose) {
19
+ var result = r.dispose.call(r.value);
20
+ if (r.async) {
21
+ return s |= 2,
22
+ Promise.resolve(result).then(next, function(e) {
23
+ fail(e);
24
+ return next();
25
+ });
26
+ }
27
+ } else {
28
+ s |= 1;
29
+ }
30
+ } catch (e) {
31
+ fail(e);
32
+ }
33
+ }
34
+ if (s === 1) {
35
+ return env.hasError ? Promise.reject(env.error) : Promise.resolve();
36
+ }
37
+ if (env.hasError) {
38
+ throw env.error;
39
+ }
40
+ }
41
+ return next();
42
+ }
43
+
44
+ export { _ts_dispose_resources as _ };
@@ -1 +1,7 @@
1
- export { __metadata as _ } from "tslib";
1
+ function _ts_metadata(metadataKey, metadataValue) {
2
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3
+ return Reflect.metadata(metadataKey, metadataValue);
4
+ }
5
+ }
6
+
7
+ export { _ts_metadata as _ };
@@ -1 +1,7 @@
1
- export { __param as _ } from "tslib";
1
+ function _ts_param(paramIndex, decorator) {
2
+ return function(target, key) {
3
+ decorator(target, key, paramIndex);
4
+ };
5
+ }
6
+
7
+ export { _ts_param as _ };
@@ -1 +1,10 @@
1
- export { __rewriteRelativeImportExtension as _ } from "tslib";
1
+ function _ts_rewrite_relative_import_extension(path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
5
+ });
6
+ }
7
+ return path;
8
+ }
9
+
10
+ export { _ts_rewrite_relative_import_extension as _ };
@@ -1 +1,19 @@
1
- export { __values as _ } from "tslib";
1
+ function _ts_values(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) {
4
+ return m.call(o);
5
+ }
6
+ if (o && typeof o.length === "number") {
7
+ return {
8
+ next: function() {
9
+ if (o && i >= o.length) {
10
+ o = void 0;
11
+ }
12
+ return { value: o && o[i++], done: !o };
13
+ }
14
+ };
15
+ }
16
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
17
+ }
18
+
19
+ export { _ts_values as _ };
@@ -7,7 +7,7 @@ function _unsupported_iterable_to_array(o, minLen) {
7
7
  var n = Object.prototype.toString.call(o).slice(8, -1);
8
8
 
9
9
  if (n === "Object" && o.constructor) n = o.constructor.name;
10
- if (n === "Map" || n === "Set") return Array.from(n);
10
+ if (n === "Map" || n === "Set") return Array.from(o);
11
11
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
12
12
  }
13
13
  export { _unsupported_iterable_to_array as _ };
@@ -66,7 +66,6 @@ export { _ as _is_native_reflect_construct } from "./_is_native_reflect_construc
66
66
  export { _ as _iterable_to_array } from "./_iterable_to_array.js";
67
67
  export { _ as _iterable_to_array_limit } from "./_iterable_to_array_limit.js";
68
68
  export { _ as _iterable_to_array_limit_loose } from "./_iterable_to_array_limit_loose.js";
69
- export { _ as _jsx } from "./_jsx.js";
70
69
  export { _ as _new_arrow_check } from "./_new_arrow_check.js";
71
70
  export { _ as _non_iterable_rest } from "./_non_iterable_rest.js";
72
71
  export { _ as _non_iterable_spread } from "./_non_iterable_spread.js";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swc/helpers",
3
- "version": "0.5.23",
3
+ "version": "0.5.24",
4
4
  "description": "External helpers for the swc project.",
5
5
  "module": "esm/index.js",
6
6
  "main": "cjs/index.cjs",
@@ -28,10 +28,7 @@
28
28
  "devDependencies": {
29
29
  "@ast-grep/napi": "^0.40.3",
30
30
  "dprint": "^0.35.3",
31
- "zx": "^7.2.1"
32
- },
33
- "dependencies": {
34
- "tslib": "^2.8.0"
31
+ "zx": "^8.0.0"
35
32
  },
36
33
  "exports": {
37
34
  "./package.json": "./package.json",
@@ -440,12 +437,6 @@
440
437
  "import": "./esm/_iterable_to_array_limit_loose.js",
441
438
  "default": "./cjs/_iterable_to_array_limit_loose.cjs"
442
439
  },
443
- "./_/_jsx": {
444
- "module-sync": "./esm/_jsx.js",
445
- "webpack": "./esm/_jsx.js",
446
- "import": "./esm/_jsx.js",
447
- "default": "./cjs/_jsx.cjs"
448
- },
449
440
  "./_/_new_arrow_check": {
450
441
  "module-sync": "./esm/_new_arrow_check.js",
451
442
  "webpack": "./esm/_new_arrow_check.js",
@@ -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
  /**