Added html function
This commit is contained in:
parent
a7d96ea52f
commit
83a025e6b1
16
__init__.py
16
__init__.py
|
@ -3,6 +3,7 @@ import pathlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
current_dir = pathlib.Path(__file__).parent
|
current_dir = pathlib.Path(__file__).parent
|
||||||
|
extensions = ['meta', 'nl2br']
|
||||||
|
|
||||||
with (current_dir / "base_feed.xml").open("r") as f:
|
with (current_dir / "base_feed.xml").open("r") as f:
|
||||||
base_feed = f.read()
|
base_feed = f.read()
|
||||||
|
@ -16,18 +17,23 @@ def convert_case(string: str):
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def convert_markdown_to_html(article_path: pathlib.Path):
|
||||||
|
with (article_path / "article.md").open("r") as f:
|
||||||
|
markdown_data = f.read()
|
||||||
|
|
||||||
|
markdown_instance = markdown.Markdown(extensions=extensions)
|
||||||
|
html = markdown_instance.convert(markdown_data)
|
||||||
|
metadata = markdown_instance.Meta
|
||||||
|
return html, metadata
|
||||||
|
|
||||||
def article_to_xml(article_path: pathlib.Path):
|
def article_to_xml(article_path: pathlib.Path):
|
||||||
try:
|
try:
|
||||||
with (article_path / "article.md").open("r") as f:
|
html, metadata = convert_markdown_to_html(article_path)
|
||||||
markdown_data = f.read()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
markdown_instance = markdown.Markdown(extensions=['meta', 'nl2br'])
|
|
||||||
html = markdown_instance.convert(markdown_data)
|
|
||||||
metadata = markdown_instance.Meta
|
|
||||||
tags = [f"<{convert_case(key)}>{metadata[key][0]}</{convert_case(key)}>" for key in metadata.keys()]
|
tags = [f"<{convert_case(key)}>{metadata[key][0]}</{convert_case(key)}>" for key in metadata.keys()]
|
||||||
tags.append(f"<description>\n{html}\n</description>")
|
tags.append(f"<description>\n{html}\n</description>")
|
||||||
return base_item.format(tags="\n".join(tags))
|
return base_item.format(tags="\n".join(tags))
|
||||||
|
|
Loading…
Reference in a new issue