1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

27 lines
711 B
Python
Raw Normal View History

2020-01-19 22:13:18 -07:00
"""Markdown processing utility functions."""
# Standard Library
import typing as t
from pathlib import Path
2020-01-17 02:50:57 -07:00
if t.TYPE_CHECKING:
# Project
from hyperglass.models import HyperglassModel
2020-01-17 02:50:57 -07:00
def get_markdown(config: "HyperglassModel", default: str, params: t.Dict[str, t.Any]) -> str:
"""Get markdown file if specified, or use default."""
2020-01-17 02:50:57 -07:00
if config.enable and config.file is not None:
# with config_path.file
if hasattr(config, "file") and isinstance(config.file, Path):
with config.file.open("r") as config_file:
md = config_file.read()
2020-01-17 02:50:57 -07:00
else:
md = default
try:
return md.format(**params)
except KeyError:
return md