From bcc4cb5744f996aed443d8160d0fa2a396ff3ffd Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 23 Apr 2021 17:19:17 +0200 Subject: [PATCH] Link to source code file on GitHub in code boxes with filenames (#166) Close #164 --- docs/stylesheets/extra.css | 7 +++++++ main.py | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index d31c1fca..c8badb5c 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -109,6 +109,7 @@ code, kbd, pre { font-size: .85em; font-weight: bold; padding: 0.5em 1em; + position: relative; } .titledCodeBox .codeBoxTitle code { @@ -118,3 +119,9 @@ code, kbd, pre { .titledCodeBox .codeBoxTitle + .highlighttable { margin-top: 0; } + +.codeBoxTitleGitHubLink { + position: absolute; + top: 0.5em; + right: 1em; +} diff --git a/main.py b/main.py index fef165bb..8e816f7d 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,28 @@ +import materialx.emoji +from markdown import markdown + def define_env(env): @env.macro def codebox(title = None, language = "", filepath = None, contents = ""): if title is not None: if filepath is not None: + editLink = f"""{env.variables['config']['repo_url']}tree/{env.variables['config']['edit_uri'].split("/")[1]}/snippets/{filepath}""" + icon = markdown(':material-link:', + extensions=['pymdownx.emoji'], + extension_configs={ + 'pymdownx.emoji': { + 'emoji_index': materialx.emoji.twemoji, + 'emoji_generator': materialx.emoji.to_svg + } + } + ).replace('

', '').replace('

', '') + return f"""
-
{title}
+
+ {title} + {icon} +
```{language} --8<-- "{filepath}" ``` -- 2.20.1