Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a library or API for wikitext template parameter modification #138

Open
NovemLinguae opened this issue Nov 2, 2022 · 0 comments
Open

Comments

@NovemLinguae
Copy link
Owner

NovemLinguae commented Nov 2, 2022

Pros:

  • Can handle nested templates and other tricky syntax that would cause bugs in a simpler system

Cons:

  • Need to use an API, which makes unit testing more difficult
  • Need to learn the library, which looks a bit complicated

Parsoid?

The "wikitext to lint" feature looks promising. https://www.mediawiki.org/wiki/Parsoid/API . only returns incorrect HTML/wikicode. doesn't return the abstract syntax tree

image

editProtectedHelper?

Izno says there's a user script that uses Parsoid to do the same thing at https://en.wikipedia.org/wiki/User:Jackmcbarn/editProtectedHelper.js

parsoid-document?

This looks like a possible Parsoid wrapper for user scripts: https://github.com/ChlodAlejandro/parsoid-document, https://chlodalejandro.github.io/parsoid-document/

Chlod comments on Discord:

importScript("User:Chlod/Scripts/ParsoidDocument/v2.js");
var parsoid = new ParsoidDocument();
parsoid.loadPage("Talk:Frank J. Wood Bridge", 1212075538);
parsoid.findTemplate("GA nominee")[0].setParameter("status", "onhold");
await parsoid.toWikitext();
// contains "|status=onhold"

https://github.com/ChlodAlejandro/parsoid-document/blob/master/src/ParsoidDocument.module.ts

"gets the HTML, puts it in an iframe, and then uses that to find templates, etc. in Parsoid, everything important is an HTML element, so it's almost the same thing as using the usual document.* functions"

Custom parser class?

Other option: I could write my own parser class, or look for a generic parser library. but then it would run into things like not recognizing tags and other wikicode-specific syntax, without lots of additional code anyway

Module:Template_parser?

Other option: feed it to https://en.wiktionary.org/wiki/Module:template_parser using the API. note the link is wiktionary, not wikipedia. "theknightwho — Today at 3:36 AM. Just so you know the limitations: the only objects it parses are templates, arguments and headings, and it won’t care if they’re valid or not (since the preprocessor doesn’t either) - however, that kind of thing is evaluated if you use any of the iterators, but obviously that means they’re slower
(By valid, I mean it doesn’t care that something like {{<}} can’t be a real template)"

@NovemLinguae NovemLinguae changed the title Use Parsoid for template parameter modification? Use a library or API for wikitext template parameter modification May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant