Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exts/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
import sphinx

def setup(app):
app.add_javascript('booktools.js')
app.add_js_file('booktools.js')
5 changes: 2 additions & 3 deletions exts/block.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
from sphinx.util.compat import Directive
import shutil
import pdb
import os.path as path
from docutils.parsers.rst import directives
from docutils.parsers.rst import Directive, directives
from docutils import nodes

def build_finished(app, ex):
if app.builder.name == "latex":
import glob
curpath = path.split(__file__)[0]
for fn in glob.glob(path.join(curpath, "latexstyle", "*.*")):
print "copy %s" % fn
print("copy %s" % fn)
shutil.copy(fn, path.join(app.builder.outdir, path.split(fn)[-1]))

class timgblock(nodes.Part, nodes.Element):
Expand Down
4 changes: 2 additions & 2 deletions exts/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def process_images(self, docname, doctree):
imgtype = imghdr.what(f)
finally:
f.close()
except (OSError, IOError), err:
except (OSError, IOError) as err:
self.warn(docname, 'image file %s not '
'readable: %s' % (filename, err),
node.line)
Expand All @@ -69,7 +69,7 @@ def process_images(self, docname, doctree):
continue
self.images.add_file(docname, imgpath)

from sphinx.util import url_re, get_matching_docs, docname_join, \
from sphinx.util import url_re, docname_join, \
FilenameUniqDict

def add_file(self, docname, newfile):
Expand Down
4 changes: 2 additions & 2 deletions exts/latex_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import sphinx.writers.latex as latex

def setup(app):
latex.LaTeXTranslator.default_elements["babel"] = '\\usepackage[english]{babel}'
# latex.LaTeXTranslator.builder["babel"] = '\\usepackage[english]{babel}'
#latex.LaTeXTranslator.default_elements["inputenc"] = ''

pass
4 changes: 2 additions & 2 deletions exts/literal_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def run(self):
if linespec is not None:
try:
linelist = parselinenos(linespec, len(lines))
except ValueError, err:
except ValueError as err:
return [document.reporter.warning(str(err), line=self.lineno)]
lines = [lines[i] for i in linelist]

Expand All @@ -102,7 +102,7 @@ def run(self):
section = self.options.get("section")
if section is not None:
section = "###%s###" % section
print section
print(section)
use = False
res = []
for line in lines:
Expand Down
2 changes: 1 addition & 1 deletion exts/number_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def replace_html_code_labels(t):
return t

def setup(app):
print "number_label loaded"
print("number_label loaded")
old_depart_literal_block = latex.LaTeXTranslator.depart_literal_block
def depart_literal_block(self, node):
old_depart_literal_block(self, node)
Expand Down
4 changes: 2 additions & 2 deletions exts/number_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def doctree_read(app, doctree):
sec-test: 文章名, 标签名, 章节名,
"""
labels = app.env.domains["std"].data["labels"]
for name, _ in doctree.nametypes.iteritems():
for name, _ in doctree.nametypes.items():
if not name.startswith("sec-"): continue
labelid = doctree.nameids[name]
node = doctree.ids[labelid].parent
Expand All @@ -39,7 +39,7 @@ def doctree_read(app, doctree):
labels[name] = app.env.docname, labelid, sectname

def setup(app):
print "number_ref loaded"
print("number_ref loaded")
old_visit_reference = latex.LaTeXTranslator.visit_reference
def visit_reference(self, node):
uri = node.get('refuri', '')
Expand Down
20 changes: 10 additions & 10 deletions exts/smallseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ def __init__(self):
_curpath=os.path.normpath(os.path.join(os.getcwd(),_localDir))
curpath=_curpath
self.d = {}
print >> sys.stderr,"loading dict..."
self.set([x.rstrip() for x in file(os.path.join(curpath,"main.dic")) ])
self.specialwords= set([x.rstrip().decode('utf-8') for x in file(os.path.join(curpath,"suffix.dic"))])
print >> sys.stderr,'dict ok.'
print("loading dict...", file=sys.stderr)
self.set([x.rstrip() for x in open(os.path.join(curpath,"main.dic")) ])
self.specialwords= set([x.rstrip() for x in open(os.path.join(curpath,"suffix.dic"))])
print("dict ok.", file=sys.stderr)
#set dictionary(a list)
def set(self,keywords):
p = self.d
q = {}
k = ''
for word in keywords:
word = (chr(11)+word).decode('utf-8')
word = chr(11)+word
if len(word)>5:
continue
p = self.d
ln = len(word)
for i in xrange(ln-1,-1,-1):
for i in range(ln-1,-1,-1):
char = word[i].lower()
if p=='':
q[k] = {}
Expand All @@ -41,7 +41,7 @@ def _binary_seg(self,s):
if ln==1:
return [s]
R = []
for i in xrange(ln,1,-1):
for i in range(ln,1,-1):
tmp = s[i-2:i]
R.append(tmp)
return R
Expand All @@ -51,9 +51,9 @@ def _pro_unreg(self,piece):
R = []
tmp = re.sub(u"。|,|,|!|…|!|《|》|<|>|\"|'|:|:|?|\?|、|\||“|”|‘|’|;|—|(|)|·|\(|\)| "," ",piece).split()
ln1 = len(tmp)
for i in xrange(len(tmp)-1,-1,-1):
for i in range(len(tmp)-1,-1,-1):
mc = re.split(r"([0-9A-Za-z\-\+#@_\.]+)",tmp[i])
for j in xrange(len(mc)-1,-1,-1):
for j in range(len(mc)-1,-1,-1):
r = mc[j]
if re.search(r"([0-9A-Za-z\-\+#@_\.]+)",r)!=None:
R.append(r)
Expand Down Expand Up @@ -86,7 +86,7 @@ def cut(self,text):
elif mem2!=None:
delta = mem2[0]-i
if delta>=1:
if (delta<5) and (re.search(ur"[\w\u2E80-\u9FFF]",t)!=None):
if (delta<5) and (re.search(u"[\w\u2E80-\u9FFF]",t)!=None):
pre = text[i-j]
#print pre
if not (pre in self.specialwords):
Expand Down
2 changes: 1 addition & 1 deletion exts/zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SearchChinese(SearchLanguage):
lang = 'zh'

def init(self, options):
print "reading Chiniese dictionary"
print("reading Chiniese dictionary")
self.seg = SEG()

def split(self, input):
Expand Down
8 changes: 4 additions & 4 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
sys.path.append(os.path.abspath(_exts))
extensions = ['sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig', 'number_ref',
extensions = ['sphinx.ext.todo', 'sphinx.ext.imgmath', 'sphinx.ext.ifconfig', 'number_ref',
'number_label', 'literal_include', 'block', 'image', 'basic', "latex_fix"]

#extensions.append('nohighlight')
Expand Down Expand Up @@ -269,10 +269,10 @@
\titlerule]
%\definecolor{VerbatimBorderColor}{rgb}{0.2,0.2,0.2}
\definecolor{VerbatimColor}{rgb}{0.95,0.95,0.95}
""".decode("utf-8")
"""

latex_elements = {
"maketitle":ur"""
"maketitle":r"""
\maketitle
\renewcommand\contentsname{目 录}
\renewcommand\partname{部分}
Expand All @@ -283,7 +283,7 @@
\chapter*{前言}
\addcontentsline{toc}{chapter}{前言}
""",
"tableofcontents":ur"""
"tableofcontents":r"""
\tableofcontents
\fancyhead[LE,RO]{%s}
""" % TITLE
Expand Down