|
@@ -21,10 +21,13 @@ class TurndownConverter {
|
|
|
|
|
|
|
|
// TODO: verify and copy several rules from VNote 2.0.
|
|
// TODO: verify and copy several rules from VNote 2.0.
|
|
|
this.fixMark();
|
|
this.fixMark();
|
|
|
|
|
+
|
|
|
|
|
+ this.fixParagraph();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
turndown(p_html) {
|
|
turndown(p_html) {
|
|
|
- return this.ts.turndown(p_html);
|
|
|
|
|
|
|
+ let markdown = this.ts.turndown(p_html);
|
|
|
|
|
+ return markdown;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Trim a string into 3 parts: leading spaces, content, trailing spaces.
|
|
// Trim a string into 3 parts: leading spaces, content, trailing spaces.
|
|
@@ -69,6 +72,25 @@ class TurndownConverter {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ fixParagraph() {
|
|
|
|
|
+ this.ts.addRule('paragraph', {
|
|
|
|
|
+ filter: 'p',
|
|
|
|
|
+ replacement: function(content) {
|
|
|
|
|
+ // Replace leading spaces with to avoid being parsed as code block.
|
|
|
|
|
+ let lRe = /^\s+/;
|
|
|
|
|
+ let ret = lRe.exec(content);
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ let leadingSpaces = ret[0];
|
|
|
|
|
+ if (leadingSpaces.length > 3) {
|
|
|
|
|
+ content = ' '.repeat(leadingSpaces.length) + content.slice(leadingSpaces.length);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return '\n\n' + content + '\n\n'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
fixImage() {
|
|
fixImage() {
|
|
|
this.ts.addRule('img_fix', {
|
|
this.ts.addRule('img_fix', {
|
|
|
filter: 'img',
|
|
filter: 'img',
|