Various improvements and checks
This commit is contained in:
parent
a2abc91a2a
commit
1608d00beb
30 changed files with 541 additions and 360 deletions
|
@ -57,7 +57,7 @@ class MarkDown{
|
|||
if(first){
|
||||
i--;
|
||||
}
|
||||
let element=null;
|
||||
let element:HTMLElement;
|
||||
let keepys="";
|
||||
|
||||
if(txt[i+1]==="#"){
|
||||
|
@ -92,21 +92,24 @@ class MarkDown{
|
|||
if(!first&&!stdsize){
|
||||
span.appendChild(document.createElement("br"));
|
||||
}
|
||||
const build=[];
|
||||
const build:string[]=[];
|
||||
for(;txt[i]!=="\n"&&txt[i]!==undefined;i++){
|
||||
build.push(txt[i]);
|
||||
}
|
||||
if(stdsize){
|
||||
element=document.createElement("span");
|
||||
try{
|
||||
if(stdsize){
|
||||
element=document.createElement("span");
|
||||
}else continue;
|
||||
if(keep){
|
||||
element.append(keepys);
|
||||
}
|
||||
element.appendChild(this.markdown(build,{keep:keep,stdsize:stdsize}));
|
||||
span.append(element);
|
||||
}finally{
|
||||
i-=1;
|
||||
console.log(txt[i]);
|
||||
continue;
|
||||
}
|
||||
if(keep){
|
||||
element.append(keepys);
|
||||
}
|
||||
element.appendChild(this.markdown(build,{keep:keep,stdsize:stdsize}));
|
||||
span.append(element);
|
||||
i-=1;
|
||||
console.log(txt[i]);
|
||||
continue;
|
||||
}
|
||||
if(first){
|
||||
i++;
|
||||
|
@ -194,7 +197,7 @@ class MarkDown{
|
|||
count++;
|
||||
}
|
||||
}
|
||||
let build=[];
|
||||
let build:string[]=[];
|
||||
let find=0;
|
||||
let j=i+count;
|
||||
for(;txt[j]!==undefined&&find!==count;j++){
|
||||
|
@ -248,7 +251,7 @@ class MarkDown{
|
|||
count++;
|
||||
}
|
||||
}
|
||||
let build=[];
|
||||
let build:string[]=[];
|
||||
let find=0;
|
||||
let j=i+count;
|
||||
for(;txt[j]!==undefined&&find!==count;j++){
|
||||
|
@ -295,7 +298,7 @@ class MarkDown{
|
|||
|
||||
if(txt[i]==="~"&&txt[i+1]==="~"){
|
||||
let count=2;
|
||||
let build=[];
|
||||
let build:string[]=[];
|
||||
let find=0;
|
||||
let j=i+2;
|
||||
for(;txt[j]!==undefined&&find!==count;j++){
|
||||
|
@ -325,7 +328,7 @@ class MarkDown{
|
|||
}
|
||||
if(txt[i]==="|"&&txt[i+1]==="|"){
|
||||
let count=2;
|
||||
let build=[];
|
||||
let build:string[]=[];
|
||||
let find=0;
|
||||
let j=i+2;
|
||||
for(;txt[j]!==undefined&&find!==count;j++){
|
||||
|
@ -372,8 +375,7 @@ class MarkDown{
|
|||
if (found) {
|
||||
appendcurrent();
|
||||
i=j;
|
||||
|
||||
const parts=build.join("").match(/^<t:([0-9]{1,16})(:([tTdDfFR]))?>$/);
|
||||
const parts=build.join("").match(/^<t:([0-9]{1,16})(:([tTdDfFR]))?>$/) as RegExpMatchArray;
|
||||
const dateInput=new Date(Number.parseInt(parts[1]) * 1000);
|
||||
let time="";
|
||||
if (Number.isNaN(dateInput.getTime())) time=build.join("");
|
||||
|
@ -449,19 +451,23 @@ class MarkDown{
|
|||
}
|
||||
};
|
||||
box.onpaste=_=>{
|
||||
if(!_.clipboardData) return;
|
||||
console.log(_.clipboardData.types)
|
||||
const data=_.clipboardData.getData("text");
|
||||
|
||||
document.execCommand('insertHTML', false, data);
|
||||
_.preventDefault();
|
||||
if(!box.onkeyup) return;
|
||||
box.onkeyup(new KeyboardEvent("_"))
|
||||
}
|
||||
}
|
||||
boxupdate(box:HTMLElement){
|
||||
var restore = saveCaretPosition(box);
|
||||
const restore = saveCaretPosition(box);
|
||||
box.innerHTML="";
|
||||
box.append(this.makeHTML({keep:true}))
|
||||
restore();
|
||||
if(restore){
|
||||
restore();
|
||||
}
|
||||
}
|
||||
static gatherBoxText(element:HTMLElement){
|
||||
if(element.tagName.toLowerCase()==="img"){
|
||||
|
@ -492,11 +498,13 @@ class MarkDown{
|
|||
//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
|
||||
function saveCaretPosition(context){
|
||||
var selection = window.getSelection();
|
||||
if(!selection) return;
|
||||
var range = selection.getRangeAt(0);
|
||||
range.setStart( context, 0 );
|
||||
var len = range.toString().length;
|
||||
|
||||
return function restore(){
|
||||
if(!selection) return;
|
||||
var pos = getTextNodeAtPosition(context, len);
|
||||
selection.removeAllRanges();
|
||||
var range = new Range();
|
||||
|
@ -509,6 +517,7 @@ function saveCaretPosition(context){
|
|||
function getTextNodeAtPosition(root, index){
|
||||
const NODE_TYPE = NodeFilter.SHOW_TEXT;
|
||||
var treeWalker = document.createTreeWalker(root, NODE_TYPE, function next(elem) {
|
||||
if(!elem.textContent) return 0;
|
||||
if(index > elem.textContent.length){
|
||||
index -= elem.textContent.length;
|
||||
return NodeFilter.FILTER_REJECT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue