wtf-plugin-wikitext
v2.0.0
Published
wikitext output plugin for wtf_wikipedia
Downloads
13
Readme
Output all, or part of a wikipedia article in wiki-script.
const wtf = require('wtf_wikipedia')
wtf.extend(require('wtf-plugin-wikitext'))
let doc = wtf('hello [[world]]')
doc.makeWikitext()
// 'hello [[world]]'
<script src="https://unpkg.com/wtf_wikipedia"></script>
<script src="https://unpkg.com/wtf-plugin-wikitext"></script>
<script defer>
wtf.plugin(window.wtfWikitext)
wtf.fetch('Hamburg').then((doc) => {
console.log(doc.sentences()[0].makeWikitext())
// Hamburg is the [[List of cities in Germany by population|second-largest city]] in Germany after [[Berlin]]
})
</script>
all wtf_wikipedia models have a .wikitext()
method that (tries to) return their original wikitext.
This method will try to _generate* the wikitext, as best it can. This is a lossy, and error-prone process, but may be useful for some applications.
let doc = wtf(`hello [[world]]. {{cool|fun=yes}}`)
let tmpl = doc.template()
console.log(tmpl.makeWikitext())
// {{cool| fun = yes}}
tmpl.data.more = 'yes'
console.log(tmpl.makeWikitext())
// {{cool| fun = yes| more = yes}}
Concievably, this could be part of a edit-bot workflow, although there are many unresolved problems still, to doing so.
work-in-progress!
PRs welcome
MIT