mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-08-26 05:07:35 -05:00
Fix text builder did not respect wide/fullwidth charactors for title line.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
Release 1.2 (in development)
|
Release 1.2 (in development)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
* Fix text builder did not respect wide/fullwidth charactors.
|
||||||
|
|
||||||
* #1062: sphinx.ext.autodoc use __init__ method signature for class signature.
|
* #1062: sphinx.ext.autodoc use __init__ method signature for class signature.
|
||||||
|
|
||||||
* PR#111: Respect add_autodoc_attrgetter() even when inherited-members is set.
|
* PR#111: Respect add_autodoc_attrgetter() even when inherited-members is set.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import re
|
|||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from docutils import nodes, writers
|
from docutils import nodes, writers
|
||||||
|
from docutils.utils import column_width
|
||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
from sphinx.locale import admonitionlabels, versionlabels, _
|
from sphinx.locale import admonitionlabels, versionlabels, _
|
||||||
@@ -165,7 +166,8 @@ class TextTranslator(nodes.NodeVisitor):
|
|||||||
char = '^'
|
char = '^'
|
||||||
text = ''.join(x[1] for x in self.states.pop() if x[0] == -1)
|
text = ''.join(x[1] for x in self.states.pop() if x[0] == -1)
|
||||||
self.stateindent.pop()
|
self.stateindent.pop()
|
||||||
self.states[-1].append((0, ['', text, '%s' % (char * len(text)), '']))
|
self.states[-1].append(
|
||||||
|
(0, ['', text, '%s' % (char * column_width(text)), '']))
|
||||||
|
|
||||||
def visit_subtitle(self, node):
|
def visit_subtitle(self, node):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
test_build_text
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Test the build process with Text builder with the test root.
|
||||||
|
|
||||||
|
:copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
|
||||||
|
:license: BSD, see LICENSE for details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
|
from docutils.utils import column_width
|
||||||
|
|
||||||
|
from util import *
|
||||||
|
|
||||||
|
|
||||||
|
def with_text_app(*args, **kw):
|
||||||
|
default_kw = {
|
||||||
|
'buildername': 'text',
|
||||||
|
'srcdir': '(empty)',
|
||||||
|
'confoverrides': {
|
||||||
|
'project': 'text',
|
||||||
|
'master_doc': 'contents',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
default_kw.update(kw)
|
||||||
|
return with_app(*args, **default_kw)
|
||||||
|
|
||||||
|
|
||||||
|
@with_text_app()
|
||||||
|
def test_multibyte_title_line(app):
|
||||||
|
title = u'\u65e5\u672c\u8a9e'
|
||||||
|
underline = u'=' * column_width(title)
|
||||||
|
content = u'\n'.join((title, underline, u''))
|
||||||
|
|
||||||
|
(app.srcdir / 'contents.rst').write_text(content, encoding='utf-8')
|
||||||
|
app.builder.build_all()
|
||||||
|
result = (app.outdir / 'contents.txt').text(encoding='utf-8')
|
||||||
|
|
||||||
|
expect_underline = underline.replace('=', '*')
|
||||||
|
result_underline = result.splitlines()[2].strip()
|
||||||
|
assert expect_underline == result_underline
|
||||||
@@ -142,6 +142,13 @@ class TestApp(application.Sphinx):
|
|||||||
temproot = tempdir / 'root'
|
temproot = tempdir / 'root'
|
||||||
test_root.copytree(temproot)
|
test_root.copytree(temproot)
|
||||||
srcdir = temproot
|
srcdir = temproot
|
||||||
|
elif srcdir == '(empty)':
|
||||||
|
tempdir = path(tempfile.mkdtemp())
|
||||||
|
self.cleanup_trees.append(tempdir)
|
||||||
|
temproot = tempdir / 'root'
|
||||||
|
temproot.makedirs()
|
||||||
|
(temproot / 'conf.py').write_text('')
|
||||||
|
srcdir = temproot
|
||||||
else:
|
else:
|
||||||
srcdir = path(srcdir)
|
srcdir = path(srcdir)
|
||||||
self.builddir = srcdir.joinpath('_build')
|
self.builddir = srcdir.joinpath('_build')
|
||||||
|
|||||||
Reference in New Issue
Block a user