# Path: academicmarkdown/_BaseParser.py
# class BaseParser(object):
# 
# 	def __init__(self, verbose=False):
# 
# 		"""
# 		Constructor.
# 
# 		Keyword arguments:
# 		verbose		--	Indicates whether verbose output should be generated.
# 						(default=False)
# 		"""
# 
# 		self.verbose = verbose
# 
# 	def parse(self, md):
# 
# 		"""
# 		Parses a MarkDown text.
# 
# 		Arguments:
# 		md		--	The Markdown text.
# 
# 		Returns:
# 		The parsed Markdown text.
# 		"""
# 
# 		raise Exception(u'BaseParser.parse() should be overridden.')
# 
# 	def msg(self, msg):
# 
# 		"""
# 		Print output in verbose mode.
# 
# 		Arguments:
# 		msg		--	The message to print.
# 		"""
# 
# 		if self.verbose:
# 			print(safe_encode(u'[%s] %s' % (self.__class__.__name__, msg),
# 				enc=u'ascii', errors=u'ignore'))
# 
# 	def getPath(self, path):
# 
# 		"""
# 		Checks whether a path is present in the `srcFolder` and if so fixes it.
# 		URLs are accepted as valid paths.
# 
# 		Arguments:
# 		path		--	A path.
# 
# 		Returns:
# 		A path.
# 		"""
# 
# 		import os
# 		from academicmarkdown import build
# 		if path.startswith(u'http://'):
# 			return path
# 		for buildPath in build.path:
# 			_path = os.path.join(buildPath, path)
# 			if os.path.exists(_path):
# 				return _path
# 		if not os.path.exists(path):
# 			raise Exception(u'Cannot find file %s' % path)
# 		return path


import re
import shlex
import subprocess
from academicmarkdown import BaseParser
from academicmarkdown.py3compat import *
along with zoteromarkdown.  If not, see <http://www.gnu.org/licenses/>.
"""


# From <http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html>
feaderTmpl = """<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<script>
function subst() {
  var vars={};
  var x=document.location.search.substring(1).split('&');
  for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
  var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
  for(var i in x) {
    var y = document.getElementsByClassName(x[i]);
    for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
  }
}
</script>
%css%
</head><body onload="subst()">
<div class="%class%">%feader%</div>
</body></html>"""

class WkHtmlToPdf(BaseParser):

	def __init__(self, css=None, fix00=False, margins=(20, 20, 30, 20),
		spacing=(10, 10), header=None, footer=u'%page% / %topage%',

# Path: academicmarkdown/_BaseParser.py
# class BaseParser(object):
# 
# 	def __init__(self, verbose=False):
# 
# 		"""
# 		Constructor.
# 
# 		Keyword arguments:
# 		verbose		--	Indicates whether verbose output should be generated.
# 						(default=False)
# 		"""
# 
# 		self.verbose = verbose
# 
# 	def parse(self, md):
# 
# 		"""
# 		Parses a MarkDown text.
# 
# 		Arguments:
# 		md		--	The Markdown text.
# 
# 		Returns:
# 		The parsed Markdown text.
# 		"""
# 
# 		raise Exception(u'BaseParser.parse() should be overridden.')
# 
# 	def msg(self, msg):
# 
# 		"""
# 		Print output in verbose mode.
# 
# 		Arguments:
# 		msg		--	The message to print.
# 		"""
# 
# 		if self.verbose:
# 			print(safe_encode(u'[%s] %s' % (self.__class__.__name__, msg),
# 				enc=u'ascii', errors=u'ignore'))
# 
# 	def getPath(self, path):
# 
# 		"""
# 		Checks whether a path is present in the `srcFolder` and if so fixes it.
# 		URLs are accepted as valid paths.
# 
# 		Arguments:
# 		path		--	A path.
# 
# 		Returns:
# 		A path.
# 		"""
# 
# 		import os
# 		from academicmarkdown import build
# 		if path.startswith(u'http://'):
# 			return path
# 		for buildPath in build.path:
# 			_path = os.path.join(buildPath, path)
# 			if os.path.exists(_path):
# 				return _path
# 		if not os.path.exists(path):
# 			raise Exception(u'Cannot find file %s' % path)
# 		return path


# Path: academicmarkdown/_WkHtmlToPdf.py
import re
import shlex
import subprocess
from academicmarkdown import BaseParser
from academicmarkdown.py3compat import *

along with zoteromarkdown.  If not, see <http://www.gnu.org/licenses/>.
"""


# From <http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html>
feaderTmpl = """<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<script>
function subst() {
  var vars={};
  var x=document.location.search.substring(1).split('&');
  for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
  var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
  for(var i in x) {
    var y = document.getElementsByClassName(x[i]);
    for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
  }
}
</script>
%css%
</head><body onload="subst()">
<div class="%class%">%feader%</div>
</body></html>"""

class WkHtmlToPdf(BaseParser):

	def __init__(self, css=None, fix00=False, margins=(20, 20, 30, 20),
		spacing=(10, 10), header=None, footer=u'%page% / %topage%',

		verbose=False, args=''):