This commit is contained in:
maru21 2023-10-01 20:58:32 +02:00
parent ec90d4c676
commit 268749a35b
2 changed files with 26 additions and 16 deletions

View File

@ -16,7 +16,7 @@ window.activeState = {
fileName: "", fileName: "",
lastElement: "", lastElement: "",
serverFilesTs: "", serverFilesTs: "",
lineBreak: 200, lineBreak: 100,
templates: [], templates: [],
templateFieldTypes: [ templateFieldTypes: [
"simpleInput", "simpleInput",

View File

@ -128,8 +128,8 @@ function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
} }
let bHtml = b.replace(/(?:\r\n|\r|\n)/g, "<br>"); let bHtml = b.replace(/(?:\r\n|\r|\n)/g, "<br>");
bHtml = bHtml.replace(/!l /g, " • "); //bHtml = bHtml.replace(/!l /g, " • ");
bHtml = bHtml.replace(/!ls /g, " ○ "); //bHtml = bHtml.replace(/!ls /g, " ○ ");
bHtml = bHtml.replace(/ /g, "&nbsp;"); bHtml = bHtml.replace(/ /g, "&nbsp;");
bHtml = bHtml =
@ -320,9 +320,10 @@ function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
} }
function parseGlobalLineBreak(data) { function parseGlobalLineBreak(data) {
//parse each line of input with parseLineBreak return condensed string with newlines
let parsedData = ''; let parsedData = '';
for (let line of data.split('\n')) { for (let line of data.split('\n')) {
let parsedLine = parseLineBreak(line); let parsedLine = parseLineBreak(line, 0, activeState.lineBreak);
if (parsedData != '') { if (parsedData != '') {
parsedData = parsedData + '\n' + parsedLine; parsedData = parsedData + '\n' + parsedLine;
} else { } else {
@ -332,34 +333,43 @@ function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
return parsedData return parsedData
} }
function parseLineBreak(line, intendation = 0) { function parseLineBreak(line, intendation = 0, lineBreak = activeState.lineBreak - 5) {
//very much in development no idea yet //add 5 chars buffer to fix list intendation issue
//each input field gets parsed line by line twice once for list inputs and a second time for each input
let lines; let lines;
if (line.length > activeState.lineBreak) { if (line.length > lineBreak) {
//create linebreak in between second to last word
let correctedLineBreak; let correctedLineBreak;
let newLineStart; let newLineStart;
let cLBt = activeState.lineBreak-(intendation*2) let cLBt = lineBreak-(intendation*2)
//find last space before linebreak
correctedLineBreak = line.substring(0, cLBt).lastIndexOf(" "); correctedLineBreak = line.substring(0, cLBt).lastIndexOf(" ");
//and fix the next lines start
newLineStart = correctedLineBreak+1; newLineStart = correctedLineBreak+1;
//add to parsed output
lines = line.substring(0, correctedLineBreak); lines = line.substring(0, correctedLineBreak);
//delete first parsed output from inputstring
line = line.substring(newLineStart); line = line.substring(newLineStart);
while(line.length > activeState.lineBreak) { let intendationSpaces = '';
let intendationSpaces = ''; //check if an intendation is given if so convert it to correct spaces
if (intendation != 0) intendationSpaces = ' '.repeat(intendation+1); if (intendation != 0) intendationSpaces = ' '.repeat(intendation+1);
let cLBt = activeState.lineBreak-(intendation*2)
//start loop to parse rest of the string
while(line.length > lineBreak) {
let cLBt = lineBreak-(intendation*2)
correctedLineBreak = line.substring(0, cLBt).lastIndexOf(" "); correctedLineBreak = line.substring(0, cLBt).lastIndexOf(" ");
newLineStart = correctedLineBreak+1; newLineStart = correctedLineBreak+1;
//add to output with intendation if given
lines += "\n" + intendationSpaces + line.substring(0, correctedLineBreak); lines += "\n" + intendationSpaces + line.substring(0, correctedLineBreak);
//delete from input
line = line.substring(newLineStart); line = line.substring(newLineStart);
break;
} }
let intendationSpaces = ''; //process rest of the string with correct intendation
if (intendation != 0) intendationSpaces = ' '.repeat(intendation+1);
lines += "\n" + intendationSpaces + line; lines += "\n" + intendationSpaces + line;
} else { } else {
//if string is within lineBreak just forward input to output
lines = line; lines = line;
} }
return lines; return lines;