kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
48 stars 6 forks source link

Accessing wikitext parser from wikiapi #17

Closed strefethen closed 3 years ago

strefethen commented 3 years ago

Hi kanasimi, I just started using this to parse content from wikipedia and I'm fetching infobox content and I would like to wikitext parse some sub-elements of the content. For example, the infobox has a string like this:

{{plainlist\n|*{{Jct|state=CA|SR|24}} in Oakland\n*{{Jct|state=CA|SR|123}} in [[Berkeley, California|Berkeley]]<!--might as well include it, since there are two lines-->\n}}

I'd like to use the parser to parse this string to allow easier processing and it's not clear to me if this is possible with the current implementation. Ultimately, it looks like surfacing the parsing in CeJS to wikiapi but am I missing some alternative?

Thanks, -Steve

kanasimi commented 3 years ago

You may try:

wikitext =`{{plainlist
|*{{Jct|state=CA|SR|24}} in Oakland
*{{Jct|state=CA|SR|123}} in [[Berkeley, California|Berkeley]]<!--might as well include it, since there are two lines-->
}}`;
parsed = CeL.wiki.parse(wikitext);

and using parsed to do something.

You may also try the wikitext parser to see what parsed looks like.

strefethen commented 3 years ago

Ah, thanks! I imported CeL and that worked.