From 5853973db8ad641435dea755ac7e541b4e179eab Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Tue, 25 Jul 2017 18:18:49 +0300 Subject: [PATCH] More comments in markdown util. --- aiogram/utils/markdown.py | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/aiogram/utils/markdown.py b/aiogram/utils/markdown.py index 7c705a00..7e6b7cf6 100644 --- a/aiogram/utils/markdown.py +++ b/aiogram/utils/markdown.py @@ -28,48 +28,134 @@ def _md(string, symbols=('', '')): def text(*content, sep=' '): + """ + Join all elements with separator + + :param content: + :param sep: + :return: + """ return _join(*content, sep=sep) def bold(*content, sep=' '): + """ + Make bold text (Markdown) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[0]) def hbold(*content, sep=' '): + """ + Make bold text (HTML) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[4]) def italic(*content, sep=' '): + """ + Make italic text (Markdown) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[1]) def hitalic(*content, sep=' '): + """ + Make italic text (HTML) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[5]) def code(*content, sep=' '): + """ + Make mono-width text (Markdown) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[2]) def hcode(*content, sep=' '): + """ + Make mono-width text (HTML) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[6]) def pre(*content, sep='\n'): + """ + Make mono-width text block (Markdown) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[3]) def hpre(*content, sep='\n'): + """ + Make mono-width text block (HTML) + + :param content: + :param sep: + :return: + """ return _md(_join(*content, sep=sep), symbols=MD_SYMBOLS[7]) def link(title, url): + """ + Format URL (Markdown) + + :param title: + :param url: + :return: + """ return "[{0}]({1})".format(_escape(title), url) def hlink(title, url): + """ + Format URL (HTML) + + :param title: + :param url: + :return: + """ return "{1}".format(url, _escape(title)) def escape_md(*content, sep=' '): + """ + Escape markdown text + + E.g. for usernames + + :param content: + :param sep: + :return: + """ return _escape(_join(*content, sep=sep))