diff --git a/Cargo.lock b/Cargo.lock index b0157c9..fc78018 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2433,7 +2433,7 @@ dependencies = [ [[package]] name = "rustpad" -version = "0.0.14" +version = "0.0.15" dependencies = [ "argon2", "aws-config", diff --git a/Cargo.toml b/Cargo.toml index 20a8c40..3312bc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustpad" -version = "0.0.14" +version = "0.0.15" edition = "2024" rust-version = "1.94" description = "Collaborative Markdown notepad built with Axum, WebSockets and SQLite, PostgreSQL and MySQL" diff --git a/static/css/styles.css b/static/css/styles.css index f71f500..6c3679b 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1258,6 +1258,12 @@ dialog::backdrop { background: var(--background); } +.public-header__actions { + display: flex; + align-items: center; + gap: 12px; +} + .public-header { position: sticky; top: 0; @@ -1302,6 +1308,10 @@ dialog::backdrop { cursor: zoom-in; } +.public-page.hide-preview-line-numbers .public-content { + padding-left: 32px; +} + @media (max-width: 600px) { .public-document { padding-top: 32px; @@ -1310,6 +1320,10 @@ dialog::backdrop { .public-content { padding: 20px 20px 20px 52px; } + + .public-page.hide-preview-line-numbers .public-content { + padding-left: 20px; + } } diff --git a/static/js/public.js b/static/js/public.js index 5366a57..d6b821d 100644 --- a/static/js/public.js +++ b/static/js/public.js @@ -7,6 +7,7 @@ import { renderMarkdown } from "@rustpad/markdown"; const token=location.pathname.split("/").filter(Boolean)[1]; const content=document.querySelector("#public-content"); +const lineNumbersToggle=document.querySelector("#public-line-numbers-toggle"); function toast(text){const el=document.querySelector("#toast");el.textContent=text;el.classList.add("visible");setTimeout(()=>el.classList.remove("visible"),1800);} async function renderMermaid(){const nodes=content.querySelectorAll(".mermaid");if(!nodes.length)return;try{const {default:mermaid}=await import("https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs");mermaid.initialize({startOnLoad:false,theme:"dark",securityLevel:"strict"});await mermaid.run({nodes:[...nodes]});}catch{nodes.forEach(n=>n.insertAdjacentHTML("beforebegin",'

Failed to load Mermaid.

'));}} async function renderCodeHighlight(){const blocks=content.querySelectorAll('pre code[class^="language-"]');if(!blocks.length)return;try{const hljs=await import("https://cdn.jsdelivr.net/npm/highlight.js@11.11.1/+esm");blocks.forEach(block=>{const lines=block.querySelectorAll(".code-line");if(!lines.length){hljs.default.highlightElement(block);return;}const language=[...block.classList].find(name=>name.startsWith("language-"))?.slice(9);lines.forEach(line=>{try{line.innerHTML=hljs.default.highlight(line.textContent,{language,ignoreIllegals:true}).value;}catch{line.innerHTML=hljs.default.highlightAuto(line.textContent).value;}});block.classList.add("hljs");});}catch{}} @@ -17,5 +18,6 @@ function lockPublicContent(allowTaskUpdates){ } async function initialize(){try{const page=await api(`/api/public/${encodeURIComponent(token)}`);document.querySelector("#public-title").textContent=page.title;document.querySelector("#public-meta").textContent=`Updated: ${new Date(page.updated_at).toLocaleString("en-US")}${page.allow_task_updates?" · tasks can be updated":""}`;document.title=`${page.title} · RustPad`;content.innerHTML=renderMarkdown(page.content);lockPublicContent(page.allow_task_updates);await Promise.all([renderMermaid(),renderCodeHighlight()]);}catch(error){content.innerHTML=`

${String(error.message)}

`;}} content.addEventListener("change",async event=>{const box=event.target.closest(".task-checkbox");if(!box||box.disabled)return;const previous=!box.checked;box.disabled=true;try{const page=await api(`/api/public/${encodeURIComponent(token)}/tasks`,{method:"POST",body:JSON.stringify({source_line:Number(box.dataset.sourceLine),checked:box.checked})});document.querySelector("#public-meta").textContent=`Updated: ${new Date(page.updated_at).toLocaleString("en-US")} · tasks can be updated`;toast("Task saved");}catch(error){box.checked=previous;toast(error.message);}finally{box.disabled=false;}}); +lineNumbersToggle.addEventListener("change",()=>{document.body.classList.toggle("hide-preview-line-numbers",!lineNumbersToggle.checked);}); document.querySelector("#copy-public-link").addEventListener("click",async()=>{try{await copyText(location.href);toast("Link copied");}catch(error){toast(error.message);}}); initialize(); diff --git a/static/public.html b/static/public.html index e4d9605..533d795 100644 --- a/static/public.html +++ b/static/public.html @@ -12,10 +12,13 @@ - +
RustPad - +
+ + +

Loading…