[Sync] Kazimir update. Typograph for Articles, Unicode HTML
This commit is contained in:
1 parent
68cb12051a
commit
7c0a4bb0ef
4 files changed
+58
-19
No files matched your search
@@ -1,7 +1,35 @@
|
||||
import lxml.html
|
||||
import requests
|
||||
from markdown import markdown
|
||||
|
||||
from kazimir.video import VideoExtension
|
||||
|
||||
|
||||
def kazimir_to_html(text):
|
||||
def markdown_to_html(text):
|
||||
return markdown(text, extensions=[VideoExtension()])
|
||||
|
||||
|
||||
def kazimir_to_html(text):
|
||||
html = markdown_to_html(text)
|
||||
return typo(html)
|
||||
|
||||
|
||||
def html_from_tree(tree):
|
||||
html = lxml.html.tostring(tree, encoding='unicode')
|
||||
html = typo(html)
|
||||
|
||||
return html
|
||||
|
||||
|
||||
def typo(html):
|
||||
url = 'http://api.tmshv.com/typograph/v1'
|
||||
res = requests.post(
|
||||
url=url,
|
||||
headers={
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
},
|
||||
data=html.encode('utf-8')
|
||||
)
|
||||
if res.status_code == 200:
|
||||
return res.text
|
||||
return html
|
||||
Reference in new issue
Block a user