-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.py
35 lines (25 loc) · 930 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
import codecs
import json
from draftjs_exporter.html import HTML
from draftjs_exporter_markdown import BLOCK_MAP, ENGINE, ENTITY_DECORATORS, STYLE_MAP
content_state = {}
# Demo content from https://github.com/springload/draftjs_exporter/blob/main/example.py.
with open('docs/example.json') as example:
content_state = json.load(example)
if __name__ == '__main__':
exporter = HTML({
'block_map': BLOCK_MAP,
'style_map': STYLE_MAP,
'entity_decorators': ENTITY_DECORATORS,
'engine': ENGINE,
})
markup = exporter.render(content_state)
print(markup)
# Output to a Markdown file to showcase the output in GitHub (and see changes in git).
with codecs.open('docs/example.txt', 'w', 'utf-8') as file:
file.write(
"""# Example output (generated by [`example.py`](../example.py))
---
{markdown}---
""".format(markdown=markup))