Quote:
Originally Posted by najgori
...or make simple program (in python): open file no. 1, read line, change whatever you want, write line in file no. 2. repeat untill the end.
|
If you already know basic Python commands, you might as well create an ad-hoc Sigil plugin. The following minimal
plugin.py code demonstrates how to use
replace() to replace
the with
<b>the
</b> and
re.sub() to replace
<i>...</i> with
<em>...</em>.
PHP Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, re
# main routine
def run(bk):
# iterate over all html files
for html_id, href in bk.text_iter():
# read orignal html code from file
original_html = bk.readfile(html_id)
# modify html code
modified_html = original_html.replace('the', '<b>the</b>')
modified_html = re.sub(r'(</*)i>', r'\1em>', modified_html )
if modified_html != original_html:
# write modified html code to file
bk.writefile(html_id, modified_html)
print(os.path.basename(href) + ' updated')
return 0
def main():
print('I reached main when I should not have\n')
return -1
if __name__ == "__main__":
sys.exit(main())