From 83d8861a67bcf04f03ca610bc080f7be2b3163d4 Mon Sep 17 00:00:00 2001 From: pokepetter Date: Wed, 1 May 2024 20:01:58 +0200 Subject: [PATCH] added copy code buttons to code blocks. --- index.html | 18 ++++++++++++++---- sswg.css | 4 ++-- sswg.py | 23 +++++++++++++++++++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 5be0fd5..6cfc5fe 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@



2) Install sswg:

-
pip install https://github.com/pokepetter/sswg/archive/refs/heads/master.zip +


How to Run
@@ -34,14 +34,14 @@



cd into the folder where your text files are and run:

-
python -m sswg +
python -m sswg



Tags



-
- # size 1.25 +
- # size 1.25 - # width 900 - # left, right, center - # normal, bold, bolder, lighter @@ -75,7 +75,7 @@


Example Website



-
# center, bold, arial, size 5 +
# center, bold, arial, size 5 ursina engine ʕ •ᴥ•ʔゝ□ @@ -111,6 +111,16 @@


(>.<)
(")_(")

+ \ No newline at end of file diff --git a/sswg.css b/sswg.css index 89ea4af..90ab3d6 100644 --- a/sswg.css +++ b/sswg.css @@ -15,10 +15,10 @@ a.button_big:hover {background-color: white; color: #e6d23f; text-decoration: un mark {background: #ccff99;} span {background-color: rgba(0, 0, 0, 0.55); padding: .1em; line-height: 1.35em;} img {max-width: 100%; vertical-align: top;} -.code_block {background-color: whitesmoke; padding: 10px; margin: 0; font-family: monospace; font-size: 20; font-weight: normal; white-space: pre; overflow: auto; border-radius:4px; scrollbar-color:red;} +.code_block {background-color: whitesmoke; padding: 10px; margin: 0; position: relative; font-family: monospace; font-size: 20; font-weight: normal; white-space: pre; overflow: auto; border-radius:4px; scrollbar-color:red;} +.copy_code_button {position:absolute; right:10px; border:none; border-radius:5px; font-family:inherit; color:gray} /* Hide scrollbar for Chrome, Safari and Opera */ .code_block::-webkit-scrollbar { - //display: none; } .sidebar {position:fixed; z-index:1; left:1em; top:1em;} @media screen and (max-width: 1800px) {.sidebar {display:none;}} diff --git a/sswg.py b/sswg.py index b776dc7..f648514 100644 --- a/sswg.py +++ b/sswg.py @@ -101,6 +101,7 @@ def get_tags(string, start_tag, end_tag, include_tags=False): is_code_block = False is_in_style_tag = False inline_images = list() + code_block_id = 0 lines = text.split('\n') @@ -214,7 +215,12 @@ def get_tags(string, start_tag, end_tag, include_tags=False): if div_class: div_class = f'class="{div_class}" ' - new_text += f'
' + div_id = f'id="code_block_{code_block_id}" ' if is_code_block else '' + + new_text += f'
' + if is_code_block: + new_text += f'' + code_block_id += 1 if not is_code_block: new_text += '\n' @@ -326,6 +332,18 @@ def get_tags(string, start_tag, end_tag, include_tags=False): new_text += '\n' + new_text += dedent('''\ + + ''') new_text += '\n\n' @@ -347,7 +365,8 @@ def get_tags(string, start_tag, end_tag, include_tags=False): mark {background: #ccff99;} span {background-color: rgba(0, 0, 0, 0.55); padding: .1em; line-height: 1.35em;} img {max-width: 100%; vertical-align: top;} - .code_block {background-color: whitesmoke; padding: 10px; margin: 0; font-family: monospace; font-size: 20; font-weight: normal; white-space: pre; overflow: auto; border-radius:4px; scrollbar-color:red;} + .code_block {background-color: whitesmoke; padding: 10px; margin: 0; position: relative; font-family: monospace; font-size: 20; font-weight: normal; white-space: pre; overflow: auto; border-radius:4px; scrollbar-color:red;} + .copy_code_button {position:absolute; right:10px; border:none; border-radius:5px; font-family:inherit; color:gray} /* Hide scrollbar for Chrome, Safari and Opera */ .code_block::-webkit-scrollbar { }