summaryrefslogtreecommitdiff
path: root/pygments/formatters/html.py
diff options
context:
space:
mode:
authorPepijn de Vos <pepijndevos@gmail.com>2012-07-14 17:22:07 -0400
committerPepijn de Vos <pepijndevos@gmail.com>2012-07-14 17:22:07 -0400
commitae937928326e68a1db4fae14c4d71e5819e00667 (patch)
tree39684874e367a1ed7d5b68ec460a005fdc44b52d /pygments/formatters/html.py
parentcc2a9d413902998dd338633ff587945e60b8e600 (diff)
downloadpygments-ae937928326e68a1db4fae14c4d71e5819e00667.tar.gz
multifile support
Example usage: #!/bin/bash for f in $@ do mkdir -p `dirname "output/$f.html"` ./pygmentize -f html -O anchorlinenos,linenos,full,tagurlprefix=`pwd`/,singlepage=False,lineanchors=L,tagsfile=tags -o "output/$f.html" "$f" done
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r--pygments/formatters/html.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 2a5454b2..6b308d59 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -356,6 +356,9 @@ class HtmlFormatter(Formatter):
self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
+ self.tagurlprefix = self._decodeifneeded(options.get('tagurlprefix', ''))
+ self.linkfext = self._decodeifneeded(options.get('linkfext', '.html'))
+ self.singlepage = get_bool_opt(options, 'singlepage', True)
if self.tagsfile:
try:
@@ -653,9 +656,14 @@ class HtmlFormatter(Formatter):
# for <span style=""> lookup only
getcls = self.ttype2class.get
c2s = self.class2style
- tagsfile = self.tagsfile
escape_table = _escape_html_table
+ tagsfile = self.tagsfile
+ singlepage = self.singlepage
+ if not singlepage:
+ tagurlprefix = self.tagurlprefix
+ linkfext = self.linkfext
+
lspan = ''
line = ''
for ttype, value in tokensource:
@@ -674,7 +682,10 @@ class HtmlFormatter(Formatter):
if tagsfile and ttype in Token.Name:
filename, lineNumber = self._lookup_ctag(value)
if filename:
- parts[0] = "<a href=\"#%s-%s\">%s" % (self.lineanchors, lineNumber, parts[0])
+ if singlepage:
+ parts[0] = "<a href=\"#%s-%s\">%s" % (self.lineanchors, lineNumber, parts[0])
+ else:
+ parts[0] = "<a href=\"%s%s%s#%s-%s\">%s" % (tagurlprefix, filename, linkfext, self.lineanchors, lineNumber, parts[0])
parts[-1] = "%s</a>" % parts[-1]
# for all but the last line