GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing phabricator.wikimedia.org — T355493 Add more information to MediaWiki parse tree
Assigned To None Authored By
Project Tags Referenced Files None
Description The action=parse&prop=parsetree API returns an XML representation of how the MediaWiki preprocessor splits up the wikitext into template names, parameters, extension tags etc. Unfortunately this representation doesn't include the template markup itself, making it hard to reconstruct the wikitext from the parse tree, which would be very useful for template manipulations (e.g. remove or change a certain parameter of a certain template). Parsoid can't do that because it can't introspect nested templates ({{outer| {{inner| param }} }} which is common in e.g. infoboxes), regexes are brittle, and writing a client-side parser is more effort than what we should force clients to do. (In Python, mwparserfromhell can do it, but there is no similar JS parser.)
Related Objects Event TimelineRestricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 21 2024, 10:38 PM2024-01-21 22:38:00 (UTC+0) Comment Actions For example {{SomeTemplate|some-param}} is represented in the parse tree as <template><title>SomeTemplate</title><part><name index=\"1\"/><value>some-param</value></part></template> Instead, it could be something like <template><markup>{{</markup><title>SomeTemplate</title><part><markup>|</markup><name index=\"1\"/><value>some-param</value></part><markup>}}</markup></template>so that loading the parse tree into a DOM model and getting the textContent of the root element would return the original wikitext. This is a breaking change so we'd need a version parameter and support for both versions, which seems straightforward. Comment Actions The parsetree preserves whitespaces and the markup is represented by the tags, it is already possible to remap the wikitext from the parsetree, not that complex, but also not easy as with textContent. Some hints:
The wikitext in <inner> is not expanded, same reason as T4700. For a deep dive into templates you would need the inclusion parsetree, that needs T51353. Content licensed under Creative Commons Attribution-ShareAlike (CC BY-SA) 4.0 unless otherwise noted; code licensed under GNU General Public License (GPL) 2.0 or later and other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL · Credits | |||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |