#!/opt/local/bin/python
import json
import os
import re
import string
import sys

myPath = os.path.dirname(os.path.realpath(__file__))

for i, line in enumerate(sys.stdin):
  (url, title, fileBase) = json.loads(line)
  fileName = fileBase + '.article'
  outFileName = fileName + '.opt'
  if os.path.exists(outFileName):
    sys.stderr.write('Skipping existing {0} {1}\n'.format(i, fileName))
  else:
    sys.stderr.write('Optimizing {0} {1}\n'.format(i, fileName))
    assert 0 == os.system('java -jar {myPath}/htmlcompressor.jar '
                 '--remove-intertag-spaces --simple-bool-attr --remove-quotes '
                  '--remove-js-protocol --type html '
                '-o {outFileName} {fileName}'
                 .format(myPath = myPath, fileName = fileName, outFileName = outFileName))

@@ -129,16 +129,87 @@
 le__))%0A%0A
+def formatPath(s):%0A  return s.replace('(', '%5C%5C(').replace(')', '%5C%5C)')%0A%0A
 for i, l
@@ -821,29 +821,91 @@
 ath,
- fileName = fileName,
+%0A                         fileName = formatPath(fileName),%0A                        
  out
@@ -915,16 +915,27 @@
 eName = 
+formatPath(
 outFileN
@@ -931,17 +931,18 @@
 th(outFileName))
+)
 %0A

Handle correctly paths with symbols '(' and ')'.