Skip to content

Commit

Permalink
Add Quote style (#59)
Browse files Browse the repository at this point in the history
* Add tests

* Add `Quote` style

* Update docs

* Prepare a new release
  • Loading branch information
SKY-ALIN authored Jan 13, 2024
1 parent a9cba71 commit 83dde8e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.0 (13.01.2024)
* Add `Emoji` element
* Add `Quote` style
* Add support fort Python 3.12
* Drop support for Python 3.7

## 0.1.2 (30.05.2023)
* Fix issue #39 (Incorrect LICENSE file inclusion)

Expand Down
5 changes: 5 additions & 0 deletions docs/source/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ You can import as :code:`from telegram_text import ...` following elements:
* :class:`telegram_text.styles.Code`
* :class:`telegram_text.styles.InlineCode`
* :class:`telegram_text.styles.Italic`
* :class:`telegram_text.styles.Quote`
* :class:`telegram_text.styles.Spoiler`
* :class:`telegram_text.styles.Strikethrough`
* :class:`telegram_text.styles.Underline`
Expand Down Expand Up @@ -88,6 +89,10 @@ telegram\_text.styles
:members:
:show-inheritance:

.. autoclass:: telegram_text.styles.Quote
:members:
:show-inheritance:


telegram\_text.elements
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = 'Vladimir Alinsky'

# The full version, including alpha/beta/rc tags
release = '0.1.2'
release = '0.2.0'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "telegram_text"
version = "0.1.2"
version = "0.2.0"
description = "Python markup module for Telegram messenger. This module provides a rich list of components to build any possible markup fast and render it to specific html or MarkdownV2 formats."
authors = ["Vladimir Alinsky <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 3 additions & 2 deletions telegram_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from .custom import TOMLSection
from .elements import Emoji, Hashtag, InlineUser, Link, User
from .markdown import OrderedList, UnorderedList
from .styles import Bold, Code, InlineCode, Italic, Spoiler, Strikethrough, Underline
from .styles import Bold, Code, InlineCode, Italic, Quote, Spoiler, Strikethrough, Underline

__version__ = '0.1.2'
__version__ = '0.2.0'
__all__ = [
"Chain",
"PlainText",
Expand All @@ -14,6 +14,7 @@
"Code",
"InlineCode",
"Italic",
"Quote",
"Spoiler",
"Strikethrough",
"Underline",
Expand Down
18 changes: 18 additions & 0 deletions telegram_text/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,21 @@ def to_html(self) -> str:
if self.html_class:
return f'<pre>{super().to_html()}</pre>'
return f'<pre>{self.text.to_html()}</pre>'


class Quote(Style):
"""Quote block.
See an example below.
Block quotation started
Block quotation continued
The last line of the block quotation
"""

markdown_symbol = '>'
html_tag = 'blockquote'

def to_markdown(self) -> str:
return self.markdown_symbol + f'\n{self.markdown_symbol}'.join(self.text.to_markdown().split('\n'))
2 changes: 1 addition & 1 deletion tests/test_meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == '0.1.2'
assert __version__ == '0.2.0'
27 changes: 26 additions & 1 deletion tests/test_styles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from telegram_text.bases import PlainText
from telegram_text.styles import Bold, Code, InlineCode, Italic, Spoiler, Strikethrough, Underline
from telegram_text.styles import Bold, Code, InlineCode, Italic, Quote, Spoiler, Strikethrough, Underline

testing_string = "Hello world"

Expand Down Expand Up @@ -87,3 +87,28 @@ def test_code_block_with_language():
assert str(obj) == f'```{language}\n' + testing_string + '```'
assert obj.to_markdown() == f'```{language}\n' + testing_string + '```'
assert obj.to_html() == f'<pre><code class="language-{language}">' + testing_string + '</code></pre>'


def test_quote_block():
obj = Quote(
"Block quotation started\n"
"Block quotation continued\n"
"The last line of the block quotation"
)
assert obj.to_plain_text() == (
"Block quotation started\n"
"Block quotation continued\n"
"The last line of the block quotation"
)
assert obj.to_markdown() == (
">Block quotation started\n"
">Block quotation continued\n"
">The last line of the block quotation"
)
assert obj.to_html() == (
"<blockquote>"
"Block quotation started\n"
"Block quotation continued\n"
"The last line of the block quotation"
"</blockquote>"
)

0 comments on commit 83dde8e

Please sign in to comment.