Commit 7b1af258 authored by Andrey Golovizin's avatar Andrey Golovizin

Use print function in doctests

parent 72a19913
......@@ -27,13 +27,13 @@ HTML output backend.
>>> from pybtex.richtext import Tag, HRef
>>> html = Backend()
>>> print Tag('em', '').render(html)
>>> print(Tag('em', '').render(html))
<BLANKLINE>
>>> print Tag('em', 'Hard &', ' heavy').render(html)
>>> print(Tag('em', 'Hard &', ' heavy').render(html))
<em>Hard &amp; heavy</em>
>>> print HRef('/', '').render(html)
>>> print(HRef('/', '').render(html))
<BLANKLINE>
>>> print HRef('/', 'Hard & heavy').render(html)
>>> print(HRef('/', 'Hard & heavy').render(html))
<a href="/">Hard &amp; heavy</a>
"""
from __future__ import unicode_literals
......@@ -57,7 +57,7 @@ PROLOGUE = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
class Backend(BaseBackend):
u"""
>>> from pybtex.richtext import Text, Tag, Symbol
>>> print Tag('em', Text(u'Л.:', Symbol('nbsp'), u'<<Химия>>')).render(Backend())
>>> print(Tag('em', Text(u'Л.:', Symbol('nbsp'), u'<<Химия>>')).render(Backend()))
<em>Л.:&nbsp;&lt;&lt;Химия&gt;&gt;</em>
"""
......@@ -91,3 +91,4 @@ class Backend(BaseBackend):
def write_entry(self, key, label, text):
self.output(u'<dt>%s</dt>\n' % label)
self.output(u'<dd>%s</dd>\n' % text)
......@@ -25,15 +25,15 @@ LaTeX output backend.
>>> from pybtex.richtext import Tag, HRef
>>> latex = Backend()
>>> print Tag('em', '').render(latex)
>>> print(Tag('em', '').render(latex))
<BLANKLINE>
>>> print Tag('em', 'Non-', 'empty').render(latex)
>>> print(Tag('em', 'Non-', 'empty').render(latex))
\\emph{Non-empty}
>>> print HRef('/', '').render(latex)
>>> print(HRef('/', '').render(latex))
<BLANKLINE>
>>> print HRef('/', 'Non-', 'empty').render(latex)
>>> print(HRef('/', 'Non-', 'empty').render(latex))
\\href{/}{Non-empty}
>>> print HRef('http://example.org/', 'http://example.org/').render(latex)
>>> print(HRef('http://example.org/', 'http://example.org/').render(latex))
\\url{http://example.org/}
"""
from __future__ import unicode_literals
......@@ -86,7 +86,7 @@ class Backend(BaseBackend):
def format_protected(self, text):
"""
>>> from pybtex.richtext import Protected
>>> print Protected('CTAN').render_as('latex')
>>> print(Protected('CTAN').render_as('latex'))
{CTAN}
"""
......@@ -105,3 +105,4 @@ class Backend(BaseBackend):
def write_entry(self, key, label, text):
self.output(u'\n\n\\bibitem[%s]{%s}\n' % (label, key))
self.output(text)
......@@ -28,13 +28,13 @@ Markdown output backend.
>>> from pybtex.richtext import Tag, HRef
>>> markdown = Backend()
>>> print Tag('em', '').render(markdown)
>>> print(Tag('em', '').render(markdown))
<BLANKLINE>
>>> print Tag('em', 'Non-', 'empty').render(markdown)
>>> print(Tag('em', 'Non-', 'empty').render(markdown))
*Non\-empty*
>>> print HRef('/', '').render(markdown)
>>> print(HRef('/', '').render(markdown))
<BLANKLINE>
>>> print HRef('/', 'Non-', 'empty').render(markdown)
>>> print(HRef('/', 'Non-', 'empty').render(markdown))
[Non\-empty](/)
"""
from __future__ import unicode_literals
......@@ -123,3 +123,4 @@ class Backend(BaseBackend):
else:
self.output(u'[%s] ' % label)
self.output(u'%s \n' % text)
......@@ -49,19 +49,19 @@ quote_or_comment = re.compile(r'[%"]')
def strip_comment(line):
"""Strip the commented part of the line."
>>> print strip_comment('a normal line')
>>> print(strip_comment('a normal line'))
a normal line
>>> print strip_comment('%')
>>> print(strip_comment('%'))
<BLANKLINE>
>>> print strip_comment('%comment')
>>> print(strip_comment('%comment'))
<BLANKLINE>
>>> print strip_comment('trailing%')
>>> print(strip_comment('trailing%'))
trailing
>>> print strip_comment('a normal line% and a comment')
>>> print(strip_comment('a normal line% and a comment'))
a normal line
>>> print strip_comment('"100% compatibility" is a myth')
>>> print(strip_comment('"100% compatibility" is a myth'))
"100% compatibility" is a myth
>>> print strip_comment('"100% compatibility" is a myth% or not?')
>>> print(strip_comment('"100% compatibility" is a myth% or not?'))
"100% compatibility" is a myth
"""
......@@ -165,3 +165,4 @@ if __name__ == '__main__':
import sys
from pprint import pprint
pprint(parse_file(sys.argv[1]))
......@@ -22,23 +22,23 @@
"""BibTeX-like name formatting.
>>> name = 'Charles Louis Xavier Joseph de la Vallee Poussin'
>>> print format_name(name, '{vv~}{ll}{, jj}{, f.}')
>>> print(format_name(name, '{vv~}{ll}{, jj}{, f.}'))
de~la Vallee~Poussin, C.~L. X.~J.
>>> name = 'abc'
>>> print format_name(name, '{vv~}{ll}{, jj}{, f.}')
>>> print(format_name(name, '{vv~}{ll}{, jj}{, f.}'))
abc
>>> name = 'Jean-Pierre Hansen'
>>> print format_name(name, '{ff~}{vv~}{ll}{, jj}')
>>> print(format_name(name, '{ff~}{vv~}{ll}{, jj}'))
Jean-Pierre Hansen
>>> print format_name(name, '{f.~}{vv~}{ll}{, jj}')
>>> print(format_name(name, '{f.~}{vv~}{ll}{, jj}'))
J.-P. Hansen
>>> name = 'F. Phidias Phony-Baloney'
>>> print format_name(name, '{v{}}{l}')
>>> print(format_name(name, '{v{}}{l}'))
P.-B
>>> print format_name(name, '{v{}}{l.}')
>>> print(format_name(name, '{v{}}{l.}'))
P.-B.
>>> print format_name(name, '{v{}}{l{}}')
>>> print(format_name(name, '{v{}}{l{}}'))
PB
"""
from __future__ import unicode_literals
......@@ -260,9 +260,9 @@ def join(words, tie='~', space=' '):
Otherwise space is inserted.
Should produce the same oubput as BibTeX.
>>> print join(['a', 'long', 'long', 'road'])
>>> print(join(['a', 'long', 'long', 'road']))
a~long long~road
>>> print join(['very', 'long', 'phrase'])
>>> print(join(['very', 'long', 'phrase']))
very long~phrase
"""
......@@ -365,3 +365,4 @@ class NameFormatParser(Scanner):
def eat_whitespace(self):
pass
......@@ -51,25 +51,25 @@ def wrap(string, width=79, subsequent_indent=' '):
(3 characters by default), so that each line contains at least one
non-whitespace character after the indent.
>>> print wrap('', width=3)
>>> print(wrap('', width=3))
<BLANKLINE>
>>> print wrap('0123456789 12345', width=10)
>>> print(wrap('0123456789 12345', width=10))
0123456789
12345
>>> print wrap('01234 6789 12345', width=10)
>>> print(wrap('01234 6789 12345', width=10))
01234 6789
12345
>>> print wrap('01234 6789 12345', width=11)
>>> print(wrap('01234 6789 12345', width=11))
01234 6789
12345
>>> print wrap('01234 6789 12345', width=9)
>>> print(wrap('01234 6789 12345', width=9))
01234
6789
12345
>>> print wrap(' a b c', width=3)
>>> print(wrap(' a b c', width=3))
a b
c
>>> print wrap('aa bb c', width=3)
>>> print(wrap('aa bb c', width=3))
aa bb
c
......@@ -151,25 +151,25 @@ class BibTeXString(object):
def change_case(string, mode):
r"""
>>> print change_case('aBcD', 'l')
>>> print(change_case('aBcD', 'l'))
abcd
>>> print change_case('aBcD', 'u')
>>> print(change_case('aBcD', 'u'))
ABCD
>>> print change_case('ABcD', 't')
>>> print(change_case('ABcD', 't'))
Abcd
>>> print change_case(r'The {\TeX book \noop}', 'u')
>>> print(change_case(r'The {\TeX book \noop}', 'u'))
THE {\TeX BOOK \noop}
>>> print change_case(r'And Now: BOOO!!!', 't')
>>> print(change_case(r'And Now: BOOO!!!', 't'))
And now: Booo!!!
>>> print change_case(r'And {Now: BOOO!!!}', 't')
>>> print(change_case(r'And {Now: BOOO!!!}', 't'))
And {Now: BOOO!!!}
>>> print change_case(r'And {Now: {BOOO}!!!}', 'l')
>>> print(change_case(r'And {Now: {BOOO}!!!}', 'l'))
and {Now: {BOOO}!!!}
>>> print change_case(r'And {\Now: BOOO!!!}', 't')
>>> print(change_case(r'And {\Now: BOOO!!!}', 't'))
And {\Now: booo!!!}
>>> print change_case(r'And {\Now: {BOOO}!!!}', 'l')
>>> print(change_case(r'And {\Now: {BOOO}!!!}', 'l'))
and {\Now: {booo}!!!}
>>> print change_case(r'{\TeX\ and databases\Dash\TeX DBI}', 't')
>>> print(change_case(r'{\TeX\ and databases\Dash\TeX DBI}', 't'))
{\TeX\ and databases\Dash\TeX DBI}
"""
......@@ -222,21 +222,21 @@ def bibtex_substring(string, start, length):
start and length are 1-based. If start is < 0, it is counted from the end
of the string. If start is 0, an empty string is returned.
>>> print bibtex_substring('abcdef', 1, 3)
>>> print(bibtex_substring('abcdef', 1, 3))
abc
>>> print bibtex_substring('abcdef', 2, 3)
>>> print(bibtex_substring('abcdef', 2, 3))
bcd
>>> print bibtex_substring('abcdef', 2, 1000)
>>> print(bibtex_substring('abcdef', 2, 1000))
bcdef
>>> print bibtex_substring('abcdef', 0, 1000)
>>> print(bibtex_substring('abcdef', 0, 1000))
<BLANKLINE>
>>> print bibtex_substring('abcdef', -1, 1)
>>> print(bibtex_substring('abcdef', -1, 1))
f
>>> print bibtex_substring('abcdef', -1, 2)
>>> print(bibtex_substring('abcdef', -1, 2))
ef
>>> print bibtex_substring('abcdef', -2, 3)
>>> print(bibtex_substring('abcdef', -2, 3))
cde
>>> print bibtex_substring('abcdef', -2, 1000)
>>> print(bibtex_substring('abcdef', -2, 1000))
abcde
"""
......@@ -258,29 +258,29 @@ def bibtex_len(string):
is a substring at brace level 1, if the first character after the opening
brace is a backslash, like in "de la Vall{\'e}e Poussin".
>>> print bibtex_len(r"de la Vall{\'e}e Poussin")
>>> print(bibtex_len(r"de la Vall{\'e}e Poussin"))
20
>>> print bibtex_len(r"de la Vall{e}e Poussin")
>>> print(bibtex_len(r"de la Vall{e}e Poussin"))
20
>>> print bibtex_len(r"de la Vallee Poussin")
>>> print(bibtex_len(r"de la Vallee Poussin"))
20
>>> print bibtex_len(r'\ABC 123')
>>> print(bibtex_len(r'\ABC 123'))
8
>>> print bibtex_len(r'{\abc}')
>>> print(bibtex_len(r'{\abc}'))
1
>>> print bibtex_len(r'{\abc')
>>> print(bibtex_len(r'{\abc'))
1
>>> print bibtex_len(r'}\abc')
>>> print(bibtex_len(r'}\abc'))
4
>>> print bibtex_len(r'\abc}')
>>> print(bibtex_len(r'\abc}'))
4
>>> print bibtex_len(r'\abc{')
>>> print(bibtex_len(r'\abc{'))
4
>>> print bibtex_len(r'level 0 {1 {2}}')
>>> print(bibtex_len(r'level 0 {1 {2}}'))
11
>>> print bibtex_len(r'level 0 {\1 {2}}')
>>> print(bibtex_len(r'level 0 {\1 {2}}'))
9
>>> print bibtex_len(r'level 0 {1 {\2}}')
>>> print(bibtex_len(r'level 0 {1 {\2}}'))
12
"""
length = 0
......@@ -330,19 +330,19 @@ def bibtex_prefix(string, num_chars):
resulting prefix ends at brace level > 0, missing closing braces are
appended.
>>> print bibtex_prefix('abc', 1)
>>> print(bibtex_prefix('abc', 1))
a
>>> print bibtex_prefix('abc', 5)
>>> print(bibtex_prefix('abc', 5))
abc
>>> print bibtex_prefix('ab{c}d', 3)
>>> print(bibtex_prefix('ab{c}d', 3))
ab{c}
>>> print bibtex_prefix('ab{cd}', 3)
>>> print(bibtex_prefix('ab{cd}', 3))
ab{c}
>>> print bibtex_prefix('ab{cd', 3)
>>> print(bibtex_prefix('ab{cd', 3))
ab{c}
>>> print bibtex_prefix(r'ab{\cd}', 3)
>>> print(bibtex_prefix(r'ab{\cd}', 3))
ab{\cd}
>>> print bibtex_prefix(r'ab{\cd', 3)
>>> print(bibtex_prefix(r'ab{\cd', 3))
ab{\cd}
"""
......@@ -362,33 +362,33 @@ def bibtex_prefix(string, num_chars):
def bibtex_purify(string):
r"""Strip special characters from the string.
>>> print bibtex_purify('Abc 1234')
>>> print(bibtex_purify('Abc 1234'))
Abc 1234
>>> print bibtex_purify('Abc 1234')
>>> print(bibtex_purify('Abc 1234'))
Abc 1234
>>> print bibtex_purify('Abc-Def')
>>> print(bibtex_purify('Abc-Def'))
Abc Def
>>> print bibtex_purify('Abc-~-Def')
>>> print(bibtex_purify('Abc-~-Def'))
Abc Def
>>> print bibtex_purify('{XXX YYY}')
>>> print(bibtex_purify('{XXX YYY}'))
XXX YYY
>>> print bibtex_purify('{XXX {YYY}}')
>>> print(bibtex_purify('{XXX {YYY}}'))
XXX YYY
>>> print bibtex_purify(r'XXX {\YYY} XXX')
>>> print(bibtex_purify(r'XXX {\YYY} XXX'))
XXX XXX
>>> print bibtex_purify(r'{XXX {\YYY} XXX}')
>>> print(bibtex_purify(r'{XXX {\YYY} XXX}'))
XXX YYY XXX
>>> print bibtex_purify(r'\\abc def')
>>> print(bibtex_purify(r'\\abc def'))
abc def
>>> print bibtex_purify('a@#$@#$b@#$@#$c')
>>> print(bibtex_purify('a@#$@#$b@#$@#$c'))
abc
>>> print bibtex_purify(r'{\noopsort{1973b}}1973')
>>> print(bibtex_purify(r'{\noopsort{1973b}}1973'))
1973b1973
>>> print bibtex_purify(r'{sort{1973b}}1973')
>>> print(bibtex_purify(r'{sort{1973b}}1973'))
sort1973b1973
>>> print bibtex_purify(r'{sort{\abc1973b}}1973')
>>> print(bibtex_purify(r'{sort{\abc1973b}}1973'))
sortabc1973b1973
>>> print bibtex_purify(r'{\noopsort{1973a}}{\switchargs{--90}{1968}}')
>>> print(bibtex_purify(r'{\noopsort{1973a}}{\switchargs{--90}{1968}}'))
1973a901968
"""
......@@ -514,19 +514,19 @@ def split_tex_string(string, sep=None, strip=True, filter_empty=False):
def bibtex_first_letter(string):
""" Return the first letter or special character of the string.
>>> print bibtex_first_letter('Andrew Blake')
>>> print(bibtex_first_letter('Andrew Blake'))
A
>>> print bibtex_first_letter('{Andrew} Blake')
>>> print(bibtex_first_letter('{Andrew} Blake'))
A
>>> print bibtex_first_letter('1Andrew')
>>> print(bibtex_first_letter('1Andrew'))
A
>>> print bibtex_first_letter('{\TeX} markup')
>>> print(bibtex_first_letter('{\TeX} markup'))
{\TeX}
>>> print bibtex_first_letter('')
>>> print(bibtex_first_letter(''))
<BLANKLINE>
>>> print bibtex_first_letter('123 123 123 {}')
>>> print(bibtex_first_letter('123 123 123 {}'))
<BLANKLINE>
>>> print bibtex_first_letter('\LaTeX Project Team')
>>> print(bibtex_first_letter('\LaTeX Project Team'))
L
"""
......@@ -543,11 +543,11 @@ def bibtex_abbreviate(string, delimiter=None, separator='-'):
"""
Abbreviate string.
>>> print bibtex_abbreviate('Andrew Blake')
>>> print(bibtex_abbreviate('Andrew Blake'))
A
>>> print bibtex_abbreviate('Jean-Pierre')
>>> print(bibtex_abbreviate('Jean-Pierre'))
J.-P
>>> print bibtex_abbreviate('Jean--Pierre')
>>> print(bibtex_abbreviate('Jean--Pierre'))
J.-P
"""
......@@ -561,3 +561,4 @@ def bibtex_abbreviate(string, delimiter=None, separator='-'):
if delimiter is None:
delimiter = '.-'
return delimiter.join(_bibtex_abbreviate())
......@@ -21,7 +21,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import print_function
import re
from collections import Mapping
......@@ -119,7 +119,7 @@ class BibliographyData(object):
>>> bib_data = parse_string(r"""
... @PREAMBLE{"\newcommand{\noopsort}[1]{}"}
... """, 'bibtex')
>>> print bib_data.preamble
>>> print(bib_data.preamble)
\newcommand{\noopsort}[1]{}
.. versionadded:: 0.19
......@@ -581,41 +581,41 @@ class Person(object):
"""Extract various parts of the name from a string.
>>> p = Person('Avinash K. Dixit')
>>> print p.first_names
>>> print(p.first_names)
[u'Avinash']
>>> print p.middle_names
>>> print(p.middle_names)
[u'K.']
>>> print p.prelast_names
>>> print(p.prelast_names)
[]
>>> print p.last_names
>>> print(p.last_names)
[u'Dixit']
>>> print p.lineage_names
>>> print(p.lineage_names)
[]
>>> print unicode(p)
>>> print(unicode(p))
Dixit, Avinash K.
>>> p == Person(unicode(p))
True
>>> p = Person('Dixit, Jr, Avinash K. ')
>>> print p.first_names
>>> print(p.first_names)
[u'Avinash']
>>> print p.middle_names
>>> print(p.middle_names)
[u'K.']
>>> print p.prelast_names
>>> print(p.prelast_names)
[]
>>> print p.last_names
>>> print(p.last_names)
[u'Dixit']
>>> print p.lineage_names
>>> print(p.lineage_names)
[u'Jr']
>>> print unicode(p)
>>> print(unicode(p))
Dixit, Jr, Avinash K.
>>> p == Person(unicode(p))
True
>>> p = Person('abc')
>>> print p.first_names, p.middle_names, p.prelast_names, p.last_names, p.lineage_names
>>> print(p.first_names, p.middle_names, p.prelast_names, p.last_names, p.lineage_names)
[] [] [] [u'abc'] []
>>> p = Person('Viktorov, Michail~Markovitch')
>>> print p.first_names, p.middle_names, p.prelast_names, p.last_names, p.lineage_names
>>> print(p.first_names, p.middle_names, p.prelast_names, p.last_names, p.lineage_names)
[u'Michail'] [u'Markovitch'] [] [u'Viktorov'] []
"""
def process_first_middle(parts):
......
......@@ -54,7 +54,7 @@ True
>>> rief97b = bib_data.entries['rief97b']
>>> authors = rief97b.persons['author']
>>> for author in authors:
... print unicode(author)
... print(unicode(author))
Rief, Matthias
Gautel, Mathias
Oesterhelt, Filipp
......@@ -62,9 +62,9 @@ Fernandez, Julio M.
Gaub, Hermann E.
# field names are case-insensitive
>>> print rief97b.fields['URL']
>>> print(rief97b.fields['URL'])
http://www.sciencemag.org/cgi/content/abstract/276/5315/1109
>>> print rief97b.fields['url']
>>> print(rief97b.fields['url'])
http://www.sciencemag.org/cgi/content/abstract/276/5315/1109
"""
......@@ -395,3 +395,4 @@ class Parser(BaseParser):
def parse_stream(self, stream):
text = stream.read()
return self.parse_string(text)
......@@ -37,16 +37,16 @@ class Writer(BaseWriter):
def quote(self, s):
"""
>>> w = Writer()
>>> print w.quote('The World')
>>> print(w.quote('The World'))
"The World"
>>> print w.quote(r'The \emph{World}')
>>> print(w.quote(r'The \emph{World}'))
"The \emph{World}"
>>> print w.quote(r'The "World"')
>>> print(w.quote(r'The "World"'))
{The "World"}
>>> try:
... print w.quote(r'The {World')
... print(w.quote(r'The {World'))
... except BibTeXError, error:
... print error
... print(error)
String has unmatched braces: The {World
"""
......@@ -69,13 +69,13 @@ class Writer(BaseWriter):
>>> try:
... w.check_braces('{')
... except BibTeXError, error:
... print error
... print(error)
String has unmatched braces: {
>>> w.check_braces('{test}}')
>>> try:
... w.check_braces('{{test}')
... except BibTeXError, error:
... print error
... print(error)
String has unmatched braces: {{test}
"""
......@@ -90,15 +90,15 @@ class Writer(BaseWriter):
ur"""Encode text as LaTeX.
>>> w = Writer(encoding='ASCII')
>>> print w._encode(u'1970–1971.')
>>> print(w._encode(u'1970–1971.'))
1970--1971.
>>> w = Writer(encoding='UTF-8')
>>> print w._encode(u'1970–1971.')
>>> print(w._encode(u'1970–1971.'))
1970–1971.
>>> w = Writer(encoding='UTF-8')
>>> print w._encode(u'100% noir')
>>> print(w._encode(u'100% noir'))
100\% noir
"""
import latexcodec # NOQA
......@@ -109,11 +109,11 @@ class Writer(BaseWriter):
ur"""Encode text as LaTeX, preserve comments.
>>> w = Writer(encoding='ASCII')
>>> print w._encode_with_comments(u'1970–1971. %% † RIP †')
>>> print(w._encode_with_comments(u'1970–1971. %% † RIP †'))
1970--1971. %% \dag\ RIP \dag
>>> w = Writer(encoding='UTF-8')
>>> print w._encode_with_comments(u'1970–1971. %% † RIP †')
>>> print(w._encode_with_comments(u'1970–1971. %% † RIP †'))
1970–1971. %% † RIP †
"""
return u'%'.join(self._encode(part) for part in text.split(u'%'))
......@@ -167,3 +167,4 @@ class Writer(BaseWriter):
for type, value in entry.fields.items():
self._write_field(stream, type, value)
stream.write(u'\n}\n')
......@@ -96,7 +96,7 @@ class Writer(BaseWriter):
>>> unicode_xml = Writer().to_string(data)
>>> isinstance(unicode_xml, unicode)
True
>>> print unicode_xml
>>> print(unicode_xml)
<bibtex:file xmlns:bibtex="http://bibtexml.sf.net/">
<BLANKLINE>
</bibtex:file>
......@@ -134,3 +134,4 @@ class Writer(BaseWriter):
writer.newline()
writer.end()
writer.close()
......@@ -24,37 +24,37 @@ r"""(simple but) rich text formatting tools
Usage:
>>> t = Text('this ', 'is a ', Tag('em', 'very'), Text(' rich', ' text'))
>>> print t.render_as('latex')
>>> print(t.render_as('latex'))
this is a \emph{very} rich text
>>> print unicode(t)
>>> print(unicode(t))
this is a very rich text
>>> t = t.capitalize().add_period()
>>> print t.render_as('latex')
>>> print(t.render_as('latex'))
This is a \emph{very} rich text.
>>> print unicode(t)
>>> print(unicode(t))
This is a very rich text.
>>> print Symbol('ndash').render_as('latex')
>>> print(Symbol('ndash').render_as('latex'))
--
>>> t = Text('Some ', Tag('em', Text('nested ', Tag('tt', 'Text', Text(' objects')))), '.')
>>> print t.render_as('latex')
>>> print(t.render_as('latex'))
Some \emph{nested \texttt{Text objects}}.
>>> print unicode(t)
>>> print(unicode(t))
Some nested Text objects.
>>> t = t.upper()
>>> print t.render_as('latex')
>>> print(t.render_as('latex'))
SOME \emph{NESTED \texttt{TEXT OBJECTS}}.
>>> print unicode(t)
>>> print(unicode(t))
SOME NESTED TEXT OBJECTS.
>>> t = Text(', ').join(['one', 'two', Tag('em', 'three')])
>>> print t.render_as('latex')
>>> print(t.render_as('latex'))
one, two, \emph{three}
>>> print unicode(t)
>>> print(unicode(t))
one, two, three
>>> t = Text(Symbol('nbsp')).join(['one', 'two', Tag('em', 'three')])
>>> print t.render_as('latex')
>>> print(t.render_as('latex'))
one~two~\emph{three}
>>> print unicode(t)
>>> print(unicode(t))
one<nbsp>two<nbsp>three
"""
from __future__ import unicode_literals
......@@ -72,9 +72,9 @@ import six
# workaround for doctests in Python 2/3
def str_repr(string):
"""
>>> print str_repr('test')
>>> print(str_repr('test'))
'test'
>>> print str_repr(u'test')
>>> print(str_repr(u'test'))
'test'
"""
......@@ -139,9 +139,9 @@ class BaseText(object):
but for tags and similar objects the appended text is placed _inside_ the tag.
>>> text = Tag('em', 'Look here')
>>> print (text + '!').render_as('html')
>>> print((text + '!').render_as('html'))
<em>Look here</em>!
>>> print text.append('!').render_as('html')
>>> print(text.append('!').render_as('html'))
<em>Look here!</em>
"""
......@@ -151,9 +151,9 @@ class BaseText(object):
"""Join a list using this text (like string.join)
>>> letters = ['a', 'b', 'c']
>>> print unicode(String('-').join(letters))
>>> print(unicode(String('-').join(letters)))
a-b-c
>>> print unicode(String('-').join(iter(letters)))
>>> print(unicode(String('-').join(iter(letters))))
a-b-c
"""
......@@ -201,11 +201,11 @@ class BaseText(object):
Add a period to the end of text, if the last character is not ".", "!" or "?".
>>> text = Text("That's all, folks")
>>> print unicode(text.add_period())
>>> print(unicode(text.add_period()))
That's all, folks.
>>> text = Text("That's all, folks!")
>>> print unicode(text.add_period())
>>> print(unicode(text.add_period()))
That's all, folks!
"""
......@@ -264,11 +264,11 @@ class BaseText(object):
and calls :py:meth:`Text.render`.
>>> text = Text('Longcat is ', Tag('em', 'looooooong'), '!')
>>> print text.render_as('html')
>>> print(text.render_as('html'))
Longcat is <em>looooooong</em>!
>>> print text.render_as('latex')
>>> print(text.render_as('latex'))
Longcat is \emph{looooooong}!
>>> print text.render_as('text')
>>> print(text.render_as('text'))
Longcat is looooooong!
:param backend_name: The name of the output backend (like ``"latex"`` or
......@@ -462,9 +462,9 @@ class BaseMultipartText(BaseText):
For Tags, HRefs, etc. the appended text is placed *inside* the tag.
>>> text = Tag('strong', 'Chuck Norris')
>>> print (text + ' wins!').render_as('html')
>>> print((text + ' wins!').render_as('html'))
<strong>Chuck Norris</strong> wins!
>>> print text.append(' wins!').render_as('html')
>>> print(text.append(' wins!').render_as('html'))
<strong>Chuck Norris wins!</strong>
"""
......@@ -692,9 +692,9 @@ class String(BaseText):
A :py:class:`String` is a wrapper for a plain Python string.
>>> from pybtex.richtext import String
>>> print String('Crime & Punishment').render_as('text')
>>> print(String('Crime & Punishment').render_as('text'))
Crime & Punishment
>>> print String('Crime & Punishment').render_as('html')
>>> print(String('Crime & Punishment').render_as('html'))
Crime &amp; Punishment
:py:class:`String` supports the same methods as :py:class:`Text`.
......@@ -706,7 +706,7 @@ class String(BaseText):
All arguments must be plain unicode strings.
Arguments are concatenated together.
>>> print unicode(String('November', ', ', 'December', '.'))
>>> print(unicode(String('November', ', ', 'December', '.')))
November, December.
"""
......@@ -825,9 +825,9 @@ class Tag(BaseMultipartText):
>>> from pybtex.richtext import Tag
>>> tag = Tag('em', 'The TeXbook')
>>> print tag.render_as('html')
>>> print(tag.render_as('html'))
<em>The TeXbook</em>