summaryrefslogtreecommitdiff
path: root/blog/render.py
blob: 9cda36af675c0bb048d26a555f7e606e7b97b34c (plain) (blame)
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
import markdown

from markdown.extensions.toc import TocExtension


def read_file_content(filename: str) -> str:
    with open(filename) as f:
        return f.read()


def write_file_content(filename: str, data: str) -> None:
    with open(filename, mode='w') as f:
        f.write(data)


def to_html(filename: str) -> str:
    text = read_file_content(filename)
    return markdown.markdown(
        text,
        extensions=[
            "fenced_code",
            "footnotes",
            "codehilite",
            TocExtension(anchorlink=True)
        ],
        extension_configs={
            "codehilite": {"css_class": "highlight"}
        },
    )