1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00

Desktop: Add option to choose Code Mirror as code editor (#3284)

This commit is contained in:
Caleb John
2020-06-06 09:00:20 -06:00
committed by GitHub
parent a3153f1c9f
commit a8c8539e7a
28 changed files with 1330 additions and 15 deletions

View File

@ -4,6 +4,10 @@ const MarkdownIt = require('markdown-it');
const { setupLinkify } = require('lib/joplin-renderer');
const removeMarkdown = require('remove-markdown');
// Taken from codemirror/addon/edit/continuelist.js
const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/;
const emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
const markdownUtils = {
// Not really escaping because that's not supported by marked.js
escapeLinkText(text) {
@ -61,9 +65,25 @@ const markdownUtils = {
return output;
},
// The match results has 5 items
// Full match array is
// [Full match, whitespace, list token, ol line number, whitespace following token]
olLineNumber(line) {
const match = line.match(/^(\d+)\.(\s.*|)$/);
return match ? Number(match[1]) : 0;
const match = line.match(listRegex);
return match ? Number(match[3]) : 0;
},
extractListToken(line) {
const match = line.match(listRegex);
return match ? match[2] : '';
},
isListItem(line) {
return listRegex.test(line);
},
isEmptyListItem(line) {
return emptyListRegex.test(line);
},
createMarkdownTable(headers, rows) {