turndown 7.2.0 → 7.2.2

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/turndown.js CHANGED
@@ -26,6 +26,10 @@ var TurndownService = (function () {
26
26
  return string.substring(0, indexEnd)
27
27
  }
28
28
 
29
+ function trimNewlines (string) {
30
+ return trimTrailingNewlines(trimLeadingNewlines(string))
31
+ }
32
+
29
33
  var blockElements = [
30
34
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
31
35
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -117,8 +121,7 @@ var TurndownService = (function () {
117
121
  filter: 'blockquote',
118
122
 
119
123
  replacement: function (content) {
120
- content = content.replace(/^\n+|\n+$/g, '');
121
- content = content.replace(/^/gm, '> ');
124
+ content = trimNewlines(content).replace(/^/gm, '> ');
122
125
  return '\n\n' + content + '\n\n'
123
126
  }
124
127
  };
@@ -140,10 +143,6 @@ var TurndownService = (function () {
140
143
  filter: 'li',
141
144
 
142
145
  replacement: function (content, node, options) {
143
- content = content
144
- .replace(/^\n+/, '') // remove leading newlines
145
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
146
- .replace(/\n/gm, '\n '); // indent
147
146
  var prefix = options.bulletListMarker + ' ';
148
147
  var parent = node.parentNode;
149
148
  if (parent.nodeName === 'OL') {
@@ -151,8 +150,11 @@ var TurndownService = (function () {
151
150
  var index = Array.prototype.indexOf.call(parent.children, node);
152
151
  prefix = (start ? Number(start) + index : index + 1) + '. ';
153
152
  }
153
+ var isParagraph = /\n$/.test(content);
154
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
155
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
154
156
  return (
155
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
157
+ prefix + content + (node.nextSibling ? '\n' : '')
156
158
  )
157
159
  }
158
160
  };
@@ -25,6 +25,10 @@ function trimTrailingNewlines (string) {
25
25
  return string.substring(0, indexEnd)
26
26
  }
27
27
 
28
+ function trimNewlines (string) {
29
+ return trimTrailingNewlines(trimLeadingNewlines(string))
30
+ }
31
+
28
32
  var blockElements = [
29
33
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
30
34
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -116,8 +120,7 @@ rules.blockquote = {
116
120
  filter: 'blockquote',
117
121
 
118
122
  replacement: function (content) {
119
- content = content.replace(/^\n+|\n+$/g, '');
120
- content = content.replace(/^/gm, '> ');
123
+ content = trimNewlines(content).replace(/^/gm, '> ');
121
124
  return '\n\n' + content + '\n\n'
122
125
  }
123
126
  };
@@ -139,10 +142,6 @@ rules.listItem = {
139
142
  filter: 'li',
140
143
 
141
144
  replacement: function (content, node, options) {
142
- content = content
143
- .replace(/^\n+/, '') // remove leading newlines
144
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
145
- .replace(/\n/gm, '\n '); // indent
146
145
  var prefix = options.bulletListMarker + ' ';
147
146
  var parent = node.parentNode;
148
147
  if (parent.nodeName === 'OL') {
@@ -150,8 +149,11 @@ rules.listItem = {
150
149
  var index = Array.prototype.indexOf.call(parent.children, node);
151
150
  prefix = (start ? Number(start) + index : index + 1) + '. ';
152
151
  }
152
+ var isParagraph = /\n$/.test(content);
153
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
154
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
153
155
  return (
154
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
156
+ prefix + content + (node.nextSibling ? '\n' : '')
155
157
  )
156
158
  }
157
159
  };
@@ -23,6 +23,10 @@ function trimTrailingNewlines (string) {
23
23
  return string.substring(0, indexEnd)
24
24
  }
25
25
 
26
+ function trimNewlines (string) {
27
+ return trimTrailingNewlines(trimLeadingNewlines(string))
28
+ }
29
+
26
30
  var blockElements = [
27
31
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
28
32
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -114,8 +118,7 @@ rules.blockquote = {
114
118
  filter: 'blockquote',
115
119
 
116
120
  replacement: function (content) {
117
- content = content.replace(/^\n+|\n+$/g, '');
118
- content = content.replace(/^/gm, '> ');
121
+ content = trimNewlines(content).replace(/^/gm, '> ');
119
122
  return '\n\n' + content + '\n\n'
120
123
  }
121
124
  };
@@ -137,10 +140,6 @@ rules.listItem = {
137
140
  filter: 'li',
138
141
 
139
142
  replacement: function (content, node, options) {
140
- content = content
141
- .replace(/^\n+/, '') // remove leading newlines
142
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
143
- .replace(/\n/gm, '\n '); // indent
144
143
  var prefix = options.bulletListMarker + ' ';
145
144
  var parent = node.parentNode;
146
145
  if (parent.nodeName === 'OL') {
@@ -148,8 +147,11 @@ rules.listItem = {
148
147
  var index = Array.prototype.indexOf.call(parent.children, node);
149
148
  prefix = (start ? Number(start) + index : index + 1) + '. ';
150
149
  }
150
+ var isParagraph = /\n$/.test(content);
151
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
152
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
151
153
  return (
152
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
154
+ prefix + content + (node.nextSibling ? '\n' : '')
153
155
  )
154
156
  }
155
157
  };
@@ -29,6 +29,10 @@
29
29
  return string.substring(0, indexEnd)
30
30
  }
31
31
 
32
+ function trimNewlines (string) {
33
+ return trimTrailingNewlines(trimLeadingNewlines(string))
34
+ }
35
+
32
36
  var blockElements = [
33
37
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
34
38
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -120,8 +124,7 @@
120
124
  filter: 'blockquote',
121
125
 
122
126
  replacement: function (content) {
123
- content = content.replace(/^\n+|\n+$/g, '');
124
- content = content.replace(/^/gm, '> ');
127
+ content = trimNewlines(content).replace(/^/gm, '> ');
125
128
  return '\n\n' + content + '\n\n'
126
129
  }
127
130
  };
@@ -143,10 +146,6 @@
143
146
  filter: 'li',
144
147
 
145
148
  replacement: function (content, node, options) {
146
- content = content
147
- .replace(/^\n+/, '') // remove leading newlines
148
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
149
- .replace(/\n/gm, '\n '); // indent
150
149
  var prefix = options.bulletListMarker + ' ';
151
150
  var parent = node.parentNode;
152
151
  if (parent.nodeName === 'OL') {
@@ -154,8 +153,11 @@
154
153
  var index = Array.prototype.indexOf.call(parent.children, node);
155
154
  prefix = (start ? Number(start) + index : index + 1) + '. ';
156
155
  }
156
+ var isParagraph = /\n$/.test(content);
157
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
158
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
157
159
  return (
158
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
160
+ prefix + content + (node.nextSibling ? '\n' : '')
159
161
  )
160
162
  }
161
163
  };
@@ -25,6 +25,10 @@ function trimTrailingNewlines (string) {
25
25
  return string.substring(0, indexEnd)
26
26
  }
27
27
 
28
+ function trimNewlines (string) {
29
+ return trimTrailingNewlines(trimLeadingNewlines(string))
30
+ }
31
+
28
32
  var blockElements = [
29
33
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
30
34
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -116,8 +120,7 @@ rules.blockquote = {
116
120
  filter: 'blockquote',
117
121
 
118
122
  replacement: function (content) {
119
- content = content.replace(/^\n+|\n+$/g, '');
120
- content = content.replace(/^/gm, '> ');
123
+ content = trimNewlines(content).replace(/^/gm, '> ');
121
124
  return '\n\n' + content + '\n\n'
122
125
  }
123
126
  };
@@ -139,10 +142,6 @@ rules.listItem = {
139
142
  filter: 'li',
140
143
 
141
144
  replacement: function (content, node, options) {
142
- content = content
143
- .replace(/^\n+/, '') // remove leading newlines
144
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
145
- .replace(/\n/gm, '\n '); // indent
146
145
  var prefix = options.bulletListMarker + ' ';
147
146
  var parent = node.parentNode;
148
147
  if (parent.nodeName === 'OL') {
@@ -150,8 +149,11 @@ rules.listItem = {
150
149
  var index = Array.prototype.indexOf.call(parent.children, node);
151
150
  prefix = (start ? Number(start) + index : index + 1) + '. ';
152
151
  }
152
+ var isParagraph = /\n$/.test(content);
153
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
154
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
153
155
  return (
154
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
156
+ prefix + content + (node.nextSibling ? '\n' : '')
155
157
  )
156
158
  }
157
159
  };
@@ -23,6 +23,10 @@ function trimTrailingNewlines (string) {
23
23
  return string.substring(0, indexEnd)
24
24
  }
25
25
 
26
+ function trimNewlines (string) {
27
+ return trimTrailingNewlines(trimLeadingNewlines(string))
28
+ }
29
+
26
30
  var blockElements = [
27
31
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
28
32
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -114,8 +118,7 @@ rules.blockquote = {
114
118
  filter: 'blockquote',
115
119
 
116
120
  replacement: function (content) {
117
- content = content.replace(/^\n+|\n+$/g, '');
118
- content = content.replace(/^/gm, '> ');
121
+ content = trimNewlines(content).replace(/^/gm, '> ');
119
122
  return '\n\n' + content + '\n\n'
120
123
  }
121
124
  };
@@ -137,10 +140,6 @@ rules.listItem = {
137
140
  filter: 'li',
138
141
 
139
142
  replacement: function (content, node, options) {
140
- content = content
141
- .replace(/^\n+/, '') // remove leading newlines
142
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
143
- .replace(/\n/gm, '\n '); // indent
144
143
  var prefix = options.bulletListMarker + ' ';
145
144
  var parent = node.parentNode;
146
145
  if (parent.nodeName === 'OL') {
@@ -148,8 +147,11 @@ rules.listItem = {
148
147
  var index = Array.prototype.indexOf.call(parent.children, node);
149
148
  prefix = (start ? Number(start) + index : index + 1) + '. ';
150
149
  }
150
+ var isParagraph = /\n$/.test(content);
151
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
152
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
151
153
  return (
152
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
154
+ prefix + content + (node.nextSibling ? '\n' : '')
153
155
  )
154
156
  }
155
157
  };
@@ -29,6 +29,10 @@
29
29
  return string.substring(0, indexEnd)
30
30
  }
31
31
 
32
+ function trimNewlines (string) {
33
+ return trimTrailingNewlines(trimLeadingNewlines(string))
34
+ }
35
+
32
36
  var blockElements = [
33
37
  'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
34
38
  'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
@@ -120,8 +124,7 @@
120
124
  filter: 'blockquote',
121
125
 
122
126
  replacement: function (content) {
123
- content = content.replace(/^\n+|\n+$/g, '');
124
- content = content.replace(/^/gm, '> ');
127
+ content = trimNewlines(content).replace(/^/gm, '> ');
125
128
  return '\n\n' + content + '\n\n'
126
129
  }
127
130
  };
@@ -143,10 +146,6 @@
143
146
  filter: 'li',
144
147
 
145
148
  replacement: function (content, node, options) {
146
- content = content
147
- .replace(/^\n+/, '') // remove leading newlines
148
- .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
149
- .replace(/\n/gm, '\n '); // indent
150
149
  var prefix = options.bulletListMarker + ' ';
151
150
  var parent = node.parentNode;
152
151
  if (parent.nodeName === 'OL') {
@@ -154,8 +153,11 @@
154
153
  var index = Array.prototype.indexOf.call(parent.children, node);
155
154
  prefix = (start ? Number(start) + index : index + 1) + '. ';
156
155
  }
156
+ var isParagraph = /\n$/.test(content);
157
+ content = trimNewlines(content) + (isParagraph ? '\n' : '');
158
+ content = content.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
157
159
  return (
158
- prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
160
+ prefix + content + (node.nextSibling ? '\n' : '')
159
161
  )
160
162
  }
161
163
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "turndown",
3
3
  "description": "A library that converts HTML to Markdown",
4
- "version": "7.2.0",
4
+ "version": "7.2.2",
5
5
  "author": "Dom Christie",
6
6
  "main": "lib/turndown.cjs.js",
7
7
  "module": "lib/turndown.es.js",