#-----------------------------------------------------------------------------# Copyright (c) 2012 - 2023, Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Text-related models'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Bokeh importsfrom..core.has_propsimportabstractfrom..core.propertiesimport(Bool,Dict,Either,Int,Required,String,Tuple,)from..modelimportModel#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=("Ascii","MathML","MathText","PlainText","TeX",)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------@abstractclassBaseText(Model):""" Base class for renderers of text content of various kinds. """def__init__(self,*args,**kwargs)->None:iflen(args)==1and"text"notinkwargs:kwargs["text"]=args[0]super().__init__(**kwargs)text=Required(String,help=""" The text value to render. """)
[docs]@abstractclassMathText(BaseText):""" Base class for renderers of mathematical content. """# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)
[docs]classAscii(MathText):""" Render mathematical content using `AsciiMath <http://asciimath.org/>`_ notation. """# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)
[docs]classMathML(MathText):""" Render mathematical content using `MathML <https://www.w3.org/Math/>`_ notation. See :ref:`ug_styling_mathtext` in the |user guide| for more information. """# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)
[docs]classTeX(MathText):""" Render mathematical content using `LaTeX <https://www.latex-project.org/>`_ notation. See :ref:`ug_styling_mathtext` in the |user guide| for more information. .. note:: Bokeh uses `MathJax <https://www.mathjax.org>`_ to render text containing mathematical notation. MathJax only supports math-mode macros (no text-mode macros). You can see more about differences between standard TeX/LaTeX and MathJax here: https://docs.mathjax.org/en/latest/input/tex/differences.html """# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)macros=Dict(String,Either(String,Tuple(String,Int)),help=""" User defined TeX macros. This is a mapping from control sequence names (without leading backslash) to either replacement strings or tuples of a replacement string and a number of arguments. Example: .. code-block:: python TeX(text=r"\\R \\rightarrow \\R^2", macros={"RR": r"{\\bf R}"}) """)inline=Bool(default=False,help=""" Whether the math text is inline display or not (for TeX input). Default is False. """)
[docs]classPlainText(BaseText):""" Represents plain text in contexts where text parsing is allowed. """# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------