Open lucible opened 2 years ago
Whew! I'm happy to say that I took another look around the code today and was able to pull something together that will suffice for my current experiments / desires.
Warning: this is really hacky and not well-tested, but it should give anyone who comes across this in the future at least a place to start looking.
First, I add two new rules to rules.ts
.
[[plain tiddlylinks]]
by nesting 2 capture groups and only selecting internal text if it doesn't include a pipe.[[text|text]]
pretty link syntax.const newRules: JSONMLRules = {
// other rules here
plainlink: {
...rules.link,
match: inline(
/^\[\[(([^\|]*?))\]\]/
),
jsonml: jsonml.link
},
prettylink: {
...rules.link,
match: inline(
/^\[\[(.*?)(?:\|(.*?))?\]\]/
),
jsonml: jsonml.link
},
// other rules here
};
Second, I adjusted the link function in jsonml.ts
to account for these two new types.
href
, lol. Maybe an arrow function would be more expressive?
prefixed
is true, we also need to know if external
is false. If so, the function assumes the target is an internal link and adds the anchor token.export function link() {
// first three consts defined here
function getURLTarget(
target: String
): String {
if (prefixed === true) {
return target;
} else if (external === false) {
return `#${target}`
} else {
return `#${target}`
}
}
const attributes = {
href: getURLTarget(target),
// ...
};
}
[[link|pretty title]]
syntax.const newRules: JSONMLRules = {
// const definitions, function, and attribute definitions
if (node.type === 'prettylink') {
attributes.href = `#${node.content[0].content}`;
node.content[0].content = node.target;
}
}
and done! Plain wiki-link style internal links should work, and so should internal Obsidian-style pretty links.
Hello!
Really grateful to have found this fork of TiddlyWiki, as it gives me hope that what I'd like to accomplish could be done!
What I'm trying to accomplish: host a TiddlyWiki server sourcing from an Obsidian vault folder. Tiddlymark is super super close to enabling that, as it solves the reading from YAML front matter issue and .md file type requirement.
What doesn't work: Obsidian has an internal linking syntax that is very similar to TiddlyWiki's, and it would be great if Tiddlymark was able to (perhaps optionally?) support that syntax. It's
[[link]]
for internal links and[[link|pretty title]]
for pretty links (flipped from TW, which is[[pretty title|link]]
)I'm sorta ok at hacking my way through the base TW code, so I was able to find where I could update the parsing to use the flipped Obsidian pretty links here and I've been trying to poke through Tiddlymark's code as well, but I'm struggling to understand what I would need to change and where. 😅
Any thoughts or assistance would be greatly appreciated -- thanks in advance. 😃