One could use a plain filter() to iterate over all the nodes, and test
each, to see if it is the template that you want to delete. Having detected
the template you want to delete, set a flag, and delete following text
nodes, until the next template node is detected.
On Tue, 21 Mar 2023, 18:28 Roy Smith, <roy(a)panix.com> wrote:
I've got some code which is essentially:
wikicode = mwp.parse(self.page.get())
for node in wikicode.filter_templates(recursive=False,
matches=title):
wikicode.remove(node)
self.page.text = str(wikicode)
self.page.save()
which works, but it leaves an extra blank line behind where the template
used to be. This is intended to be run on [[:en:Template talk:Did you
know/Approved]], i.e. one template per line.
What's the best way to get rid of the blank lines? I'm trying to avoid
just running a regex replacement on the raw text because that's fragile,
but maybe theres really no good alternative here?
_______________________________________________
pywikibot mailing list -- pywikibot(a)lists.wikimedia.org
Public archives at
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/m…
To unsubscribe send an email to pywikibot-leave(a)lists.wikimedia.org