font-size: .85em;
font-weight: bold;
padding: 0.5em 1em;
+ position: relative;
}
.titledCodeBox .codeBoxTitle code {
.titledCodeBox .codeBoxTitle + .highlighttable {
margin-top: 0;
}
+
+.codeBoxTitleGitHubLink {
+ position: absolute;
+ top: 0.5em;
+ right: 1em;
+}
+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('<p>', '').replace('</p>', '')
+
return f"""
<div class="titledCodeBox">
- <div class="codeBoxTitle"><code>{title}</code></div>
+ <div class="codeBoxTitle">
+ <code>{title}</code>
+ <a class="codeBoxTitleGitHubLink" href="{editLink}" title="View on GitHub">{icon}</a>
+ </div>
```{language}
--8<-- "{filepath}"
```