Today was a beautiful early spring day here in New York (my apologies to those 
of you in the "winter is approaching" hemisphere) so I decided to move away 
from the keyboard and went out for a bike ride.  Along the way, I pretty much 
came to the same conclusion, and now that I'm back, it's nice to see 
confirmation that I was thinking in the right direction.  Thanks!



> On Mar 21, 2023, at 5:20 PM, William Avery <willm.av...@gmail.com> wrote:
> 
> 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, <r...@panix.com 
> <mailto:r...@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@lists.wikimedia.org 
> <mailto:pywikibot@lists.wikimedia.org>
> Public archives at 
> https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/SRJVFLJSSFFMAWE6HMNLUH6A2HO23SDX/
>  
> <https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/SRJVFLJSSFFMAWE6HMNLUH6A2HO23SDX/>
> To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org 
> <mailto:pywikibot-le...@lists.wikimedia.org>
> _______________________________________________
> pywikibot mailing list -- pywikibot@lists.wikimedia.org
> Public archives at 
> https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/PH6WBAERXKIAQHQNDGWKOH5BUC5TWVZL/
> To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org

_______________________________________________
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/3OYCNMN6WNMFXWJIVCOF6BUBJECOLOQJ/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org

Reply via email to