wtf-plugin-wikitext

2.0.0 • Public • Published
a plugin for wtf_wikipedia

npm install wtf-plugin-wikitext

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

Readme

Keywords

none

Package Sidebar

Install

npm i wtf-plugin-wikitext

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

30.2 kB

Total Files

19

Last publish

Collaborators

  • spencermountain