Created
October 1, 2013 16:56
-
-
Save nkallen/6781648 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env coffee | |
fs = require('fs') | |
libxml = require('libxmljs') | |
file = fs.readFileSync(path = process.argv[2], 'utf8') | |
console.log(path) | |
xml = libxml.parseXml(file) | |
for quote in xml.find("//q") | |
firstLineInQuote = true | |
lastLineInQuote = null | |
for child in quote.childNodes() | |
quote.addPrevSibling(child) | |
if child.name() == 'l' | |
lastLineInQuote = child | |
if firstLineInQuote | |
firstTextNodeInLine = (node for node in child.childNodes() when node.name() == 'text')[0] | |
firstTextNodeInLine.addPrevSibling(xml.root().node('milestone').attr({unit: 'start-quote'})) | |
firstLineInQuote = false | |
if lastLineInQuote | |
lastLineInQuote.node('milestone').attr({unit: 'end-quote'}) | |
quote.remove() | |
fs.writeSync(fs.openSync("#{path}", 'w'), xml.toString()) |
This file contains 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
#!/usr/bin/env coffee | |
fs = require('fs') | |
greek = require('pseudw-util').greek | |
libxml = require('libxmljs') | |
file = fs.readFileSync(path = process.argv[2], 'utf8') | |
console.log(path) | |
xml = libxml.parseXml(file) | |
sampleLineNumber = xml.get(".//l[@n != '']")?.attr('n')?.value() | |
if !Number.isNaN(Number(sampleLineNumber)) | |
for b in xml.find("//body/div[@type='book']|//body/div[@type='act']") | |
count = 1 | |
for l in b.find("./p/l|./sp/p/l") | |
n = l.attr('n')?.value() | |
if n | |
if !Number.isNaN(Number(n)) | |
count = Number(n) | |
else | |
throw [n, count] | |
l.attr('n', count++) | |
fs.writeSync(fs.openSync("#{path}", 'w'), xml.toString()) |
This file contains 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
#!/usr/bin/env coffee | |
fs = require('fs') | |
libxml = require('libxmljs') | |
file = fs.readFileSync(path = process.argv[2], 'utf8') | |
console.log(path) | |
xml = libxml.parseXml(file) | |
for parent in xml.find("//l/..") | |
throw "Not sure what to do with #{parent.name()}" unless parent.name() in ['div', 'div1'] | |
para = null | |
container = [] | |
for child in parent.childNodes() | |
child.remove() | |
switch child.name() | |
when 'l' | |
if child.get("./milestone[@unit='para']") || child.get("./milestone[@unit='Para']") || !para | |
para = new libxml.Element(xml, 'lg') | |
container.push(para) | |
para.addChild(child) | |
else | |
if para | |
para.addChild(child) | |
else | |
container.push(child) | |
for child in container | |
parent.addChild(child) | |
fs.writeSync(fs.openSync("#{path}", 'w'), xml.toString()) |
This file contains 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
#!/usr/bin/env coffee | |
fs = require('fs') | |
libxml = require('libxmljs') | |
path = process.argv[2] | |
console.log(path) | |
file = fs.readFileSync(path) | |
doc = libxml.parseXml(file) | |
fs.writeSync(fs.openSync("#{path}", 'w'), doc.toString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment