-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat, docs: enable custom markdown rendering to allow metadata
- Loading branch information
1 parent
0e1d755
commit 614ed5a
Showing
2 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Dict, List, Union | ||
|
||
import yaml | ||
|
||
import solara | ||
|
||
|
||
# We want to separate metadata from the markdown files before rendering them, which solara.Markdown doesn't support | ||
@solara.component | ||
def MarkdownWithMetadata(content: str, unsafe_solara_execute=True): | ||
if "---" in content: | ||
pre_content, raw_metadata, post_content = content.split("---") | ||
metadata: Dict[str, Union[str, List[str]]] = yaml.safe_load(raw_metadata) | ||
|
||
if len(pre_content) == 0: | ||
content = post_content | ||
else: | ||
content = pre_content + post_content | ||
|
||
if "title" not in metadata.keys(): | ||
metadata["title"] = content.split("#")[1].split("\n")[0] | ||
|
||
for key, value in metadata.items(): | ||
if key == "title": | ||
solara.Title(value) | ||
elif ":" in key: | ||
solara.Meta(property=key, content=value) | ||
else: | ||
solara.Meta(name=key, content=value) | ||
solara.Markdown(content, unsafe_solara_execute=unsafe_solara_execute) |