~aw/patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

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

Johann150
Details
Message ID
<20210330220930.3273-1-johann@qwertqwefsday.eu>
DKIM signature
pass
Download raw message
Patch: +11 -2
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

Johann150
Details
Message ID
<20210330220930.3273-2-johann@qwertqwefsday.eu>
In-Reply-To
<20210330220930.3273-1-johann@qwertqwefsday.eu> (view parent)
DKIM signature
pass
Download raw message
Patch: +2 -2
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
Reply to thread Export thread (mbox)