Extending export formats
See original GitHub issueAnalysis of current code shows that the export of the generated Abstract Syntax Tree attaches toHtml()
, toMarkdown()
, toLatex()
to all levels of the AST:
Document
Section
Paragraph
Sentence
For extending the capabilties of awtf
as a wiki transformation framework someone would installnpm install wtf_wikipedia
and then require the module in the extension with
const wtf = require('wtf_wikipedia');
Assume we want to add/replace the existing default one with another export format or add a new export format my_format
, then the constructors need new export methods for the AST nodes - something like this:
wtf.ast.Document.prototype.my_format = function(options) {
....
return doc_in_my_format;
};
wtf.ast.Paragraph.prototype.my_format = function(options) {
....
return par_in_my_format;
};
wtf.ast.Section.prototype.my_format = function(options) {
....
return sec_in_my_format;
};
...
I guess the constructors for the AST nodes defined in src
can be expanded for another format if the AST node constructor are accessible in the required wtf_wikipedia
- i.e. the constructor e.g. of a Document
node in src/01-document/Document.js
is available in wtf
at wtf.ast.Document
. These access to the constructors could be added at src/index.js
with a require command.
wtf.ast = require('astnodes');
Or is there a better way to add plugins or extension for new export formats to wtf_wikipedia
without touching the current code base of wtf_wikipedia
, Spencer?
Cheers Bert
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
Excuse me Spencer, do not want to trigger a refactoring. Excuse me for that. Forgot about the fact that nodes like
Sentence
are used multiple times and therequire()
must be adapted, if the export consists of just a single method. Would recommend to export always a hash withmodule.export={...}
so that expanding the export hash does not require the adaptions of multipleconst mynode = require('0x-node')
imports. Thank you for all your feedback and thoughts, very valuable for me. Cheers, Berthey, this should all be possible now, as of v8! https://github.com/spencermountain/wtf_wikipedia/#configuration cheers