the-riddle
clone your own copy | download snapshot

Snapshots | iceberg

Inside this repository

transform_keywords.py
text/x-python

Download raw (851 bytes)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
import glob
import codecs
import os.path
import argparse

parser = argparse.ArgumentParser("Insert image references")
parser.add_argument('folder', help="HTML sources folder")
args = parser.parse_args()

for bookfolder in glob.glob("{0}/book*".format(os.path.normpath(args.folder))):
  print "{0}".format(bookfolder)
  for htmlpath in glob.glob("{0}/*.html".format(os.path.normpath(bookfolder))):
    print "\t{0}".format(htmlpath)
    htmlstring = None

    with codecs.open(htmlpath, mode='r', encoding='utf-8') as htmlfile:
      htmlstring = htmlfile.read()
      htmlstring = re.sub(r'\+\+(.[^\+]+)\+\+', '<span class="keyword">\g<1></span>', htmlstring)
      
    if htmlstring:
      with codecs.open(htmlpath, mode='w', encoding='utf-8') as htmlfile:
        htmlfile.write(htmlstring)