|
|
|
@ -1,4 +1,4 @@
|
|
|
|
import { getStartPositionInLine, setStartPositionInLine } from "./caret.js";
|
|
|
|
import { saveSelection, loadSelection } from "./caret.js";
|
|
|
|
|
|
|
|
|
|
|
|
function load(textarea, div) {
|
|
|
|
function load(textarea, div) {
|
|
|
|
div.innerHTML = '';
|
|
|
|
div.innerHTML = '';
|
|
|
|
@ -14,7 +14,7 @@ function load(textarea, div) {
|
|
|
|
function appendData(div, data) {
|
|
|
|
function appendData(div, data) {
|
|
|
|
const selection = window.getSelection();
|
|
|
|
const selection = window.getSelection();
|
|
|
|
selection.deleteFromDocument();
|
|
|
|
selection.deleteFromDocument();
|
|
|
|
let ret = getStartPositionInLine();
|
|
|
|
let ret = saveSelection();
|
|
|
|
let line = ret[0];
|
|
|
|
let line = ret[0];
|
|
|
|
let position = ret[1];
|
|
|
|
let position = ret[1];
|
|
|
|
if (line == null) {
|
|
|
|
if (line == null) {
|
|
|
|
@ -41,7 +41,7 @@ function appendData(div, data) {
|
|
|
|
prevline.after(newline);
|
|
|
|
prevline.after(newline);
|
|
|
|
position = lines[lines.length - 1].length;
|
|
|
|
position = lines[lines.length - 1].length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setStartPositionInLine(newline, position);
|
|
|
|
loadSelection([newline, position, newline, position]);
|
|
|
|
redrawTables(div, dpwidth(div));
|
|
|
|
redrawTables(div, dpwidth(div));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -125,9 +125,9 @@ function formatLine(line) {
|
|
|
|
line = ret[0];
|
|
|
|
line = ret[0];
|
|
|
|
let listMono = ret[1];
|
|
|
|
let listMono = ret[1];
|
|
|
|
|
|
|
|
|
|
|
|
// test remove link
|
|
|
|
|
|
|
|
ret = removeLink(line);
|
|
|
|
ret = removeLink(line);
|
|
|
|
console.log('removeLink ' + ret[0]);
|
|
|
|
line = ret[0];
|
|
|
|
|
|
|
|
let listLink = ret[1];
|
|
|
|
|
|
|
|
|
|
|
|
if (line.match(/^\s*_{3,}\s*$/)) {
|
|
|
|
if (line.match(/^\s*_{3,}\s*$/)) {
|
|
|
|
token = /^(\s*_{3,}\s*)$/
|
|
|
|
token = /^(\s*_{3,}\s*)$/
|
|
|
|
@ -195,10 +195,11 @@ function formatLine(line) {
|
|
|
|
if (token != null) {
|
|
|
|
if (token != null) {
|
|
|
|
line = line.replace(token, '<span class="token">$1</span>');
|
|
|
|
line = line.replace(token, '<span class="token">$1</span>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = addLink(line);
|
|
|
|
|
|
|
|
line = addBold(line);
|
|
|
|
line = addBold(line);
|
|
|
|
line = addItalic(line);
|
|
|
|
line = addItalic(line);
|
|
|
|
|
|
|
|
line = addStrike(line);
|
|
|
|
line = addTableLine(line);
|
|
|
|
line = addTableLine(line);
|
|
|
|
|
|
|
|
line = addLink(line, listLink);
|
|
|
|
line = addMono(line, listMono);
|
|
|
|
line = addMono(line, listMono);
|
|
|
|
elem.innerHTML = line;
|
|
|
|
elem.innerHTML = line;
|
|
|
|
if (elem.getElementsByClassName('tablerow').length > 0) {
|
|
|
|
if (elem.getElementsByClassName('tablerow').length > 0) {
|
|
|
|
@ -471,11 +472,33 @@ function removeLink(line) {
|
|
|
|
return [line, null];
|
|
|
|
return [line, null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
line = line.replace(/(\[([^\]]*?)\]\(([^\)]*?)\))/g, "[$2]()");
|
|
|
|
line = line.replace(/(\[([^\]]*?)\]\(([^\)]*?)\))/g, "[]()");
|
|
|
|
return [line, listLink.reverse()];
|
|
|
|
return [line, listLink.reverse()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addLink(line) {
|
|
|
|
function addLink(line, listLink) {
|
|
|
|
|
|
|
|
if (listLink == null) {
|
|
|
|
|
|
|
|
return line;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let cpt = 0;
|
|
|
|
|
|
|
|
let match;
|
|
|
|
|
|
|
|
let matches = [];
|
|
|
|
|
|
|
|
let re = /\[\]\(\)/g;
|
|
|
|
|
|
|
|
while ((match = re.exec(line)) != null) {
|
|
|
|
|
|
|
|
matches[cpt] = match.index;
|
|
|
|
|
|
|
|
if (cpt > 1000) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cpt++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
matches = matches.reverse();
|
|
|
|
|
|
|
|
for(let i=0; i<matches.length; i++) {
|
|
|
|
|
|
|
|
line = line.substring(0, matches[i]) + formatLink(listLink[i]) + line.substring(matches[i]+4, line.length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatLink(line) {
|
|
|
|
line = line.replace(/(\[([^\]]+?)\]\(([^\)]+?)\))/ig, '<span class="token">[</span><a class="link" data-href="$3" href="$3">$2</a><span class="token">]($3)</span>');
|
|
|
|
line = line.replace(/(\[([^\]]+?)\]\(([^\)]+?)\))/ig, '<span class="token">[</span><a class="link" data-href="$3" href="$3">$2</a><span class="token">]($3)</span>');
|
|
|
|
line = line.replace(/(\[([^\]]+?)\]\(\))/ig, '<span class="token">[</span><a class="link" data-href="$2" href="$2">$2</a><span class="token">]()</span>');
|
|
|
|
line = line.replace(/(\[([^\]]+?)\]\(\))/ig, '<span class="token">[</span><a class="link" data-href="$2" href="$2">$2</a><span class="token">]()</span>');
|
|
|
|
line = line.replace(/(\[\]\(([^\)]+?)\))/ig, '<span class="token">[](</span><a class="link" data-href="$2" href="$2">$2</a><span class="token">)</span>');
|
|
|
|
line = line.replace(/(\[\]\(([^\)]+?)\))/ig, '<span class="token">[](</span><a class="link" data-href="$2" href="$2">$2</a><span class="token">)</span>');
|
|
|
|
@ -494,4 +517,9 @@ function addItalic(line) {
|
|
|
|
return line;
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addStrike(line) {
|
|
|
|
|
|
|
|
line = line.replace(/~~([^\s].*?)~~/ig, '<s><span class="token">~~</span>$1<span class="token">~~</span></s>');
|
|
|
|
|
|
|
|
return line;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { load, save, formatLine, formatTable, redrawTables, dpwidth, appendData };
|
|
|
|
export { load, save, formatLine, formatTable, redrawTables, dpwidth, appendData };
|
|
|
|
|