-
Notifications
You must be signed in to change notification settings - Fork 79
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
Support for expanding templates. #100
Comments
I don't know how I feel about this. You can do something similar yourself by iterating over the templates after I'm not too sure I like the idea of asking people to put a bunch of wikicode files in a directory, since template expansions are somewhat dynamic, and how are you going to decide which templates to put in the directory? I think a better idea is passing a callback function to What are some concrete use cases for this feature? |
I completely agree, and in fact, that's pretty much what smc.mw does under the hood. A template directory was just the most straightforward way I found of describing the feature without dwelling too much into its implementation :)
My usecase is having better support for templates in my pet project CitationHunt. Basically I'm parsing Wikipedia dumps looking for short snippets lacking citations. I use mwparserfromhell to help find I can definitely see your point that this could be done in the application, and my usecase is simple enough that it might be doable. On the other hand, having robust support for this, including parser functions, looks far from trivial, so it could be helpful to have the parser optionally handle it. |
Can you clarify the parser function thing - do you mean expanding parser function logic within the parser (e.g. the parser knows to convert Either way, the callback concept for expanding (regular) templates seems reasonable, so I'll implement that part. |
It would be great to have the former, as it would make it easy to support some very common but otherwise simple templates like IPAc-en, but I'm fine with not having it if you think it would be of little value in general. I suspect that simple expansion and maybe a few heuristics for dealing with broken text (such as removing empty parenthesis) could fix quite a lot of my broken snippets anyway.
Great, thanks! And thanks for being so responsive! 👍 |
I'm working on this for my wiki-scripts project - see the ws.parser_helpers.template_expansion module and the accompanying tests. The main function, I hope that I managed to cover most of the MediaWiki peculiarities regarding transclusion (or at least added notes into the code). There is one particular issue that bugs me though: according to the Transclusion#Transclusion markup documentation, the |
I also hacked together a recursive template expander as part of wiktionary parsing code (lexicator creates Wikidata lexemes), but due to Lua usage and complexity, I am beginning to reduce its usage in favor of asking MediaWiki to do this work for me using For example, template "Movie" is used on many pages, and internally it calls template "Infobox" with some useful strings that I would like to use after all the preparations done by the Movie template/lua code. I do not want to parse HTML generated by the Infobox, so I substitute Infobox template with my own version using |
It would be nice if the application could optionally specify, say, a directory containing templates (one per file), and have
parse
expand those recursively in the wikicode as needed, in addition to parser functions and other magic words, before returning the final AST.I realize this would be quite a lot of work, but it would go a long way towards MediaWiki compatibility. This feature already exists in the smc.mw parser, from which I stole the template directory idea. Thoughts?
The text was updated successfully, but these errors were encountered: