~aw/patches

mygit: make line links permalinks v1 PROPOSED

Johann150
Johann150: 2
 make line links permalinks
 fix CSS for syntax highlighting

 3 files changed, 13 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~aw/patches/patches/21655/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH mygit v1 1/2] make line links permalinks Export this patch

Johann150
The commit a shorthand name of a ref points to may change thus
rendering a line link out of date. This can be fixed by instead
using the commit oid.
---
 src/main.rs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 7122a64..18a4ec3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -428,12 +428,21 @@ async fn repo_file(req: Request<()>) -> tide::Result {
            LinesWithEndings::from(file_string)
                .for_each(|line| highlighter.parse_html_for_line_which_includes_newline(line));

            // use oid so it is a permalink
            let prefix = format!(
                "/{}/tree/{}/item/{}",
                req.param("repo_name").unwrap(),
                commit.id(),
                path.display()
            );

            let mut output = String::from("<pre>\n");
            for (n, line) in highlighter.finalize().lines().enumerate() {
                output.push_str(&format!(
                    "<a href='#L{0}' id='L{0}' class='line'>{0}</a>{1}\n",
                    "<a href='{1}#L{0}' id='L{0}' class='line'>{0}</a>{2}\n",
                    n + 1,
                    line
                    prefix,
                    line,
                ));
            }
            output.push_str("</pre>\n");
-- 
2.30.1.windows.1

[PATCH mygit v1 2/2] fix CSS for syntax highlighting Export this patch

Johann150
I forgot to change the class style back to Spaced, which is what
was used when generating the base of the style sheets from syntect.

Also the .line CSS selector interfered with some syntect items
that were also using this class. The solution is to restrict it
to links only. This made some lines, e.g. with doc comments
display wrong by having multiple line numbers on one line.
---
 src/main.rs                | 2 +-
 templates/static/style.css | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 18a4ec3..15c9c62 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -423,7 +423,7 @@ async fn repo_file(req: Request<()>) -> tide::Result {
            let mut highlighter = ClassedHTMLGenerator::new_with_class_style(
                &syntax,
                &syntax_set,
                ClassStyle::SpacedPrefixed { prefix: "code" },
                ClassStyle::Spaced,
            );
            LinesWithEndings::from(file_string)
                .for_each(|line| highlighter.parse_html_for_line_which_includes_newline(line));
diff --git a/templates/static/style.css b/templates/static/style.css
index 0399b3c..5f2b65d 100644
--- a/templates/static/style.css
+++ b/templates/static/style.css
@@ -34,7 +34,7 @@ body {
    font-size: .9rem;
}

.line {
a.line {
    display: inline-block;
    width: 4em;
    margin-right: .7em;
-- 
2.30.1.windows.1