From 3ba0cfcab98f2bea59c7e4863d72c389d607fa3f Mon Sep 17 00:00:00 2001 From: A91y <65825207+A91y@users.noreply.github.com> Date: Sat, 13 Jan 2024 03:11:14 +0530 Subject: [PATCH 1/3] feat: added copying text button in Paste.py --- src/paste/main.py | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/paste/main.py b/src/paste/main.py index 1fc041c..9628e00 100644 --- a/src/paste/main.py +++ b/src/paste/main.py @@ -102,8 +102,7 @@ async def get_paste_data(uuid: str, user_agent: Optional[str] = Header(None)) -> formatter = HtmlFormatter( style="colorful", full=True, linenos="inline", cssclass='code') highlighted_code: str = highlight(content, lexer, formatter) - - print(highlighted_code) + # print(highlighted_code) custom_style = """ .code pre span.linenos { color: #999; @@ -141,17 +140,58 @@ async def get_paste_data(uuid: str, user_agent: Optional[str] = Header(None)) -> pre { font-family: 'Consolas','Monaco','Andale Mono','Ubuntu Mono','monospace;' !important; } + .copy-button { + position: fixed; + top: 10px; + right: 10px; + padding: 10px; + background-color: #4CAF50; + color: #fff; + cursor: pointer; + border: none; + border-radius: 5px; + outline: none; + } + """ + custom_script = """ + function copyAllText() { + // Create a range object to select the entire document + const range = document.createRange(); + range.selectNode(document.body); + + // Create a selection object and add the range to it + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + + // Copy the selected text to the clipboard + document.execCommand('copy'); + + // Clear the selection to avoid interfering with the user's selection + selection.removeAllRanges(); + + // You can customize the copied message + alert('All text copied to clipboard!'); + } + """ response_content: str = f""" - {uuid} + {uuid} | Paste.py + +
+ +
{highlighted_code} + """ return HTMLResponse( From 34f1432b5c1d401ef140b68b2b792a1556d9978b Mon Sep 17 00:00:00 2001 From: A91y <65825207+A91y@users.noreply.github.com> Date: Sat, 13 Jan 2024 03:14:17 +0530 Subject: [PATCH 2/3] refactor: add formatting --- src/paste/main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/paste/main.py b/src/paste/main.py index d0d84ac..42dfa27 100644 --- a/src/paste/main.py +++ b/src/paste/main.py @@ -70,7 +70,8 @@ BASE_DIR: Path = Path(__file__).resolve().parent -templates: Jinja2Templates = Jinja2Templates(directory=str(Path(BASE_DIR, "templates"))) +templates: Jinja2Templates = Jinja2Templates( + directory=str(Path(BASE_DIR, "templates"))) @app.post("/file") @@ -126,8 +127,10 @@ async def get_paste_data(uuid: str, user_agent: Optional[str] = Header(None)) -> try: lexer = get_lexer_by_name(file_extension, stripall=True) except ClassNotFound: - lexer = get_lexer_by_name("text", stripall=True) # Default lexer - formatter = HtmlFormatter(style="colorful", full=True, linenos="inline", cssclass="code") + lexer = get_lexer_by_name( + "text", stripall=True) # Default lexer + formatter = HtmlFormatter( + style="colorful", full=True, linenos="inline", cssclass="code") highlighted_code: str = highlight(content, lexer, formatter) # print(highlighted_code) custom_style = """ @@ -241,9 +244,11 @@ async def delete_paste(uuid: str) -> PlainTextResponse: os.remove(path) return PlainTextResponse(f"File successfully deleted {uuid}") except FileNotFoundError: - raise HTTPException(detail="File Not Found", status_code=status.HTTP_404_NOT_FOUND) + raise HTTPException(detail="File Not Found", + status_code=status.HTTP_404_NOT_FOUND) except Exception as e: - raise HTTPException(detail=f"The exception is {e}", status_code=status.HTTP_409_CONFLICT) + raise HTTPException( + detail=f"The exception is {e}", status_code=status.HTTP_409_CONFLICT) @app.get("/web", response_class=HTMLResponse) From aa67a7342d0c3a03843aa879c5d7718d03b38b6b Mon Sep 17 00:00:00 2001 From: Ayush Agrawal <65825207+A91y@users.noreply.github.com> Date: Sat, 13 Jan 2024 09:20:43 +0530 Subject: [PATCH 3/3] refactor: update title in /paste/ --- src/paste/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paste/main.py b/src/paste/main.py index 42dfa27..5444f40 100644 --- a/src/paste/main.py +++ b/src/paste/main.py @@ -208,7 +208,7 @@ async def get_paste_data(uuid: str, user_agent: Optional[str] = Header(None)) -> response_content: str = f""" - {uuid} | Paste.py + {uuid} | paste.py 🐍