foldsite/src/rendering/markdown.py
Tanishq Dubey 1fc99dd2ce
All checks were successful
Datadog Software Composition Analysis / Datadog SBOM Generation and Upload (push) Successful in 16s
Datadog Secrets Scanning / Datadog Static Analyzer (push) Successful in 15s
Datadog Static Analysis / Datadog Static Analyzer (push) Successful in 23s
fix exif parsing, this is basically 1.0
2025-03-11 22:56:40 -04:00

29 lines
747 B
Python

import frontmatter
import mistune
from pathlib import Path
from bs4 import BeautifulSoup
mistune_render = mistune.create_markdown(
renderer=mistune.HTMLRenderer(escape=False),
plugins=["strikethrough", "footnotes", "table", "task_lists", "abbr", "math"],
)
def render_markdown(path: Path):
with open(path, "r", encoding="utf-8") as f:
obj = frontmatter.load(f)
content = mistune_render(obj.content)
return content, obj.metadata, obj
def read_raw_markdown(path: Path) -> str:
with open(path, "r") as f:
obj = frontmatter.load(f)
return obj.content
def rendered_markdown_to_plain_text(html):
text = "\n\n".join(BeautifulSoup(html, features="html.parser").stripped_strings)
return text