<commit_before># Copyright (C) 2006, 2007, 2008, 2009  <NAME>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

r"""(simple but) rich text formatting tools

Usage:
>>> from pybtex.backends import latex
>>> backend = latex.Writer()
>>> t = Text('this ', 'is a ', Tag('emph', 'very'), Text(' rich', ' text'))
>>> print t.render(backend)
this is a \emph{very} rich text
>>> print t.plaintext()
this is a very rich text
>>> t = t.capfirst().add_period()
>>> print t.render(backend)
This is a \emph{very} rich text.
>>> print t.plaintext()
This is a very rich text.
>>> print Symbol('ndash').render(backend)
--
>>> t = Text('Some ', Tag('emph', Text('nested ', Tag('texttt', 'Text', Text(' objects')))), '.')
>>> print t.render(backend)
Some \emph{nested \texttt{Text objects}}.
>>> print t.plaintext()
Some nested Text objects.
>>> from string import upper, lower
>>> t = t.map(upper)
>>> print t.render(backend)
SOME \emph{NESTED \texttt{TEXT OBJECTS}}.
>>> print t.plaintext()
SOME NESTED TEXT OBJECTS.

>>> t = Text(', ').join(['one', 'two', Tag('emph', 'three')])
>>> print t.render(backend)
one, two, \emph{three}
>>> print t.plaintext()
one, two, three
>>> t = Text(Symbol('nbsp')).join(['one', 'two', Tag('emph', 'three')])
>>> print t.render(backend)
one~two~\emph{three}
>>> print t.plaintext()
one<nbsp>two<nbsp>three
"""

from copy import deepcopy
from pybtex import textutils
import string

class Text(list):
    """
    Rich text is basically a list of
    - plain strings
    - Tag objects
    - other Text objects
    Text is used as an internal formatting language of Pybtex,
    being rendered to to HTML or LaTeX markup or whatever in the end.
    """

    def __init__(self, *parts):
        r"""Create a Text consisting of one or more parts."""

        list.__init__(self, parts)

    def __len__(self):
        return sum(len(part) for part in self)

    def __add__(self, other):
        """Concatenate this Text with another Text or string.
        >>> t = Text('a')
        >>> print (t + 'b').plaintext()
        ab
        >>> print (t + t).plaintext()
        aa
        >>> print t.plaintext()
        a<commit_msg>Make docstrings reST-compatible.<commit_after># Copyright (C) 2006, 2007, 2008, 2009  <NAME>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

r"""(simple but) rich text formatting tools

Usage:

>>> from pybtex.backends import latex
>>> backend = latex.Writer()
>>> t = Text('this ', 'is a ', Tag('emph', 'very'), Text(' rich', ' text'))
>>> print t.render(backend)
this is a \emph{very} rich text
>>> print t.plaintext()
this is a very rich text
>>> t = t.capfirst().add_period()
>>> print t.render(backend)
This is a \emph{very} rich text.
>>> print t.plaintext()
This is a very rich text.
>>> print Symbol('ndash').render(backend)
--
>>> t = Text('Some ', Tag('emph', Text('nested ', Tag('texttt', 'Text', Text(' objects')))), '.')
>>> print t.render(backend)
Some \emph{nested \texttt{Text objects}}.
>>> print t.plaintext()
Some nested Text objects.
>>> from string import upper, lower
>>> t = t.map(upper)
>>> print t.render(backend)
SOME \emph{NESTED \texttt{TEXT OBJECTS}}.
>>> print t.plaintext()
SOME NESTED TEXT OBJECTS.

>>> t = Text(', ').join(['one', 'two', Tag('emph', 'three')])
>>> print t.render(backend)
one, two, \emph{three}
>>> print t.plaintext()
one, two, three
>>> t = Text(Symbol('nbsp')).join(['one', 'two', Tag('emph', 'three')])
>>> print t.render(backend)
one~two~\emph{three}
>>> print t.plaintext()
one<nbsp>two<nbsp>three
"""

from copy import deepcopy
from pybtex import textutils
import string

class Text(list):
    """
    Rich text is basically a list of:

    - plain strings
    - Tag objects
    - other Text objects

    Text is used as an internal formatting language of Pybtex,
    being rendered to to HTML or LaTeX markup or whatever in the end.
    """

    def __init__(self, *parts):
        """Create a Text consisting of one or more parts."""

        list.__init__(self, parts)

    def __len__(self):
        """Return the number of characters in this Text."""
        return sum(len(part) for part in self)

    def __add__(self, other):
        """
        Concatenate this Text with another Text or string.

        >>> t = Text('a')
        >>> print (t + 'b').plaintext()
        ab
        >>> print (t + t).plaintext()
        aa
        >>> print t.plaintext()
        a
{'fraction_non_alphanumeric': 0.14877521613832853, 'fraction_numerical': 0.006123919308357349, 'mean_word_length': 3.5479115479115477, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836647', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1643, 'n_words': 661}