Merge branch 'CyberTailor-master'

This commit is contained in:
Casey 2023-05-13 08:09:18 +03:00
commit 9cfbcf635a
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 9 additions and 7 deletions

View File

@ -151,6 +151,8 @@ def node_to_html(el: PageElement) -> str:
def node_to_markdown(el: PageElement) -> str: def node_to_markdown(el: PageElement) -> str:
""" Convert HTML to Markdown (Discord flavor) """
TAG_TRANSFORMS: Dict[ TAG_TRANSFORMS: Dict[
str, str,
Callable[ Callable[
@ -168,19 +170,19 @@ def node_to_markdown(el: PageElement) -> str:
str.join("", map(node_to_markdown, tag.children)) + "\n\n" str.join("", map(node_to_markdown, tag.children)) + "\n\n"
), ),
"i": lambda tag: ( "i": lambda tag: (
"_%s_" % str.join("", map(node_to_markdown, tag.children))
),
"b": lambda tag: (
"*%s*" % str.join("", map(node_to_markdown, tag.children)) "*%s*" % str.join("", map(node_to_markdown, tag.children))
), ),
"b": lambda tag: (
"**%s**" % str.join("", map(node_to_markdown, tag.children))
),
"s": lambda tag: ( "s": lambda tag: (
"~%s~" % str.join("", map(node_to_markdown, tag.children)) "~~%s~~" % str.join("", map(node_to_markdown, tag.children))
), ),
"u": lambda tag: ( "u": lambda tag: (
"__%s__" % str.join("", map(node_to_markdown, tag.children)) "__%s__" % str.join("", map(node_to_markdown, tag.children))
), ),
"pre": lambda tag: ( "pre": lambda tag: (
"\n``%s``\n" % str.join("", map(node_to_markdown, tag.children)) "\n```%s```\n" % str.join("", map(node_to_markdown, tag.children))
), ),
"code": lambda tag: ( "code": lambda tag: (
"`%s`" % str.join("", map(node_to_markdown, tag.children)) "`%s`" % str.join("", map(node_to_markdown, tag.children))
@ -194,7 +196,7 @@ def node_to_markdown(el: PageElement) -> str:
% str.join( % str.join(
"\n", "\n",
( (
"\u258d%s" % part "> %s" % part
for part in str.join( for part in str.join(
"", map(node_to_markdown, tag.children) "", map(node_to_markdown, tag.children)
).split("\n") ).split("\n")
@ -208,7 +210,7 @@ def node_to_markdown(el: PageElement) -> str:
% str.join( % str.join(
"\n", "\n",
( (
" \u2022 " "* "
+ node_to_markdown(li).replace("\n", "\n ").rstrip() + node_to_markdown(li).replace("\n", "\n ").rstrip()
for li in tag.children for li in tag.children
), ),