turndown 7.2.1 → 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(
|
|
121
|
-
content = content.replace(/^/gm, '> ');
|
|
124
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
122
125
|
return '\n\n' + content + '\n\n'
|
|
123
126
|
}
|
|
124
127
|
};
|
|
@@ -147,12 +150,11 @@ var TurndownService = (function () {
|
|
|
147
150
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
148
151
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
149
152
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
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(
|
|
120
|
-
content = content.replace(/^/gm, '> ');
|
|
123
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
121
124
|
return '\n\n' + content + '\n\n'
|
|
122
125
|
}
|
|
123
126
|
};
|
|
@@ -146,12 +149,11 @@ rules.listItem = {
|
|
|
146
149
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
147
150
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
148
151
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
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(
|
|
118
|
-
content = content.replace(/^/gm, '> ');
|
|
121
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
119
122
|
return '\n\n' + content + '\n\n'
|
|
120
123
|
}
|
|
121
124
|
};
|
|
@@ -144,12 +147,11 @@ rules.listItem = {
|
|
|
144
147
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
145
148
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
146
149
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
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(
|
|
124
|
-
content = content.replace(/^/gm, '> ');
|
|
127
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
125
128
|
return '\n\n' + content + '\n\n'
|
|
126
129
|
}
|
|
127
130
|
};
|
|
@@ -150,12 +153,11 @@
|
|
|
150
153
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
151
154
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
152
155
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
160
|
+
prefix + content + (node.nextSibling ? '\n' : '')
|
|
159
161
|
)
|
|
160
162
|
}
|
|
161
163
|
};
|
package/lib/turndown.cjs.js
CHANGED
|
@@ -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(
|
|
120
|
-
content = content.replace(/^/gm, '> ');
|
|
123
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
121
124
|
return '\n\n' + content + '\n\n'
|
|
122
125
|
}
|
|
123
126
|
};
|
|
@@ -146,12 +149,11 @@ rules.listItem = {
|
|
|
146
149
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
147
150
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
148
151
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
156
|
+
prefix + content + (node.nextSibling ? '\n' : '')
|
|
155
157
|
)
|
|
156
158
|
}
|
|
157
159
|
};
|
package/lib/turndown.es.js
CHANGED
|
@@ -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(
|
|
118
|
-
content = content.replace(/^/gm, '> ');
|
|
121
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
119
122
|
return '\n\n' + content + '\n\n'
|
|
120
123
|
}
|
|
121
124
|
};
|
|
@@ -144,12 +147,11 @@ rules.listItem = {
|
|
|
144
147
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
145
148
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
146
149
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
154
|
+
prefix + content + (node.nextSibling ? '\n' : '')
|
|
153
155
|
)
|
|
154
156
|
}
|
|
155
157
|
};
|
package/lib/turndown.umd.js
CHANGED
|
@@ -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(
|
|
124
|
-
content = content.replace(/^/gm, '> ');
|
|
127
|
+
content = trimNewlines(content).replace(/^/gm, '> ');
|
|
125
128
|
return '\n\n' + content + '\n\n'
|
|
126
129
|
}
|
|
127
130
|
};
|
|
@@ -150,12 +153,11 @@
|
|
|
150
153
|
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
151
154
|
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
|
152
155
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
.replace(/\n/gm, '\n' + ' '.repeat(prefix.length)); // indent
|
|
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
|
|
160
|
+
prefix + content + (node.nextSibling ? '\n' : '')
|
|
159
161
|
)
|
|
160
162
|
}
|
|
161
163
|
};
|