1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-22 16:08:09 +00:00

Merge pull request #10 from milan-rusev/master

Markdown-it markdown parser
This commit is contained in:
Patrizio Bekerle 2017-08-09 14:50:20 +02:00 committed by GitHub
commit 6b48bd75c2
3 changed files with 8067 additions and 0 deletions

10
markdown-it/info.json Normal file
View file

@ -0,0 +1,10 @@
{
"name": "Markdown-it markdown parser",
"identifier": "markdown-it",
"script": "markdown-it.qml",
"resources": ["markdown-it.js"],
"authors": ["@milan-rusev"],
"version": "0.0.1",
"minAppVersion": "17.08.2",
"description" : "This script replaces the default markdown renderer with markdown-it.\n\n<b>Dependencies</b>\n<a href=\"https://github.com/markdown-it/markdown-it">markdown-it.js</a> (v8.3.2 bundled with the script)\n\n<b>Usage</b>\nFor the possible configuration options check <a href=\"https://github.com/markdown-it/markdown-it/tree/master/lib/presets">here</a>."
}

7965
markdown-it/markdown-it.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,92 @@
import QtQml 2.0
import QOwnNotesTypes 1.0
import "markdown-it.js" as MarkdownIt
QtObject {
property variant md;
property string options;
property string customStylesheet;
property variant settingsVariables: [
{
"identifier": "options",
"name": "Markdown-it options",
"description": "For available options and default values see https://github.com/markdown-it/markdown-it/blob/master/lib/presets",
"type": "text",
"default":
"{"+"\n"+
" //html: false, // Enable HTML tags in source"+"\n"+
" //xhtmlOut: false, // Use '/' to close single tags (<br />)"+"\n"+
" //breaks: false, // Convert '\\n' in paragraphs into <br>"+"\n"+
" //langPrefix: 'language-', // CSS language prefix for fenced blocks"+"\n"+
" //linkify: false, // autoconvert URL-like texts to links"+"\n"+
""+"\n"+
" // Enable some language-neutral replacements + quotes beautification"+"\n"+
" //typographer: false,"+"\n"+
""+"\n"+
" // Double + single quotes replacement pairs, when typographer enabled,"+"\n"+
" // and smartquotes on. Could be either a String or an Array."+"\n"+
" //"+"\n"+
" // For example, you can use '«»„“' for Russian, '„“‚‘' for German,"+"\n"+
" // and ['«\\xA0', '\\xA0»', '\\xA0', '\\xA0'] for French (including nbsp)."+"\n"+
" //quotes: '\\u201c\\u201d\\u2018\\u2019', /* “”‘’ */"+"\n"+
""+"\n"+
" // Highlighter function. Should return escaped HTML,"+"\n"+
" // or '' if the source string is not changed and should be escaped externaly."+"\n"+
" // If result starts with <pre... internal wrapper is skipped."+"\n"+
" //"+"\n"+
" // function (/*str, lang*/) { return ''; }"+"\n"+
" //"+"\n"+
" //highlight: null,"+"\n"+
""+"\n"+
" //maxNesting: 100 // Internal protection, recursion limit"+"\n"+
"}"
},
{
"identifier": "customStylesheet",
"name": "Custom stylesheet",
"description": "Please enter your custom stylesheet:",
"type": "text",
"default": null,
},
];
function init() {
var optionsObj = eval("("+options+")");
md = new MarkdownIt.markdownit(optionsObj);
//Allow file:// url scheme
var validateLinkOrig = md.validateLink;
var GOOD_PROTO_RE = /^(file):/;
md.validateLink = function(url)
{
var str = url.trim().toLowerCase();
return GOOD_PROTO_RE.test(str) ? true : validateLinkOrig(url);
}
}
function noteToMarkdownHtmlHook(note, html) {
var mdHtml = md.render(note.noteText);
//Insert root folder in attachments and media relative urls
var path = script.currentNoteFolderPath();
if (script.platformIsWindows()) {
path = "/" + path;
}
mdHtml = mdHtml.replace(new RegExp("href=\"file://attachments/", "gi"), "href=\"file://" + path + "/attachments/");
mdHtml = mdHtml.replace(new RegExp("src=\"file://media/", "gi"), "src=\"file://" + path + "/media/");
//Get original styles
var head = html.match(new RegExp("<head>(?:.|\n)*?</head>"))[0];
//Add custom styles
head = head.replace("</style>", customStylesheet + "</style>");
mdHtml = "<html>"+head+"<body>"+mdHtml+"</body></html>";
return mdHtml;
}
}