From 8b35f1fef3c5d3223ae8854dff33580e0dfd738a Mon Sep 17 00:00:00 2001 From: david Date: Sun, 5 Feb 2023 18:19:29 -0600 Subject: [PATCH] Added support for locations with :'s in them --- main.js | 12 +++++++++--- src/index.ts | 14 +++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index e14ff9d..caca2c4 100644 --- a/main.js +++ b/main.js @@ -61,8 +61,11 @@ var MyPlugin = class extends import_obsidian.Plugin { } }); lines.forEach((line, linenum) => { - if (line.split("")[0] != " " && line.split("")[0] != " ") { + if (line[0] != " " && line[0] != " ") { var newkey = line.trim().split("#")[0].trim(); + if (newkey[newkey.length - 1] == ":") { + newkey = newkey.slice(0, newkey.length - 1); + } if (!locations[newkey]) { locations[newkey] = linenum; visitslocs[newkey] = 0; @@ -133,8 +136,8 @@ function MakeNodeFromLineToNextJump(linenum, text, fromnode2, edgelabel) { } while (i < text.length) { var line = text[i]; - if (line.split("")[0] == " " || line.split("")[0] == " ") { - if (line.trim().split("")[0] == "j") { + if (line[0] == " " || line[0] == " ") { + if (line.trim()[0] == "j") { currnode = currnode + line + "\n```"; newnode = { "id": nodeid, "x": workingx * side, "y": workingy, "width": 550, "height": 25 * currnode.split("\n").length, "type": "text", "text": currnode, "startline": linenum, "endline": i }; nodeid = nodeid + 1; @@ -155,6 +158,9 @@ function MakeNodeFromLineToNextJump(linenum, text, fromnode2, edgelabel) { currnode = currnode + line + "\n"; } } else { + if (line[line.length - 1] == ":") { + line = line.slice(0, line.length - 1); + } if (visitslocs[line.trim()] == 0 && i != linenum) { currnode = currnode + "```"; newnode = { "id": nodeid, "x": workingx * side, "y": workingy, "width": 550, "height": 25 * currnode.split("\n").length, "type": "text", "text": currnode, "startline": linenum, "endline": i }; diff --git a/src/index.ts b/src/index.ts index 8f6684b..7f3a86e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,9 +44,13 @@ export default class MyPlugin extends Plugin { lines.forEach((line,linenum) => { //Only look at lines that could be locations - if(line.split("")[0] != '\t' && line.split("")[0] != " "){ + if(line[0] != '\t' && line[0] != " "){ //Cut out white space and comments (#) var newkey = line.trim().split("#")[0].trim() + //Strip off ":" if they are at the end of the location string + if(newkey[newkey.length-1] == ":"){ + newkey = newkey.slice(0,newkey.length-1) + } //Populate locations and visits array with line numbers and all 0's if (!locations[newkey]) { locations[newkey] = linenum; @@ -139,8 +143,8 @@ function MakeNodeFromLineToNextJump(linenum: any, text: any, fromnode: any, edge while(i < text.length){ var line = text[i] //If the current line is an instruction and not a location - if(line.split("")[0] == '\t' || line.split("")[0] == " "){ - if(line.trim().split("")[0] == 'j'){ + if(line[0] == '\t' || line[0] == " "){ + if(line.trim()[0] == 'j'){ currnode = currnode + line + "\n```" newnode = {"id":nodeid, "x": workingx*side, "y": workingy, "width": 550,"height": 25*currnode.split("\n").length, "type": "text", "text": currnode, "startline": linenum,"endline": i} nodeid = nodeid + 1 @@ -166,6 +170,10 @@ function MakeNodeFromLineToNextJump(linenum: any, text: any, fromnode: any, edge } //Else, we're handling a location else{ + //Remove ":" if at the end of location + if(line[line.length-1] == ":"){ + line = line.slice(0,line.length-1) + } //Have we visited this location before (0 == no) and is this not the first line of a node? if(visitslocs[line.trim()] == 0 && i != linenum){ //Close the node text and create a node object