Remove TinyMce Added Squire

This commit is contained in:
Max G
2020-02-01 22:21:22 +00:00
parent 68effaa5c3
commit 133a86e09e
91 changed files with 6538 additions and 10672 deletions

View File

@@ -8,7 +8,7 @@ ProcessText.removeHtml = (string) => {
}
return string
.replace(/&[#A-Za-z0-9]+;/g,' ') //Rip out all HTML entities
.replace(/&[[#A-Za-z0-9]+A-Za-z0-9]+;/g,' ') //Rip out all HTML entities
.replace(/<[^>]+>/g, ' ') //Rip out all HTML tags
.replace(/\s+/g, ' ') //Remove all whitespace
.trim()
@@ -25,6 +25,8 @@ ProcessText.getUrlsFromString = (string) => {
+ Empty lines are skipped
+ URLs are turned into links
+ All URLs are givent the target="_blank" property
+ Lists are given extra display characters
+ If note starts as a list, skip the title
*/
ProcessText.deduceNoteTitle = (inString) => {
@@ -36,7 +38,16 @@ ProcessText.deduceNoteTitle = (inString) => {
return {title, sub}
}
let lines = inString.match(/[^\r\n]+/g)
//Remove inline styles that may be added by editor
inString = inString.replace(/style=".*?"/g,'')
//Match full line and closing tag or just closing tag
let lines = inString.match(/[<[a-zA-Z0-9]+>(.*?)<\/[a-zA-Z0-9]+>|<\/[a-zA-Z0-9>]+?>/g)
if(lines == null){ lines = [inString] }
//.match(/[^\r\n]+/g) //Match return or newline
// console.log(lines)
let finalLines = []
const startTags = ['<ol','<li','<ul']
@@ -45,6 +56,7 @@ ProcessText.deduceNoteTitle = (inString) => {
let totalLines = Math.min(lines.length, 6)
let charLimit = 250
let listStart = false
let noTitleJustList = false
for(let i=0; i < totalLines; i++){
@@ -53,7 +65,10 @@ ProcessText.deduceNoteTitle = (inString) => {
continue
}
const cleanLine = ProcessText.removeHtml(lines[i]).trim().replace('&nbsp','')
//Various empty chars are possible
const cleanLine = ProcessText.removeHtml(lines[i])
.replace('<br>','')
.trim()
const lineStart = lines[i].trim().substring(0, 3)
charLimit -= cleanLine.length
@@ -69,6 +84,11 @@ ProcessText.deduceNoteTitle = (inString) => {
continue
}
//Check if note starts with a list, don't include title, just show list
if(finalLines.length == 0 && startTags.includes(lineStart)){
noTitleJustList = true
}
//Empty line, may be a list open or close
if(cleanLine.length == 0 && (startTags.includes(lineStart) || endTags.includes(lineStart) )){
if(listStart == false){
@@ -86,7 +106,7 @@ ProcessText.deduceNoteTitle = (inString) => {
}
//Skip empty lines
if(!cleanLine || cleanLine.length == 0 || cleanLine == '&nbsp;'){
if(!cleanLine || cleanLine.length == 0){
totalLines++
continue
}
@@ -126,7 +146,7 @@ ProcessText.deduceNoteTitle = (inString) => {
}
//Pull out title if its not an empty string
if(ProcessText.removeHtml(finalLines[0]).trim().replace('&nbsp','').length > 0){
if(ProcessText.removeHtml(finalLines[0]).trim().replace('&nbsp','').length > 0 && !noTitleJustList){
title = finalLines.shift()
}