View Single Post
Old 03-16-2015, 07:27 AM   #9
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 29,368
Karma: 211545324
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Find:
Code:
<([Hh][1-6])([^>]*)>(.*?)</\1>
Code:
import regex
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    text_str = regex.sub(r'''[-–—]''', ' ', match.group(3))
    text_str = regex.sub(r''' {2,}''', ' ', text_str)
    return '<{0}{1}>{2}</{0}>'.format(match.group(1), match.group(2), text_str)
I don't know about graceful (I've always been strangely comforted by the aesthetics of the python one-liner, myself), but the above won't have the ten-space-or-less limitation.

** added the possibility to work with header tags that may have attributes.

Last edited by DiapDealer; 03-16-2015 at 07:50 AM.
DiapDealer is online now   Reply With Quote