Skip to content

Instantly share code, notes, and snippets.

@alfredxing
Created August 10, 2014 17:21
Show Gist options
  • Save alfredxing/527e07f2d0429f4a063f to your computer and use it in GitHub Desktop.
Save alfredxing/527e07f2d0429f4a063f to your computer and use it in GitHub Desktop.
Replace font ID's for Brick SVG fonts
import glob
import os
import re
fonts = glob.glob('/Users/alfred/Documents/Git/brick/fonts/*/*.svg')
for font in fonts:
print 'Processing %s...' % font,
font_id = os.path.basename(os.path.dirname(font))
f = open(font, 'r')
contents = f.read()
contents = contents.replace('<svg>', '<svg version="1.1" xmlns="http://www.w3.org/2000/svg">')
contents = re.sub(r'<font id="[a-zA-Z-]+"', '<font id="%s"' % font_id, contents)
f.close()
f = open(font, 'w')
f.write(contents)
f.close()
print 'done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment