-
Hi, I'm recently playing https://github.com/unifiedjs/unified , I can make a tid <-> md converter if I can access to tw's wikitext parser. I know I can do this inside a tw runtime context: let result = new $tw.Wiki.parsers['text/vnd.tiddlywiki']('text/vnd.tiddlywiki', '! Hello', {}) But I want to achieve this outside of the TiddlyWiki runtime context: // only import parsers, and tree shaking other code, so my npm package can be small,
// and without bundling nodejs codes into a npm package that is used in the web
import { parsers } from 'tiddlywiki' In the worse case, I will have to copy code inside |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
TWs parser is created dynamically at startup and it's not exposed that way. TWs initial commit was Nov 2011. The development started way before this date. ...
ES6 was 4 years away, so TW used and still uses the CommonJS specification to The other thing is, that the TW parsetree doesn't contain all the information the So if you want to use that info you will first need to help us to extend the parser. ... There is a pending PR: Add more start/end parser ranges #4977 which would need to be merged first. Then we will need to implement the line info, which imo will be the hardest part, since the TW parsers don't work line based. just some thoughts. |
Beta Was this translation helpful? Give feedback.
-
Hi @linonetwo the parser can be reused fairly easily already just by using var $tw = require("tiddlywiki").TiddlyWiki();
$tw.boot.argv = ["--version"];
$tw.boot.boot(function () {
var text = "HelloThere this is ''wikitext''";
var parseTree = $tw.wiki.parseText("text/vnd.tiddlywiki",text).tree;
console.log(JSON.stringify(parseTree,null,4));
}); At the moment our npm package is 18MB, which I don't think is excessive by modern standards. As you note, to strip things back to a minimum would likely involve a lot of complexity. As @pmario notes, #4977 should be merged soon; it is included in the list at #6086. |
Beta Was this translation helpful? Give feedback.
Hi @linonetwo the parser can be reused fairly easily already just by using
npm install tiddlywiki --save
and something like the following:At the moment our npm package is 18MB, which I don't think is excessive by modern standards. As you note, to strip things back to a minimum would likely involve a lot of complexity.
As @pmario notes, #4977 should be merged soon; it is included in the list at #6086.