-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcsl-remove-class-from-dependents.py
47 lines (37 loc) · 1.52 KB
/
csl-remove-class-from-dependents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
# Python script to remove class from cs:style in dependents
# Author: Rintze M. Zelle
# Version: 2013-03-29
# * Requires lxml library (http://lxml.de/)
import os, glob, re, inspect
from lxml import etree
# http://stackoverflow.com/questions/50499
folderPath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentFolderPath = os.path.dirname (folderPath)
path = os.path.join(parentFolderPath, 'styles')
styles = []
for stylepath in glob.glob( os.path.join(path, 'dependent', '*.csl') ):
styles.append(os.path.join(stylepath))
for style in styles:
parser = etree.XMLParser(remove_blank_text=True)
parsedStyle = etree.parse(style, parser)
styleElement = parsedStyle.getroot()
fixedStyle = False
if "class" in styleElement.attrib:
del styleElement.attrib["class"]
fixedStyle = True
if (fixedStyle == False):
continue
try:
parsedStyle = etree.tostring(parsedStyle, pretty_print=True, xml_declaration=True, encoding="utf-8")
parsedStyle = parsedStyle.replace("'", '"', 4)
parsedStyle = parsedStyle.replace(" ", " ")#no-break space
parsedStyle = parsedStyle.replace("ᵉ", "ᵉ")
parsedStyle = parsedStyle.replace("‑", "‑")#non-breaking hyphen
parsedStyle = parsedStyle.replace("–", "–")#en dash
parsedStyle = parsedStyle.replace("—", "—")#em dash
f = open(style, 'w')
f.write ( parsedStyle )
f.close()
except:
pass