Closed kleinfelter closed 4 years ago
Actually, Relink is designed so you should be able to plug in a handler for a different tiddler type pretty easily. All tiddler text is handled by text.js. All this does is collect together all the relinktextoperator
modules. And then when it processes a tiddler's text, it looks for the correct module to the type.
Currently, only one such module exists, in wikitext.js. It's here it exports a function titled text/vnd.tiddlywiki
.
All you need to do is create a relinktextoperator
module that exports a function like:
/*\
module-type: relinktextoperator
title: $:/plugins/kleinfelter/relink/mmdtext.js
type: application/javascript
\*/
exports["text/markdown"] = function(tiddler, fromTitle, toTitle, changes, options) {
// look in tiddler.fields.text if it contains fromTitle in any form that needs to be updated.
// If yes, set `changes.text` to the text where fromTitle is changed to toTitle.
// otherwise do nothing
}
Within it, I guess you can be as complicated as you like. You could do simple regexp find-and-replace for links, or maybe you can integrate with the markdown plugin parser somehow, which is what Relink does with the tiddlywiki wikitext parser.
side note: If you look in text.js, you'll see it quick-rejects tiddlers that don't contain the name fromTiddler. I realize now I'm going to have to move that to wikitext, so don't count on that being there.
Huh. I just realized I assumed you're a programmer, and that you'd make the solution yourself. There isn't already a solution for this because markdown isn't a core part of tiddlywiki.
I assume you're rendering your markdown in tiddlywiki through some other plugin? I don't actually know. If it's ubiquitous enough, this may be something worth making it a part of Relink, or at least as an extension available alongside relink.
I do program sometimes. I'm using https://github.com/Jermolene/TiddlyWiki5/blob/master/plugins/tiddlywiki/markdown
Thank you for the pointers. When I can make some time, I'll take a look and see what I can do. I'll probably go for simple -- start with just
[[title]]
and maybe grow it to
[[title|visibleHyperlink]]
I'm just trying to get the majority of the links updated. If I miss one or two, once in a while, I can live with that. 99% of my links match the simple title-in-brackets case.
Whoops! No, I was mistaken. That markdown plugin is installed, but the one I'm actually using is https://github.com/anstosa/tw5-markdown
It more closely matches the dialect of Markdown which I actually use. I wish there were a real standard for Markdown. The lovely thing about standards is there are so many to choose from. ;-)
Wait.
Is that how markdown works? I thought all you'd need to look for is [caption](#link/to/tiddler)
and replace those. What markdown plugin are you using where wiki syntax like [[title]]
can still be used to make links?
So what you actually need is something that parses hybrid wikitext/markdown tiddlers? That's... much uglier.
I guess if the markdown links aren't the kind of links you're using for inter-tiddler linking, then you might be able to get away with just making the wikitext relinker also operate on your markdown tiddlers too.
/*\
module-type: relinktextoperator
title: $:/plugins/kleinfelter/relink/mmdtext.js
type: application/javascript
\*/
var parsers = require("$:/plugins/flibbles/relink/relinkoperations/text/wikitext.js");
exports["text/markdown"] = parsers["text/vnd.tiddlywiki"];
Then Relink will parse your markdown tiddlers like they were tiddlywiki tiddlers. If you need special handling, you could wrap parsers["text/vnd.tiddlywiki"]
in another function which takes a look at the text again for markdown patterns.
Ah yes, well there is no Markdown markup for intra-wiki links because Gruber didn't deal with that.
You say "Relink will parse your markdown tiddlers..." Is it actually parsing the text of the tiddler? If so, won't it fail to build a wikitext parse tree? And if it is parsing, are the updates done to the underlying text or to the parse tree?
I hate to think what would happen if it parsed Markdown as wikitext and then wrote the whole thing back out from the parse tree. Gonna lose content that way!
I think maybe the thing to do is to treat it as type=text and just go for the simple
[[title]]
links.
So I actually looked at the markdown plugin that ships with tiddlywiki. It actually has syntax for intra-wiki links: [Caption to link](#tiddler-title)
. It talks about it here, so I thought that was the kind of thing you were referring to.
Relink doesn't actually convert into a parse tree in order to better preserve the raw text's formatting. The worst it would do is replace fromTitle into toTitle in inappropriate places, or fail to replace in places it should.
So without further input, I'm going ahead and closing this issue. If Relink ever natively supports Markdown, it'll probably be the core markdown plugin that ships with tiddlywiki. Supporting something like anstosa Markdown would probably be more appropriate for an extension to Relink.
I am using http://demo.santosa.family/#tw5-markdown plugin to use markdown in the tiddler. When type of tiddler is set to "text/vnd.tiddlywiki" relink updates change in title to all tiddlers. However when the type of tiddler is set to "text/x-markdown" then relink don't update the new title in other linked tiddlers.
What can solve this problem?
I'm very confused by all these markdown plugins.
Does this support links like [Caption](#tiddler)
and also [[Caption|tiddler]]
?
The problem can be solved with a simple module I could write in 10 minutes if it's pure markdown. But if it's this hybrid stuff that can't pick a lane, it'd take a few modules to create a hybrid parser.
This is GitHub-flavored Markdown plus "Anything that the Markdown engine doesn’t recognize falls back to the built-in parser." So yeah, it's hybrid.
Pure Markdown (even GitHub Markdown, as opposed to Gruber Markdown) wouldn't be very useful in TiddlyWiki because you couldn't link to other Tiddlers. In fact, one could say that your tool already support pure Markdown because there are no no intra-wiki links, so relinking the null set fully handles it. ;-)
On Tue, May 19, 2020 at 9:50 PM Cameron Fischer notifications@github.com wrote:
I'm very confused by all these markdown plugins. Does this support links like Caption and also [[Caption|tiddler]]?
The problem can be solved with a simple module I could write in 10 minutes if it's pure markdown. But if it's this hybrid stuff that can't pick a lane, it'd take a few modules to create a hybrid parser.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/flibbles/tw5-relink/issues/12#issuecomment-631185349, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGJXBZOEBDEMW5PKSPPA5TRSMZQDANCNFSM4KHGRBHQ .
Hmm. I'll throw together a module that does the job, but just so you know, the pure markdown does support intra-wiki links. [Caption](#tiddler)
is a markdown link that links to another tiddler, and that's the kind of link I'll make sure Relink supports.
The problem with their hybrid method is that it goofs up your ability to use macros and widgets. They just render wrong and never call, so it's like it kind of supports wikitext, but it feels more like an incomplete side-effect to me.
I'll make a module. Hopefully it can help you too, @kleinfelter, assuming you still need it. I'm just worried that the module will only work with some markdown implementations and not others.
You are absolutely right about the issues with that plugin. A really solid GitHub-flavored Markdown processor for TW that also enabled macros and widgets would be spiffy. Sadly, I'm not going to have the time to do it myself, so I'll have to hope someone else gets motivated. :-(
Thank you much for looking into this again! I'm definitely interested.
On Wed, May 20, 2020 at 9:27 AM Cameron Fischer notifications@github.com wrote:
Hmm. I'll throw together a module that does the job, but just so you know, the pure markdown does support intra-wiki links. Caption is a markdown link that links to another tiddler, and that's the kind of link I'll make sure Relink supports.
The problem with their hybrid method is that it goofs up your ability to use macros and widgets. They just render wrong and never call, so it's like it kind of supports wikitext, but it feels more like an incomplete side-effect to me.
I'll make a module. Hopefully it can help you too, @kleinfelter https://github.com/kleinfelter, assuming you still need it. I'm just worried that the module will only work with some markdown implementations and not others.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flibbles/tw5-relink/issues/12#issuecomment-631472999, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGJXBYPZD2TAGJORHWWJ4TRSPLD5ANCNFSM4KHGRBHQ .
Because there are several different markdown plugins, each slightly different, and because most of them like to do their silly hybrid support, this module is going to take me some time.
I'll reopen this and get back with you when I have something.
As a stopgap solution, I added the text
field with type wikitext
via the plugin configuration panel. It seems to handle links created using the WikiText [[link]]
syntax.
Is the version with the stopgap solution available somwhere for testing? I'd love to give it a whirl and provide feedback.
The stopgap solution is to just add text=wikitext
into your whitelist table.
...but please God don't do this. It's so error prone. It can wreck your markdown. I'm working hours every day to make the markdown support, and make it right. It should be ready this weekend soon.
Holy crap that took a lot of work. There is now a supplemental Relink plugin to add markdown support. See the demo site for install details.
That plugin will work with anstosa/tw5-markdown, but I built it against tiddlywiki's core tiddlywiki/markdown plugin. I'll be straight with you guys. It's better in every single way except one (and I submitted a bugfix PR for that).
[X]
Whelp. That's it. I've got to take a serious break from coding. This "quick little module" I described earlier ended up being eight sizeable javascript files. It's not perfect yet, but it's a hell of a lot better than adding the text
field with type wikitext
to the plugin configuration panel.
Closing this issue.
"Holy crap that took a lot of work." LOL. This is often how programming goes. Thank you for the effort!
On Mon, May 25, 2020 at 9:48 PM Cameron Fischer notifications@github.com wrote:
Holy crap that took a lot of work. There is now a supplemental Relink plugin to add markdown support. See the demo site for install details.
That plugin will work with anstosa/tw5-markdown, but I built it against tiddlywiki's core tiddlywiki/markdown plugin. I'll be straight with you guys. It's better in every single way except one (and I submitted a bugfix PR for that).
- It's got more features. As far as I can tell, the only one it's missing is the checkmark syntax [X]
- It handles internal links far better, and it handles internal image links, which anstosa's doesn't.
- It does allow widgets and macros.
- It also supports prettylinks. You just have to enable it first. Just add "prettylink" to the end of the string in the shadow tiddler: $:/config/markdown/renderWikiTextPragma
Whelp. That's it. I've got to take a serious break from coding. This "quick little module" I described earlier ended up being eight sizeable javascript files. It's not perfect yet, but it's a hell of a lot better than adding the text field with type wikitext to the plugin configuration panel.
Closing this issue.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flibbles/tw5-relink/issues/12#issuecomment-633766668, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGJXB36ZWXOPBZ3SJ6GR2DRTMNVLANCNFSM4KHGRBHQ .
Gee. All of my non-system/non-plugin tiddlers are Markdown. Where would I need to look to investigate turning Relink loose on Markdown tiddlers? What issues would I need to consider?
(There's a reason why I use Markdown and node.js -- I means that all of my tiddlers are stored in individual Markdown files. That's a pretty safe mechanism if I later decide to migrate to a different product for my personal knowledge base.)