- class mdfy.elements.text.MdText(content: str, formatter: MdFormatter | None = None, no_style: bool = False)[source]¶
Bases:
MdElementMdElementt class to handle the text and styling of text.
- formatter¶
The formatter to apply styling to the content.
- Type:
MdFormatter
Examples
>>> # If you have installed mdfy[styled-text] >>> from mdfy import MdText >>> try: >>> import lark >>> except ModuleNotFoundError: >>> print("Please install mdfy[styled-text] to use MdText with styles.") >>> exit(0) >>> >>> text = MdText("This is [bold:bold] text.") >>> print(text) This is **bold** text. >>> MdText("[This is underline text:underline].").to_str() <u>This is underline text</u>. >>> MdText("[This is [nested:bold] style text:underline].").to_str() <u>This is **nested** style text</u>. >>> MdText("You can use aliases e.g. [st:st] [bd:bo].").to_str() You can use aliases e.g. ***st*** **bd**.
Note
- Available style patterns:
strong: bold text (e.g. ***strong***)
bold: bold text (e.g. **bold**)
italic: italic text (e.g. *italic*)
not: strike-through text (e.g. ~~strike-through~~)
underline: underlined text (e.g. <u>underlined</u>)
code: inline code (e.g. code)
- Also, the following aliases are available for the style patterns:
strong: st
bold: bo, bd
italic: it
not: no, nt
underline: un, ul
code: cd, quote