Re: [fossil-users] Patch: Syntax Highlighting Integration (line numbers working) (fixed)

2018-07-01 Thread Lester L. Martin II

Format flowed was breaking the patch, it's now attached,
sorry for the trouble.

--
Lester L. Martin II
Index: src/db.c
==
--- src/db.c
+++ src/db.c
@@ -3259,10 +3259,15 @@
 ** A shell command used to launch your preferred
 ** web browser when given a URL as an argument.
 ** Defaults to "start" on windows, "open" on Mac,
 ** and "firefox" on Unix.
 */
+/*
+** SETTING: syntax-hlboolean default=off
+** This is a boolean set such that themes can use TH1 code
+** to detect if they should enable syntax highlighting.
+*/
 
 /*
 ** Look up a control setting by its name.  Return a pointer to the Setting
 ** object, or NULL if there is no such setting.
 **

Index: src/info.c
==
--- src/info.c
+++ src/info.c
@@ -665,11 +665,11 @@
  "  FROM blob, event"
  " WHERE blob.rid=%d"
  "   AND event.objid=%d",
  rid, rid
   );
-  
+
   cookie_link_parameter("diff","diff","2");
   diffType = atoi(PD("diff","2"));
   if( db_step()==SQLITE_ROW ){
 const char *zUuid = db_column_text(, 0);
 int nUuid = db_column_bytes(, 0);
@@ -2150,29 +2150,36 @@
   @ 
 }else{
   style_submenu_element("Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
   blob_to_utf8_no_bom(, 0);
   zMime = mimetype_from_content();
-  @ 
   if( zMime==0 ){
-const char *z;
+const char *z, *ext, *name;
+char *tmp;
 z = blob_str();
-if( zLn ){
+name = blob_str();
+ext = (tmp = strrchr(name, '.')) == NULL ? "" : tmp+1;
+@ 
+if( zLn && (db_get_boolean("syntax-hl", 0) != 0) ) {
+  @ %h(z)
+}else if( zLn ){
   output_text_with_line_numbers(z, zLn);
 }else{
-  @ 
-  @ %h(z)
-  @ 
+  @ %h(z)
 }
+@ 
   }else if( strncmp(zMime, "image/", 6)==0 ){
+@ 
 @ (file is %d(blob_size()) bytes of image data)
 @ 
 style_submenu_element("Image", "%R/raw/%s?m=%s", zUuid, zMime);
+@ 
   }else{
+@ 
 @ (file is %d(blob_size()) bytes of binary data)
+@ 
   }
-  @ 
 }
   }
   style_footer();
 }
 
@@ -2227,11 +2234,11 @@
 if( strcmp(zModAction,"approve")==0 ){
   moderation_approve(rid);
 }
   }
   zTktTitle = db_table_has_column("repository", "ticket", "title" )
-  ? db_text("(No title)", 
+  ? db_text("(No title)",
 "SELECT title FROM ticket WHERE tkt_uuid=%Q", zTktName)
   : 0;
   style_header("Ticket Change Details");
   style_submenu_element("Raw", "%R/artifact/%s", zUuid);
   style_submenu_element("History", "%R/tkthistory/%s", zTktName);

___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] Patch: Syntax Highlighting Integration (line numbers working) (fixed)

2018-07-01 Thread Lester L. Martin II

On 2018-07-01 20:03, Lester L. Martin II wrote:

On 2018-07-01 19:52, Lester L. Martin II wrote:

Note:

Have noticed that the functions, utilized without highlighting,
actually generate 2 new lines, one at the beginning, and one at
the end. This breaks line numbering (file grew longer in lines).
Believe this has existed *before* I worked on my syntax
highlighting and line numbering patch. If anyone can confirm
this is the case in Fossil 2.6 (have to inspect the html
markup), please let me know. This behaviour isn't exhibited
in the default builtin line numbering code, just the
non-line-numbering code.

Will follow up with a patch to fix that as well likely.


Apparently the previous patch (generated by fossil diff) wouldn't
work properly. This patch is generated by fossil diff -i... and
has worked at least locally. Thanks to an IRC user for letting
me know the patch was failing to apply properly. Please let me
know if this won't apply.

Index: src/db.c
==
--- src/db.c
+++ src/db.c
@@ -3259,10 +3259,15 @@
 ** A shell command used to launch your preferred
 ** web browser when given a URL as an argument.
 ** Defaults to "start" on windows, "open" on Mac,
 ** and "firefox" on Unix.
 */
+/*
+** SETTING: syntax-hlboolean default=off
+** This is a boolean set such that themes can use TH1 code
+** to detect if they should enable syntax highlighting.
+*/

 /*
 ** Look up a control setting by its name.  Return a pointer to the 
Setting

 ** object, or NULL if there is no such setting.
 **

Index: src/info.c
==
--- src/info.c
+++ src/info.c
@@ -665,11 +665,11 @@
  "  FROM blob, event"
  " WHERE blob.rid=%d"
  "   AND event.objid=%d",
  rid, rid
   );
-
+
   cookie_link_parameter("diff","diff","2");
   diffType = atoi(PD("diff","2"));
   if( db_step()==SQLITE_ROW ){
 const char *zUuid = db_column_text(, 0);
 int nUuid = db_column_bytes(, 0);
@@ -2150,29 +2150,36 @@
   @ 
 }else{
   style_submenu_element("Hex", "%s/hexdump?name=%s", g.zTop, 
zUuid);

   blob_to_utf8_no_bom(, 0);
   zMime = mimetype_from_content();
-  @ 
   if( zMime==0 ){
-const char *z;
+const char *z, *ext, *name;
+char *tmp;
 z = blob_str();
-if( zLn ){
+name = blob_str();
+ext = (tmp = strrchr(name, '.')) == NULL ? "" : tmp+1;
+@ 
+if( zLn && (db_get_boolean("syntax-hl", 0) != 0) ) {
+  @ %h(z)
+}else if( zLn ){
   output_text_with_line_numbers(z, zLn);
 }else{
-  @ 
-  @ %h(z)
-  @ 
+  @ %h(z)
 }
+@ 
   }else if( strncmp(zMime, "image/", 6)==0 ){
+@ 
 @ (file is %d(blob_size()) bytes of image 
data)

 @ 
 style_submenu_element("Image", "%R/raw/%s?m=%s", zUuid, zMime);
+@ 
   }else{
+@ 
 @ (file is %d(blob_size()) bytes of binary data)
+@ 
   }
-  @ 
 }
   }
   style_footer();
 }

@@ -2227,11 +2234,11 @@
 if( strcmp(zModAction,"approve")==0 ){
   moderation_approve(rid);
 }
   }
   zTktTitle = db_table_has_column("repository", "ticket", "title" )
-  ? db_text("(No title)",
+  ? db_text("(No title)",
 "SELECT title FROM ticket WHERE tkt_uuid=%Q", zTktName)
   : 0;
   style_header("Ticket Change Details");
   style_submenu_element("Raw", "%R/artifact/%s", zUuid);
   style_submenu_element("History", "%R/tkthistory/%s", zTktName);

___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] Patch: Syntax Highlighting Integration (line numbers working) (fixed)

2018-07-01 Thread Lester L. Martin II

On 2018-07-01 19:52, Lester L. Martin II wrote:

Note:

Have noticed that the functions, utilized without highlighting,
actually generate 2 new lines, one at the beginning, and one at
the end. This breaks line numbering (file grew longer in lines).
Believe this has existed *before* I worked on my syntax
highlighting and line numbering patch. If anyone can confirm
this is the case in Fossil 2.6 (have to inspect the html
markup), please let me know. This behaviour isn't exhibited
in the default builtin line numbering code, just the
non-line-numbering code.

Will follow up with a patch to fix that as well likely.


The fix (patch is redone) is as follows:
Index: src/db.c
==
--- /home/masky/misc/fossil/src/db.c~0	2018-07-01 20:02:18.68783 
-0500

+++ /home/masky/misc/fossil/src/db.c2018-07-01 16:34:01.746686000 -0500
@@ -3263,0 +3264,5 @@
+/*
+** SETTING: syntax-hlboolean default=off
+** This is a boolean set such that themes can use TH1 code
+** to detect if they should enable syntax highlighting.
+*/
Index: src/info.c
==
--- /home/masky/misc/fossil/src/info.c~0	2018-07-01 20:02:18.714191000 
-0500
+++ /home/masky/misc/fossil/src/info.c	2018-07-01 19:57:46.87257 
-0500

@@ -670 +670 @@
-
+
@@ -2155 +2154,0 @@
-  @ 
@@ -2157 +2156,2 @@
-const char *z;
+const char *z, *ext, *name;
+char *tmp;
@@ -2159 +2159,6 @@
-if( zLn ){
+name = blob_str();
+ext = (tmp = strrchr(name, '.')) == NULL ? "" : tmp+1;
+@ 
+if( zLn && (db_get_boolean("syntax-hl", 0) != 0) ) {
+  @ %h(z)
+}else if( zLn ){
@@ -2162,3 +2167 @@
-  @ 
-  @ %h(z)
-  @ 
+  @ %h(z)
@@ -2165,0 +2169 @@
+@ 
@@ -2166,0 +2171 @@
+@ 
@@ -2169,0 +2175 @@
+@ 
@@ -2170,0 +2177 @@
+@ 
@@ -2171,0 +2179 @@
+@ 
@@ -2173 +2180,0 @@
-  @ 
@@ -2232 +2239 @@
-  ? db_text("(No title)",
+  ? db_text("(No title)",


--
Lester L. Martin II
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] Patch: Syntax Highlighting Integration (line numbers working)

2018-07-01 Thread Lester L. Martin II

Note:

Have noticed that the functions, utilized without highlighting,
actually generate 2 new lines, one at the beginning, and one at
the end. This breaks line numbering (file grew longer in lines).
Believe this has existed *before* I worked on my syntax
highlighting and line numbering patch. If anyone can confirm
this is the case in Fossil 2.6 (have to inspect the html
markup), please let me know. This behaviour isn't exhibited
in the default builtin line numbering code, just the
non-line-numbering code.

Will follow up with a patch to fix that as well likely.

--
Lester L. Martin II
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


[fossil-users] Patch: Syntax Highlighting Integration (line numbers working)

2018-07-01 Thread Lester L. Martin II

This patch changes the way `void artifact_page(void)` renders a files
content. It also adds a new setting in "src/db.c" relating to syntax
highlighting. As with the previous patch, it changes content rendering
to use ``. In addition, on the paths that need ``
it removes the `` from the section. The introduction of a
new setting 'syntax-hl' allows for the code to determine if syntax
highlighting is enabled, and if so, render things the new way. The new
way of rendering content to make it compatible with syntax highlighting,
whilst line numbering, is to skip a call to
`void output_text_with_line_numbers(const char *, const char *)` and
allow external javascript code to deal with line numbering. If syntax-hl
is "off" it will continue to render line numbers the old way, whilst
retaining the new rendering of content without line numbers.

This should allow for Fossil to remain agnostic to syntax highlighting
systems and allow for the option to forgo syntax highlighting for those
who would not wish to have it.

One utilizes it by modifying the theme with TH1 code to test for if
the "=" parameter is available `[getParameter "ln"]` and if the
setting 'syntax-hl' is on `[setting "syntax-hl"]`. This does require
the user to serve up javascript files related to syntax highlighting.
Currently this is tested with highlight.js and a modified line numbering
extension to it.

This code however *does not* rely on highlight.js and if others wish
to use (for example) prism.js they need only modify their theme to
detect the appropriate settings and load up javascript files and make
javascript calls based upon the settings.

Provided at the end are first the patch, then an example as to how to
change the theme to support this, then the modified line numbering
extension to highlight.js (via link). All but the patch assume one is
utilizing version 9.12.0 of highlight.js, and will use the provided line
numbering extension. Do note that the line numbering extension does not
support the full extent of "=" as of yet. Work will continue on that
but it does not hinder the ability to utilize this patch and for anyone
to properly implement "=".

It is my opinion (and solely my opinion) that assuming I get the line
numbering script and "=" up to par with the C source that we might
wish to make things even simpler for the user by including the gamut
of this stuff so it's as easy as checking a seperate setting
'easy-syntax-hl'. That of course depends on if its acceptable to either
include highlight.js and the line numbering extension I've modified,
or to link to them from within (meaning a relaxation of the content
security policy as noted in ).

The patch:
Below is the output of `fossil diff` ran against checkout
'50daa540f8881cb022600fefcba3f20f44175e28' with my changes:

Index: src/db.c
==
--- /home/masky/misc/fossil/src/db.c~0	2018-07-01 18:15:59.427006000 
-0500

+++ /home/masky/misc/fossil/src/db.c2018-07-01 16:34:01.746686000 -0500
@@ -3263,0 +3264,5 @@
+/*
+** SETTING: syntax-hlboolean default=off
+** This is a boolean set such that themes can use TH1 code
+** to detect if they should enable syntax highlighting.
+*/
Index: src/info.c
==
--- /home/masky/misc/fossil/src/info.c~0	2018-07-01 18:15:59.457016000 
-0500
+++ /home/masky/misc/fossil/src/info.c	2018-07-01 16:34:01.891965000 
-0500

@@ -670 +670 @@
-
+
@@ -2155 +2154,0 @@
-  @ 
@@ -2157 +2156,2 @@
-const char *z;
+const char *z, *ext, *name;
+char *tmp;
@@ -2159 +2159,6 @@
-if( zLn ){
+name = blob_str();
+ext = (tmp = strrchr(name, '.')) == NULL ? "" : tmp+1;
+@ 
+if( zLn && (db_get_boolean("syntax-hl", 0) != 0) ) {
+  @ %h(z)
+}else if( zLn ){
@@ -2162 +2166,0 @@
-  @ 
@@ -2164 +2167,0 @@
-  @ 
@@ -2165,0 +2169 @@
+@ 
@@ -2166,0 +2171 @@
+@ 
@@ -2169,0 +2175 @@
+@ 
@@ -2170,0 +2177 @@
+@ 
@@ -2171,0 +2179 @@
+@ 
@@ -2173 +2180,0 @@
-  @ 
@@ -2232 +2239 @@
-  ? db_text("(No title)",
+  ? db_text("(No title)",

!!END!!

Below is the theme modification required (added to header above
``):

if {[setting "syntax-hl"]} {
  html "href='https://code.amlegion.org/agate.min.css'>\n"
  html "src='https://code.amlegion.org/highlight.min.js'>\n"

  html "\n"
  html "hljs.configure({languages: []});\n"
  html "hljs.initHighlightingOnLoad();\n"
  if {[getParameter "ln"] ne ""} {
html "hljs.initLineNumbersOnLoad();"
html "hljs.initLineNumScroll();"
  }
}


!!END!!

The highlight.js specific customized line numbering extension destined
to see further work is available at:
https://code.amlegion.org/hljsln.v1.js
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org