pastebin.fi line numbers & highlight (git patch)
- 📅 2023-05-19T10:15:19.464Z
- 👁️ 201 katselukertaa
- 🔓 Julkinen
diff --git a/src/static/hljs.css b/src/static/hljs.css
index c7ab704..fb76194 100644
--- a/src/static/hljs.css
+++ b/src/static/hljs.css
@@ -68,4 +68,38 @@
.hljs-strong {
font-weight: bold;
+}
+
+/* line numbers in highlightjs-line-numbers.js */
+
+/* for block of numbers */
+.hljs-ln-numbers {
+ -webkit-touch-callout: none;
+ -webkit-user-select: none;
+ -khtml-user-select: none;
+ -moz-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+
+ text-align: center;
+ color: #ccc;
+ border-right: 1px solid #CCC !important;
+ vertical-align: top;
+ padding-right: 5px;
+
+ /* your custom style here */
+}
+
+/* for block of code */
+.hljs-ln-code {
+ padding-left: 10px !important;
+}
+
+/* do not style as normal table */
+table.hljs-ln {
+ margin: none;
+}
+
+td.hljs-ln-line {
+ border: none;
}
\ No newline at end of file
diff --git a/src/static/main.css b/src/static/main.css
index 51d872b..6d0b7a4 100644
--- a/src/static/main.css
+++ b/src/static/main.css
@@ -7,6 +7,11 @@
gap: 20px;
}
+pre, code, .hljs, tbody {
+ padding: 0 !important;
+ margin: 0 !important;
+}
+
code {
max-width: 100%;
word-wrap: break-word;
diff --git a/src/views/paste.pug b/src/views/paste.pug
index 63dd710..c1f4bfb 100644
--- a/src/views/paste.pug
+++ b/src/views/paste.pug
@@ -33,5 +33,16 @@ html(lang="fi")
pre
code(class='language-' + paste.language) #{ paste.content }
script(src='/static/highlight.min.js')
+ script(src='/static/highlightjs-line-numbers.js')
+ script(src='/static/highlightjs-highlight-lines.js')
script.
+ const lineHighlights = window.location.hash.replace('#', '').split('-');
+
hljs.highlightAll();
+ hljs.initLineNumbersOnLoad();
+ if (lineHighlights.length > 1) {
+ console.log(lineHighlights)
+ hljs.highlightLinesAll([
+ [{start: lineHighlights[0], end: lineHighlights[1], color: '#fdfad7'}]
+ ]);
+ }