Re: Syntax highlighting issue

2020-08-26 Thread Mateja Maric

It worked! Thank you so much!

On 8/26/20 6:11 PM, Konstantin Ryabitsev wrote:

On Wed, Aug 26, 2020 at 05:59:06PM +0200, Mateja Maric wrote:

I use cgit on my server (https://git.matejamaric.com) and syntax
highlighting doesn't work for some reason.

My config file is fine (I think) and python-pygments package is installed.

The weirdest thing is that when I view page source, styling and html span
tags are there, but code is still not colored for some reason.

If you look at the dev console, you will see the reason:

Refused to apply inline style because it violates the following Content
Security Policy directive: "default-src 'self'". Either the
'unsafe-inline' keyword, a hash
('sha256-icLlI0jX3/L5wqZp69+gNqGNNMcU6bh4T+qqxWv/2as='), or a nonce
('nonce-...') is required to enable inline execution. Note also that
'style-src' was not explicitly set, so 'default-src' is used as a
fallback.

You need to change the Content-Security-Policy header to set style-src
to allow inline styles. E.g. this is on git.kernel.org:

Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'; 
img-src https:

-K


Re: Syntax highlighting issue

2020-08-26 Thread Konstantin Ryabitsev
On Wed, Aug 26, 2020 at 05:59:06PM +0200, Mateja Maric wrote:
> I use cgit on my server (https://git.matejamaric.com) and syntax
> highlighting doesn't work for some reason.
> 
> My config file is fine (I think) and python-pygments package is installed.
> 
> The weirdest thing is that when I view page source, styling and html span
> tags are there, but code is still not colored for some reason.

If you look at the dev console, you will see the reason:

Refused to apply inline style because it violates the following Content 
Security Policy directive: "default-src 'self'". Either the 
'unsafe-inline' keyword, a hash 
('sha256-icLlI0jX3/L5wqZp69+gNqGNNMcU6bh4T+qqxWv/2as='), or a nonce 
('nonce-...') is required to enable inline execution. Note also that 
'style-src' was not explicitly set, so 'default-src' is used as a 
fallback.

You need to change the Content-Security-Policy header to set style-src 
to allow inline styles. E.g. this is on git.kernel.org:

Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'; 
img-src https:

-K


Syntax highlighting issue

2020-08-26 Thread Mateja Maric
I use cgit on my server (https://git.matejamaric.com) and syntax 
highlighting doesn't work for some reason.


My config file is fine (I think) and python-pygments package is installed.

The weirdest thing is that when I view page source, styling and html 
span tags are there, but code is still not colored for some reason.


This is my cgitrc:

css=/cgit-css/cgit.css
logo=/cgit-css/cgit.png
favicon=/cgit-css/favicon.ico

source-filter=/usr/lib/cgit/filters/syntax-highlighting.py
about-filter=/usr/lib/cgit/filters/about-formatting.sh

root-title=Mateja's repositories
root-desc=Here you can find all my public projects.
snapshots=tar.gz zip
root-readme=/usr/share/webapps/cgit/about.md

clone-url=https://git.matejamaric.com/$CGIT_REPO_URL
enable-index-owner=1
enable-index-links=1
remove-suffix=1
enable-blame=1
enable-commit-graph=1
enable-log-filecount=1
enable-log-linecount=1
branch-sort=age

enable-git-config=1

mimetype.gif=image/gif
mimetype.html=text/html
mimetype.jpg=image/jpeg
mimetype.jpeg=image/jpeg
mimetype.pdf=application/pdf
mimetype.png=image/png
mimetype.svg=image/svg+xml

readme=:README.md
readme=:readme.md
readme=:README.mkd
readme=:readme.mkd
readme=:README.rst
readme=:readme.rst
readme=:README.html
readme=:readme.html
readme=:README.htm
readme=:readme.htm
readme=:README.txt
readme=:readme.txt
readme=:README
readme=:readme
readme=:INSTALL.md
readme=:install.md
readme=:INSTALL.mkd
readme=:install.mkd
readme=:INSTALL.rst
readme=:install.rst
readme=:INSTALL.html
readme=:install.html
readme=:INSTALL.htm
readme=:install.htm
readme=:INSTALL.txt
readme=:install.txt
readme=:INSTALL
readme=:install

project-list=/var/lib/gitolite/projects.list
scan-path=/var/lib/gitolite/repositories



Re: How to check error during syntax highlighting

2018-12-24 Thread John Keeping
On Mon, Dec 24, 2018 at 06:37:12PM +0900, Katsuya Horiuchi wrote:
> I have been playing with filters, specifically syntax-highlighting.py,
> in order to render markdown in tree.
> However, I would see empty output when something goes wrong.
> 
> Is it possible to check error during syntax highlighting (i.e. take log)?

The filter's stderr stream may appear in the web server's log file.

I use a small Python program for experimenting with CGit, which will
forward stderr from the filter:

https://github.com/johnkeeping/git-instacgit

You can also simply run CGit in a terminal with a couple of environment
variables set, although this is not the most straightforward mechanism
to set up.  See cgit_url() in tests/setup.sh for an example of this.


Regards,
John
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


How to check error during syntax highlighting

2018-12-24 Thread Katsuya Horiuchi
Hello,

I have been playing with filters, specifically syntax-highlighting.py,
in order to render markdown in tree.
However, I would see empty output when something goes wrong.

Is it possible to check error during syntax highlighting (i.e. take log)?

Thanks for help in advance.


Best,

Katsuya Horiuchi
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 0/4] Add ui-blame syntax highlighting

2018-01-19 Thread Jason A. Donenfeld
This patchset has been merged to master. Thanks for your contribution!

Jason
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 4/4 v3] ui-blame: Allow syntax highlighting

2017-11-05 Thread John Keeping
On Sun, Oct 29, 2017 at 11:23:38PM +0100, Jason A. Donenfeld wrote:
> Works remarkably well. Excellent work. Example, for others on the list:
> 
> https://git.zx2c4.com/WireGuard/blame/src/noise.c
> 
> Pending objections from others, I'll merge this from jd/color-blame to
> master in a few days.

This version looks great to me, so I say merge away!
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 4/4 v3] ui-blame: Allow syntax highlighting

2017-10-29 Thread Jason A. Donenfeld
Works remarkably well. Excellent work. Example, for others on the list:

https://git.zx2c4.com/WireGuard/blame/src/noise.c

Pending objections from others, I'll merge this from jd/color-blame to
master in a few days.

Thanks for this series!

Jason
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 4/4 v3] ui-blame: Allow syntax highlighting

2017-10-28 Thread Jeff Smith
Place file contents into a single block so that syntax highlighting can
be applied in the usual fashion.  Place the alternating color bars
behind the file contents.  Force the default syntax highlighting
background to transparent.

Signed-off-by: Jeff Smith 
---

Here is the version that corrects for tab characters in the text.

 cgit.css   | 10 +++
 filters/syntax-highlighting.py |  2 +-
 ui-blame.c | 63 ++
 3 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/cgit.css b/cgit.css
index 20b7e86..217a05a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
background: white;
 }
 
+div#cgit table.blame td.lines > div {
+   position: relative;
+}
+
+div#cgit table.blame td.lines > div > pre {
+   padding: 0 0 0 0.5em;
+   position: absolute;
+   top: 0;
+}
+
 div#cgit table.bin-blob {
margin-top: 0.5em;
border: solid 1px black;
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..e912594 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, 
encoding='utf-8', errors='replace
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', 
errors='replace')
 data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(style='pastie')
+formatter = HtmlFormatter(style='pastie', nobackground=True)
 
 try:
lexer = guess_lexer_for_filename(filename, data)
diff --git a/ui-blame.c b/ui-blame.c
index f506616..afbcf0d 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct blame_entry 
*ent)
htmlf(numberfmt, ++lineno);
 }
 
-static void emit_blame_entry_line(struct blame_scoreboard *sb,
- struct blame_entry *ent)
+static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
+struct blame_entry *ent)
 {
-   const char *cp, *cpend;
+   unsigned long line;
+   size_t len, maxlen = 2;
+   const char* pos, *endpos;
 
-   cp = blame_nth_line(sb, ent->lno);
-   cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+   for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
+   html("\n");
+   pos = blame_nth_line(sb, line);
+   endpos = blame_nth_line(sb, line + 1);
+   len = 0;
+   while (pos < endpos) {
+   len++;
+   if (*pos++ == '\t')
+   len = (len + 7) & ~7;
+   }
+   if (len > maxlen)
+   maxlen = len;
+   }
 
-   html_ntxt(cp, cpend - cp);
+   for (len = 0; len < maxlen - 1; len++)
+   html(" ");
 }
 
 struct walk_tree_context {
@@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const 
char *path,
 const char *basename, const char *rev)
 {
enum object_type type;
+   char *buf;
unsigned long size;
struct argv_array rev_argv = ARGV_ARRAY_INIT;
struct rev_info revs;
@@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, const 
char *path,
return;
}
 
+   buf = read_sha1_file(sha1, &type, &size);
+   if (!buf) {
+   cgit_print_error_page(500, "Internal server error",
+   "Error reading object %s", sha1_to_hex(sha1));
+   return;
+   }
+
argv_array_push(&rev_argv, "blame");
argv_array_push(&rev_argv, rev);
init_revisions(&revs, NULL);
@@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, const 
char *path,
html("\n");
}
 
-   /* Lines */
-   html("");
+   html("");
+
+   /* Colored bars behind lines */
+   html("");
for (ent = sb.ent; ent; ) {
struct blame_entry *e = ent->next;
-   html("");
-   emit_blame_entry_line(&sb, ent);
-   html("");
+   html("");
+   emit_blame_entry_line_background(&sb, ent);
+   html("");
free(ent);
ent = e;
}
-   html("\n");
+   html("");
 
free((void *)sb.final_buf);
 
+   /* Lines */
+   html("");
+   if (ctx.repo->source_filter) {
+   char *filter_arg = xstrdup(basename);
+   cgit_open_filter(ctx.repo->source_filter, filte

Re: [PATCH 4/4 v2] ui-blame: Allow syntax highlighting

2017-10-28 Thread Jeffrey Smith
Sorry, ignore that one.  Wasn't meant to be sent quite yet.

On Sat, Oct 28, 2017 at 9:23 PM, Jeff Smith  wrote:
> Place file contents into a single block so that syntax highlighting can
> be applied in the usual fashion.  Place the alternating color bars
> behind the file contents.  Force the default syntax highlighting
> background to transparent.
>
> Signed-off-by: Jeff Smith 
> ---
>  cgit.css   | 10 +++
>  filters/syntax-highlighting.py |  2 +-
>  ui-blame.c | 63 
> ++
>  3 files changed, 62 insertions(+), 13 deletions(-)
>
> diff --git a/cgit.css b/cgit.css
> index 20b7e86..217a05a 100644
> --- a/cgit.css
> +++ b/cgit.css
> @@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
> background: white;
>  }
>
> +div#cgit table.blame td.lines > div {
> +   position: relative;
> +}
> +
> +div#cgit table.blame td.lines > div > pre {
> +   padding: 0 0 0 0.5em;
> +   position: absolute;
> +   top: 0;
> +}
> +
>  div#cgit table.bin-blob {
> margin-top: 0.5em;
> border: solid 1px black;
> diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
> index 5888b50..e912594 100755
> --- a/filters/syntax-highlighting.py
> +++ b/filters/syntax-highlighting.py
> @@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, 
> encoding='utf-8', errors='replace
>  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', 
> errors='replace')
>  data = sys.stdin.read()
>  filename = sys.argv[1]
> -formatter = HtmlFormatter(style='pastie')
> +formatter = HtmlFormatter(style='pastie', nobackground=True)
>
>  try:
> lexer = guess_lexer_for_filename(filename, data)
> diff --git a/ui-blame.c b/ui-blame.c
> index f506616..bb6261f 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct 
> blame_entry *ent)
> htmlf(numberfmt, ++lineno);
>  }
>
> -static void emit_blame_entry_line(struct blame_scoreboard *sb,
> - struct blame_entry *ent)
> +static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
> +struct blame_entry *ent)
>  {
> -   const char *cp, *cpend;
> +   unsigned long line;
> +   size_t len, maxlen = 2;
> +   const char* pos, endpos;
>
> -   cp = blame_nth_line(sb, ent->lno);
> -   cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> +   for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
> +   html("\n");
> +   pos = blame_nth_line(sb, line);
> +   endpos = blame_nth_line(sb, line + 1);
> +   len = 0;
> +   while (pos < endpos) {
> +   len++;
> +   if (*pos++ == '\t')
> +   len = (len + 7) & ~7;
> +   }
> +   if (len > maxlen)
> +   maxlen = len;
> +   }
>
> -   html_ntxt(cp, cpend - cp);
> +   for (len = 0; len < maxlen - 1; len++)
> +   html(" ");
>  }
>
>  struct walk_tree_context {
> @@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const 
> char *path,
>  const char *basename, const char *rev)
>  {
> enum object_type type;
> +   char *buf;
> unsigned long size;
> struct argv_array rev_argv = ARGV_ARRAY_INIT;
> struct rev_info revs;
> @@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, 
> const char *path,
> return;
> }
>
> +   buf = read_sha1_file(sha1, &type, &size);
> +   if (!buf) {
> +   cgit_print_error_page(500, "Internal server error",
> +   "Error reading object %s", sha1_to_hex(sha1));
> +   return;
> +   }
> +
> argv_array_push(&rev_argv, "blame");
> argv_array_push(&rev_argv, rev);
> init_revisions(&revs, NULL);
> @@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, 
> const char *path,
> html("\n");
> }
>
> -   /* Lines */
> -   html("");
> +   html("");
> +
> +   /* Colored bars behind lines */
> +   html("");
> for (ent = sb.ent; ent; ) {
>   

[PATCH 4/4 v2] ui-blame: Allow syntax highlighting

2017-10-28 Thread Jeff Smith
Place file contents into a single block so that syntax highlighting can
be applied in the usual fashion.  Place the alternating color bars
behind the file contents.  Force the default syntax highlighting
background to transparent.

Signed-off-by: Jeff Smith 
---
 cgit.css   | 10 +++
 filters/syntax-highlighting.py |  2 +-
 ui-blame.c | 63 ++
 3 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/cgit.css b/cgit.css
index 20b7e86..217a05a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
background: white;
 }
 
+div#cgit table.blame td.lines > div {
+   position: relative;
+}
+
+div#cgit table.blame td.lines > div > pre {
+   padding: 0 0 0 0.5em;
+   position: absolute;
+   top: 0;
+}
+
 div#cgit table.bin-blob {
margin-top: 0.5em;
border: solid 1px black;
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..e912594 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, 
encoding='utf-8', errors='replace
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', 
errors='replace')
 data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(style='pastie')
+formatter = HtmlFormatter(style='pastie', nobackground=True)
 
 try:
lexer = guess_lexer_for_filename(filename, data)
diff --git a/ui-blame.c b/ui-blame.c
index f506616..bb6261f 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct blame_entry 
*ent)
htmlf(numberfmt, ++lineno);
 }
 
-static void emit_blame_entry_line(struct blame_scoreboard *sb,
- struct blame_entry *ent)
+static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
+struct blame_entry *ent)
 {
-   const char *cp, *cpend;
+   unsigned long line;
+   size_t len, maxlen = 2;
+   const char* pos, endpos;
 
-   cp = blame_nth_line(sb, ent->lno);
-   cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+   for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
+   html("\n");
+   pos = blame_nth_line(sb, line);
+   endpos = blame_nth_line(sb, line + 1);
+   len = 0;
+   while (pos < endpos) {
+   len++;
+   if (*pos++ == '\t')
+   len = (len + 7) & ~7;
+   }
+   if (len > maxlen)
+   maxlen = len;
+   }
 
-   html_ntxt(cp, cpend - cp);
+   for (len = 0; len < maxlen - 1; len++)
+   html(" ");
 }
 
 struct walk_tree_context {
@@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const 
char *path,
 const char *basename, const char *rev)
 {
enum object_type type;
+   char *buf;
unsigned long size;
struct argv_array rev_argv = ARGV_ARRAY_INIT;
struct rev_info revs;
@@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, const 
char *path,
return;
}
 
+   buf = read_sha1_file(sha1, &type, &size);
+   if (!buf) {
+   cgit_print_error_page(500, "Internal server error",
+   "Error reading object %s", sha1_to_hex(sha1));
+   return;
+   }
+
argv_array_push(&rev_argv, "blame");
argv_array_push(&rev_argv, rev);
init_revisions(&revs, NULL);
@@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, const 
char *path,
html("\n");
}
 
-   /* Lines */
-   html("");
+   html("");
+
+   /* Colored bars behind lines */
+   html("");
for (ent = sb.ent; ent; ) {
struct blame_entry *e = ent->next;
-   html("");
-   emit_blame_entry_line(&sb, ent);
-   html("");
+   html("");
+   emit_blame_entry_line_background(&sb, ent);
+   html("");
free(ent);
ent = e;
}
-   html("\n");
+   html("");
 
free((void *)sb.final_buf);
 
+   /* Lines */
+   html("");
+   if (ctx.repo->source_filter) {
+   char *filter_arg = xstrdup(basename);
+   cgit_open_filter(ctx.repo->source_filter, filter_arg);
+   html_raw(buf, size);
+   cgit_c

Re: [PATCH 4/4] ui-blame: Allow syntax highlighting

2017-10-24 Thread Jason A. Donenfeld
Just waiting on resubmission of this 4/4, then. I'll put 1-3 in a branch.

Jason
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 4/4] ui-blame: Allow syntax highlighting

2017-10-21 Thread Jeffrey Smith
On Sat, Oct 21, 2017 at 9:43 AM, John Keeping  wrote:
>
> This doesn't account for tabs, which is noticable in long lines (I
> happened to test with cgit.c where line 615 is quite a bit longer than
> average).
>
> It is fixed by using:
>
> const char *start = blame_nth_line(sb, line);
> const char *end = blame_nth_line(sb, line + 1);
>
> html("\n");
> len = end - start;
> while (start < end)
> if (*(start++) == '\t')
> len += 7;
>

Nice catch.  Since '\t' is 'advance to next tab-stop' not 'advance # spaces',
that calculation could give a len larger than necessary.  I will add the code
to handle tabs properly.

>> + if (len > maxlen)
>> + maxlen = len;
>> + }
>>
>> - html_ntxt(cp, cpend - cp);
>> + for (len = 0; len < maxlen - 1; len++)
>> + html(" ");
>
> Should this use   or is a plain space guaranteed to be okay here?

This is inside of a 'pre' block, so spaces will do the right thing.
___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: [PATCH 4/4] ui-blame: Allow syntax highlighting

2017-10-21 Thread John Keeping
On Tue, Oct 17, 2017 at 11:17:35PM -0500, Jeff Smith wrote:
> Place file contents into a single block so that syntax highlighting can
> be applied in the usual fashion.  Place the alternating color bars
> behind the file contents.  Force the default syntax highlighting
> background to transparent.
> 
> Signed-off-by: Jeff Smith 

Other than a couple of minor comments below, this looks reasonable to
me.

It does suffer the same drawback as the normal tree view with source
highlighting in that a little care is needed to avoid the line numbers
and content getting out of step (try adding "font-size: larger" to one
of the syntax highlighting CSS rules!), but since we already accept that
there I think we can accept it here as well.

> ---
>  cgit.css   | 10 
>  filters/syntax-highlighting.py |  2 +-
>  ui-blame.c | 55 
> +-
>  3 files changed, 54 insertions(+), 13 deletions(-)
> 
> diff --git a/cgit.css b/cgit.css
> index 20b7e86..217a05a 100644
> --- a/cgit.css
> +++ b/cgit.css
> @@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
>   background: white;
>  }
>  
> +div#cgit table.blame td.lines > div {
> + position: relative;
> +}
> +
> +div#cgit table.blame td.lines > div > pre {
> + padding: 0 0 0 0.5em;
> + position: absolute;
> + top: 0;
> +}
> +
>  div#cgit table.bin-blob {
>   margin-top: 0.5em;
>   border: solid 1px black;
> diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
> index 5888b50..e912594 100755
> --- a/filters/syntax-highlighting.py
> +++ b/filters/syntax-highlighting.py
> @@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, 
> encoding='utf-8', errors='replace
>  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', 
> errors='replace')
>  data = sys.stdin.read()
>  filename = sys.argv[1]
> -formatter = HtmlFormatter(style='pastie')
> +formatter = HtmlFormatter(style='pastie', nobackground=True)
>  
>  try:
>   lexer = guess_lexer_for_filename(filename, data)
> diff --git a/ui-blame.c b/ui-blame.c
> index f506616..574c3ee 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -67,15 +67,21 @@ static void emit_blame_entry_linenumber(struct 
> blame_entry *ent)
>   htmlf(numberfmt, ++lineno);
>  }
>  
> -static void emit_blame_entry_line(struct blame_scoreboard *sb,
> -   struct blame_entry *ent)
> +static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
> +  struct blame_entry *ent)
>  {
> - const char *cp, *cpend;
> + unsigned long line;
> + size_t len, maxlen = 2;
>  
> - cp = blame_nth_line(sb, ent->lno);
> - cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> + for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
> + html("\n");
> + len = blame_nth_line(sb, line + 1) - blame_nth_line(sb, line);

This doesn't account for tabs, which is noticable in long lines (I
happened to test with cgit.c where line 615 is quite a bit longer than
average).

It is fixed by using:

const char *start = blame_nth_line(sb, line);
const char *end = blame_nth_line(sb, line + 1);

html("\n");
len = end - start;
while (start < end)
if (*(start++) == '\t')
len += 7;

> + if (len > maxlen)
> + maxlen = len;
> + }
>  
> - html_ntxt(cp, cpend - cp);
> + for (len = 0; len < maxlen - 1; len++)
> + html(" ");

Should this use   or is a plain space guaranteed to be okay here?

>  }
>  
>  struct walk_tree_context {
> @@ -88,6 +94,7 @@ static void print_object(const unsigned char *sha1, const 
> char *path,
>const char *basename, const char *rev)
>  {
>   enum object_type type;
> + char *buf;
>   unsigned long size;
>   struct argv_array rev_argv = ARGV_ARRAY_INIT;
>   struct rev_info revs;
> @@ -102,6 +109,13 @@ static void print_object(const unsigned char *sha1, 
> const char *path,
>   return;
>   }
>  
> + buf = read_sha1_file(sha1, &type, &size);
> + if (!buf) {
> + cgit_print_error_page(500, "Internal server error",
> + "Error reading object %s", sha1_to_hex(sha1));
> + return;
> + }
> +
>   argv_array_push(&rev_argv, "blame

[PATCH 4/4] ui-blame: Allow syntax highlighting

2017-10-17 Thread Jeff Smith
Place file contents into a single block so that syntax highlighting can
be applied in the usual fashion.  Place the alternating color bars
behind the file contents.  Force the default syntax highlighting
background to transparent.

Signed-off-by: Jeff Smith 
---
 cgit.css   | 10 
 filters/syntax-highlighting.py |  2 +-
 ui-blame.c | 55 +-
 3 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/cgit.css b/cgit.css
index 20b7e86..217a05a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
background: white;
 }
 
+div#cgit table.blame td.lines > div {
+   position: relative;
+}
+
+div#cgit table.blame td.lines > div > pre {
+   padding: 0 0 0 0.5em;
+   position: absolute;
+   top: 0;
+}
+
 div#cgit table.bin-blob {
margin-top: 0.5em;
border: solid 1px black;
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..e912594 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, 
encoding='utf-8', errors='replace
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', 
errors='replace')
 data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(style='pastie')
+formatter = HtmlFormatter(style='pastie', nobackground=True)
 
 try:
lexer = guess_lexer_for_filename(filename, data)
diff --git a/ui-blame.c b/ui-blame.c
index f506616..574c3ee 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -67,15 +67,21 @@ static void emit_blame_entry_linenumber(struct blame_entry 
*ent)
htmlf(numberfmt, ++lineno);
 }
 
-static void emit_blame_entry_line(struct blame_scoreboard *sb,
- struct blame_entry *ent)
+static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
+struct blame_entry *ent)
 {
-   const char *cp, *cpend;
+   unsigned long line;
+   size_t len, maxlen = 2;
 
-   cp = blame_nth_line(sb, ent->lno);
-   cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+   for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
+   html("\n");
+   len = blame_nth_line(sb, line + 1) - blame_nth_line(sb, line);
+   if (len > maxlen)
+   maxlen = len;
+   }
 
-   html_ntxt(cp, cpend - cp);
+   for (len = 0; len < maxlen - 1; len++)
+   html(" ");
 }
 
 struct walk_tree_context {
@@ -88,6 +94,7 @@ static void print_object(const unsigned char *sha1, const 
char *path,
 const char *basename, const char *rev)
 {
enum object_type type;
+   char *buf;
unsigned long size;
struct argv_array rev_argv = ARGV_ARRAY_INIT;
struct rev_info revs;
@@ -102,6 +109,13 @@ static void print_object(const unsigned char *sha1, const 
char *path,
return;
}
 
+   buf = read_sha1_file(sha1, &type, &size);
+   if (!buf) {
+   cgit_print_error_page(500, "Internal server error",
+   "Error reading object %s", sha1_to_hex(sha1));
+   return;
+   }
+
argv_array_push(&rev_argv, "blame");
argv_array_push(&rev_argv, rev);
init_revisions(&revs, NULL);
@@ -157,20 +171,37 @@ static void print_object(const unsigned char *sha1, const 
char *path,
html("\n");
}
 
-   /* Lines */
-   html("");
+   html("");
+
+   /* Colored bars behind lines */
+   html("");
for (ent = sb.ent; ent; ) {
struct blame_entry *e = ent->next;
-   html("");
-   emit_blame_entry_line(&sb, ent);
-   html("");
+   html("");
+   emit_blame_entry_line_background(&sb, ent);
+   html("");
free(ent);
ent = e;
}
-   html("\n");
+   html("");
 
free((void *)sb.final_buf);
 
+   /* Lines */
+   html("");
+   if (ctx.repo->source_filter) {
+   char *filter_arg = xstrdup(basename);
+   cgit_open_filter(ctx.repo->source_filter, filter_arg);
+   html_raw(buf, size);
+   cgit_close_filter(ctx.repo->source_filter);
+   free(filter_arg);
+   } else {
+   html_txt(buf);
+   }
+   html("");
+
+   html("\n");
+
html("\n\n");
 
cgit_print_layout_end();
-- 
2.9.4

___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


[PATCH 0/4] Add ui-blame syntax highlighting

2017-10-17 Thread Jeff Smith
I reorganized the ordering of the table so that the lines of the file
are contained within a single cell, and the base layer of that cell
contains the alternating colors.  I then pass the full contents of the
file through the source filter.

Jeff Smith (4):
  ui-blame: Distinguish hashes column from lines column
  ui-blame: Break out emit_blame_entry into component methods
  ui-blame: Make each column into a single table cell
  ui-blame: Allow syntax highlighting

 cgit.css   |  30 +++-
 filters/syntax-highlighting.py |   2 +-
 ui-blame.c | 109 -
 3 files changed, 115 insertions(+), 26 deletions(-)

-- 
2.9.4

___
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit


Re: SIGPIPE from syntax highlighting filter if highlight is not available

2016-10-01 Thread John Keeping
On Thu, Sep 29, 2016 at 04:38:41PM +0200, Vadim Zeitlin wrote:
>  As this is the first time I'm posting here, let me start by thanking you
> for developing cgit! I'm using it since quite some time under Debian
> (currently Jessie) and it works very well but recently I've mistakenly
> removed highlight package because I thought it was redundant with other
> similar tools and completely forgot that cgit depended on it.
> 
>  Since then, viewing any files in cgit didn't work, which was probably only
> to be expected, but viewing sufficiently large files resulted in 500 server
> error due to, after debugging, SIGPIPE received but not handled by cgit
> when reading from the filter subprocess.
> 
>  I'm not sure what exactly should be done here: maybe nothing, and people
> should be just more careful with uninstalling dependencies. But I think
> ideally cgit should give an error indicating that filter execution failed
> and I'd at least expect it not to just die without any further information.

If we ignore SIGPIPE we should just hit the die_errno() in
html.c::html_raw() which will say "write error on html output".  That's
not really as useful as it could be, since that code doesn't care
whether or not it's writing via a filter.

I'm not sure if we want to start keeping track of whether we're writing
through a filter, but some form of error message rather than a silent
failure does seem like an improvment.  I think we just need to ignore
SIGPIPE to make that happen.
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


SIGPIPE from syntax highlighting filter if highlight is not available

2016-09-29 Thread Vadim Zeitlin
 Hello,

 As this is the first time I'm posting here, let me start by thanking you
for developing cgit! I'm using it since quite some time under Debian
(currently Jessie) and it works very well but recently I've mistakenly
removed highlight package because I thought it was redundant with other
similar tools and completely forgot that cgit depended on it.

 Since then, viewing any files in cgit didn't work, which was probably only
to be expected, but viewing sufficiently large files resulted in 500 server
error due to, after debugging, SIGPIPE received but not handled by cgit
when reading from the filter subprocess.

 I'm not sure what exactly should be done here: maybe nothing, and people
should be just more careful with uninstalling dependencies. But I think
ideally cgit should give an error indicating that filter execution failed
and I'd at least expect it not to just die without any further information.

 Thanks again for cgit!
VZ


pgpwQL2Xnj8Fv.pgp
Description: PGP signature
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: syntax highlighting

2016-03-06 Thread Ferry Huberts

I have a git server with cgit running on CentOS 6 as well.

I use in cgitrc:

source-filter=/syntax-highlighting.bash


Which is in the cgit tree as filters/syntax-highlighting.sh

Install highlight (from EPEL) and adjust the script for the installed 
version of highlight, which should be v3.




On 05/03/16 23:47, Anthony LaTorre wrote:

Hi all,

I've recently installed cgit on CentOS 6 from the EPEL repository.
Unfortunately python3 is not available for CentOS 6. I have a couple
of questions:

- Why the hard dependency on python 3? I realize this is really a
packaging problem, but the syntax-highlighting.py doesn't look too
complex. Is there a reason python2 is not supported? Would a patch be
welcome?

- I have manually installed python3 but I still don't see any of the
source files. I have verified that the script appears to be working by
running:

$ cat code.h | /usr/libexec/cgit/filters/syntax-highlighting.py code.h

and I do see what appears to be the correct HTML.

How can I debug why I am not seeing anything? Is there a log file somewhere?

Thanks,

Tony
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit



--
Ferry Huberts
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


Re: syntax highlighting

2016-03-06 Thread Stefan Tatschner
On 05.03.2016 23:47, Anthony LaTorre wrote:
> Hi all,
> 
> I've recently installed cgit on CentOS 6 from the EPEL repository.
> Unfortunately python3 is not available for CentOS 6. I have a couple
> of questions:

Just use the Python2 version of the script; it is in the Git-Log:

https://git.zx2c4.com/cgit/tree/filters/syntax-highlighting.py?id=ceffeb5d52609a38c5d5d410456d796673fe8461

Stefan
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit


syntax highlighting

2016-03-05 Thread Anthony LaTorre
Hi all,

I've recently installed cgit on CentOS 6 from the EPEL repository.
Unfortunately python3 is not available for CentOS 6. I have a couple
of questions:

- Why the hard dependency on python 3? I realize this is really a
packaging problem, but the syntax-highlighting.py doesn't look too
complex. Is there a reason python2 is not supported? Would a patch be
welcome?

- I have manually installed python3 but I still don't see any of the
source files. I have verified that the script appears to be working by
running:

$ cat code.h | /usr/libexec/cgit/filters/syntax-highlighting.py code.h

and I do see what appears to be the correct HTML.

How can I debug why I am not seeing anything? Is there a log file somewhere?

Thanks,

Tony
___
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit