mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
use GFM extensions for markdown export, closes #638
This commit is contained in:
parent
ed24e32305
commit
f6fc24d11d
9
package-lock.json
generated
9
package-lock.json
generated
@ -1549,7 +1549,7 @@
|
|||||||
},
|
},
|
||||||
"buf-compare": {
|
"buf-compare": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/buf-compare/-/buf-compare-1.0.1.tgz",
|
"resolved": "http://registry.npmjs.org/buf-compare/-/buf-compare-1.0.1.tgz",
|
||||||
"integrity": "sha1-/vKNqLgROgoNtEMLC2Rntpcws0o=",
|
"integrity": "sha1-/vKNqLgROgoNtEMLC2Rntpcws0o=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
@ -4713,7 +4713,7 @@
|
|||||||
},
|
},
|
||||||
"load-json-file": {
|
"load-json-file": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
||||||
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
@ -13130,6 +13130,11 @@
|
|||||||
"jsdom": "^11.9.0"
|
"jsdom": "^11.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"turndown-plugin-gfm": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/turndown-plugin-gfm/-/turndown-plugin-gfm-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-vwz9tfvF7XN/jE0dGoBei3FXWuvll78ohzCZQuOb+ZjWrs3a0XhQVomJEb2Qh4VHTPNRO4GPZh0V7VRbiWwkRg=="
|
||||||
|
},
|
||||||
"tweetnacl": {
|
"tweetnacl": {
|
||||||
"version": "0.14.5",
|
"version": "0.14.5",
|
||||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
"string-similarity": "^3.0.0",
|
"string-similarity": "^3.0.0",
|
||||||
"tar-stream": "2.1.0",
|
"tar-stream": "2.1.0",
|
||||||
"turndown": "5.0.3",
|
"turndown": "5.0.3",
|
||||||
|
"turndown-plugin-gfm": "1.0.2",
|
||||||
"unescape": "1.0.1",
|
"unescape": "1.0.1",
|
||||||
"ws": "7.1.2",
|
"ws": "7.1.2",
|
||||||
"xml2js": "0.4.22"
|
"xml2js": "0.4.22"
|
||||||
|
19
src/services/export/md.js
Normal file
19
src/services/export/md.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const TurndownService = require('turndown');
|
||||||
|
const turndownPluginGfm = require('turndown-plugin-gfm');
|
||||||
|
|
||||||
|
let instance = null;
|
||||||
|
|
||||||
|
function toMarkdown(content) {
|
||||||
|
if (instance === null) {
|
||||||
|
instance = new TurndownService();
|
||||||
|
instance.use(turndownPluginGfm.gfm);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance.turndown(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
toMarkdown
|
||||||
|
};
|
@ -1,9 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const TurndownService = require('turndown');
|
|
||||||
const mimeTypes = require('mime-types');
|
const mimeTypes = require('mime-types');
|
||||||
const html = require('html');
|
const html = require('html');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
const mdService = require('./md');
|
||||||
|
|
||||||
async function exportSingleNote(exportContext, branch, format, res) {
|
async function exportSingleNote(exportContext, branch, format, res) {
|
||||||
const note = await branch.getNote();
|
const note = await branch.getNote();
|
||||||
@ -31,8 +31,7 @@ async function exportSingleNote(exportContext, branch, format, res) {
|
|||||||
mime = 'text/html';
|
mime = 'text/html';
|
||||||
}
|
}
|
||||||
else if (format === 'markdown') {
|
else if (format === 'markdown') {
|
||||||
const turndownService = new TurndownService();
|
payload = mdService.toMarkdown(content);
|
||||||
payload = turndownService.turndown(content);
|
|
||||||
extension = 'md';
|
extension = 'md';
|
||||||
mime = 'text/x-markdown'
|
mime = 'text/x-markdown'
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ const repository = require('../repository');
|
|||||||
const tar = require('tar-stream');
|
const tar = require('tar-stream');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const mimeTypes = require('mime-types');
|
const mimeTypes = require('mime-types');
|
||||||
const TurndownService = require('turndown');
|
const mdService = require('./md');
|
||||||
const packageInfo = require('../../../package.json');
|
const packageInfo = require('../../../package.json');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const protectedSessionService = require('../protected_session');
|
const protectedSessionService = require('../protected_session');
|
||||||
@ -17,8 +17,6 @@ const sanitize = require("sanitize-filename");
|
|||||||
* @param {string} format - 'html' or 'markdown'
|
* @param {string} format - 'html' or 'markdown'
|
||||||
*/
|
*/
|
||||||
async function exportToTar(exportContext, branch, format, res) {
|
async function exportToTar(exportContext, branch, format, res) {
|
||||||
let turndownService = format === 'markdown' ? new TurndownService() : null;
|
|
||||||
|
|
||||||
const pack = tar.pack();
|
const pack = tar.pack();
|
||||||
|
|
||||||
const noteIdToMeta = {};
|
const noteIdToMeta = {};
|
||||||
@ -232,7 +230,7 @@ ${content}
|
|||||||
return html.prettyPrint(content, {indent_size: 2});
|
return html.prettyPrint(content, {indent_size: 2});
|
||||||
}
|
}
|
||||||
else if (noteMeta.format === 'markdown') {
|
else if (noteMeta.format === 'markdown') {
|
||||||
let markdownContent = turndownService.turndown(content);
|
let markdownContent = mdService.toMarkdown(content);
|
||||||
|
|
||||||
if (markdownContent.trim().length > 0 && !markdownContent.startsWith("# ")) {
|
if (markdownContent.trim().length > 0 && !markdownContent.startsWith("# ")) {
|
||||||
markdownContent = '# ' + title + "\r\n" + markdownContent;
|
markdownContent = '# ' + title + "\r\n" + markdownContent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user