Last active
August 29, 2015 14:07
-
-
Save squarepegsys/00f5b505a470a778b947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree | |
def bib2html(xmlString): | |
root = etree.fromstring(xmlString) | |
out = etree.Element("out") | |
for beg_verse in root.findall(".//verse[@sID]"): | |
this_verse = etree.tostring(beg_verse) | |
span = etree.Element("span") | |
out.append(span) | |
verse_text=this_verse[this_verse.find("/>")+2:] | |
span.attrib["class"]="verse" | |
span.attrib["id"]=beg_verse.attrib["sID"] | |
span2=etree.Element("span") | |
span2.attrib["class"]="nobreak" | |
span.append(span2) | |
vnum=etree.Element("span") | |
vnum.attrib["class"]="vnum" | |
vnum.text=beg_verse.attrib["sID"].split(".")[-1] | |
span2.append(vnum) | |
first,rest=verse_text.split(" ",1) | |
vnum.tail=" "+first | |
span2.tail=rest | |
return etree.tostring(out) | |
def test_judges_3_2(): | |
xmlString = '<start><verse osisID="Judg.3.2" sID="Judg.3.2"/>Only that the generations of the children of Israel might know, to teach them war, at the least such as before knew nothing thereof;<verse eID="Judg.3.2"/></start>' | |
out = bib2html(xmlString) | |
assert '<out><span class="verse" id="Judg.3.2"><span class="nobreak"><span class="vnum">2</span> Only</span>that the generations of the children of Israel might know, to teach them war, at the least such as before knew nothing thereof;</span></out>'==out | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment