-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5be815f
commit c73161b
Showing
3 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
from deepdiff import DeepDiff | ||
|
||
|
||
def test_slack_renderer_1(): | ||
from marko import Markdown | ||
from suisei.slack_markdown.renderer import SlackRenderer | ||
from suisei.slack_markdown.extensions import SLACK_EXTENSION | ||
|
||
MARKDOWN_TEXT = """ | ||
**Hello *world*** | ||
~~strike~~ | ||
```cpp | ||
#include <iostream> | ||
int main() { | ||
std::cout << "Hello, world!" << std::endl; | ||
return 0; | ||
} | ||
``` | ||
[Hello, world!](https://example.com) | ||
https://example.com | ||
![Hello, world!](https://example.com/hello.png) | ||
- List item 1 | ||
- List item 1.1 | ||
- List item 1.2 | ||
- List item 1.2 | ||
1. List item 1 | ||
2. List item 2 | ||
1. List item 2.1 | ||
1. List item 2.1 | ||
> Hello, world! | ||
> - Scramble Egg | ||
> - Bacon | ||
> - Ham | ||
> - ??? | ||
""" | ||
|
||
markdown = Markdown(renderer=SlackRenderer) | ||
markdown.use(SLACK_EXTENSION) | ||
parsed = markdown.parse(MARKDOWN_TEXT) | ||
rendered = markdown.render(parsed) | ||
rendered = SlackRenderer.postprocess(rendered) | ||
expected = [ | ||
{ | ||
"type": "rich_text", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{"type": "text", "text": "Hello ", "style": {"bold": True}}, | ||
{ | ||
"type": "text", | ||
"text": "world", | ||
"style": {"italic": True, "bold": True}, | ||
}, | ||
{"type": "text", "text": "\n"}, | ||
{"type": "text", "text": "strike", "style": {"strike": True}}, | ||
], | ||
}, | ||
{ | ||
"type": "rich_text_preformatted", | ||
"elements": [ | ||
{ | ||
"type": "text", | ||
"text": '#include <iostream>\n\nint main() {\n std::cout << "Hello, world!" << std::endl;\n return 0;\n}', | ||
} | ||
], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{ | ||
"type": "link", | ||
"url": "https://example.com", | ||
"text": "Hello, world!", | ||
} | ||
], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{ | ||
"type": "link", | ||
"url": "https://example.com", | ||
"text": "https://example.com", | ||
} | ||
], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{ | ||
"type": "link", | ||
"url": "https://example.com/hello.png", | ||
"text": "Hello, world!", | ||
} | ||
], | ||
}, | ||
{ | ||
"type": "rich_text_list", | ||
"style": "bullet", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 1"}], | ||
} | ||
], | ||
"indent": 0, | ||
}, | ||
{ | ||
"type": "rich_text_list", | ||
"style": "bullet", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 1.1"}], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 1.2"}], | ||
}, | ||
], | ||
"indent": 1, | ||
}, | ||
{ | ||
"type": "rich_text_list", | ||
"style": "bullet", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 1.2"}], | ||
} | ||
], | ||
"indent": 2, | ||
}, | ||
{ | ||
"type": "rich_text_list", | ||
"style": "ordered", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 1"}], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 2"}], | ||
}, | ||
], | ||
"indent": 0, | ||
}, | ||
{ | ||
"type": "rich_text_list", | ||
"style": "ordered", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 2.1"}], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "List item 2.1"}], | ||
}, | ||
], | ||
"indent": 1, | ||
}, | ||
{ | ||
"type": "rich_text_quote", | ||
"elements": [{"type": "text", "text": "Hello, world!"}], | ||
}, | ||
], | ||
}, | ||
{ | ||
"type": "rich_text", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_list", | ||
"style": "bullet", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "Scramble Egg"}], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "Bacon"}], | ||
}, | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "Ham"}], | ||
}, | ||
], | ||
"indent": 0, | ||
"border": 1, | ||
}, | ||
{ | ||
"type": "rich_text_list", | ||
"style": "bullet", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [{"type": "text", "text": "???"}], | ||
} | ||
], | ||
"indent": 1, | ||
"border": 1, | ||
}, | ||
], | ||
}, | ||
] | ||
|
||
assert not DeepDiff(rendered, expected) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.