Added support for locations with :'s in them

This commit is contained in:
david 2023-02-05 18:19:29 -06:00
parent 8a1a4b98c5
commit 8b35f1fef3
2 changed files with 20 additions and 6 deletions

12
main.js
View file

@ -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 };

View file

@ -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