tomaswolf / gerrit-gitblit-plugin

Integrates standard GitBlit (currently 1.7.1) as a repository viewer in Gerrit
Apache License 2.0
22 stars 5 forks source link

Syntax highlighting for Go #10

Closed 7AC closed 8 years ago

7AC commented 8 years ago

Syntax highlighting seems to work perfectly for most languages, however I can't get it to work for Go (golang). I do see that the jar I downloaded contains com/gitblit/wicket/pages/prettify/lang-go.js. I'm using Gerrit 2.11.4 and gitblit-plugin-2.11.3.162.2.jar. Thank you for the awesome plugin btw!

tomaswolf commented 8 years ago

What extension do your Go files have?

7AC commented 8 years ago

They all have .go.

tomaswolf commented 8 years ago

Works for me. Please note that the syntax coloring for Go in prettify is very minimal. It appears it only colors comments.

7AC commented 8 years ago

Interesting... If I run their run_prettify.js directly on this:

<html>
<body>
   <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
   <pre class="prettyprint lang-go">// No copyright
package foo

import (
   "bar"
)

// Baz is a type
type Baz int</pre>
</body>
</html>

I end up with:

<html><head><link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.css"></head><body>

   <pre class="prettyprint lang-go prettyprinted" style=""><span class="com">// No copyright</span><span class="pln">
</span><span class="kwd">package</span><span class="pln"> foo

</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">(</span><span class="pln">
   </span><span class="str">"bar"</span><span class="pln">
</span><span class="pun">)</span><span class="pln">

</span><span class="com">// Baz is a type</span><span class="pln">
type </span><span class="typ">Baz</span><span class="pln"> </span><span class="kwd">int</span></pre>

</body></html>
tomaswolf commented 8 years ago

Strange indeed... I'll have to analyze this some more in the next days.

tomaswolf commented 8 years ago

No idea why run_prettify.js gives something different than prettify.js. Might just as well be a bug in run_prettify, or maybe not. I haven't analyzed the internals of this prettify thing. I find it bizarre that some (apparently java?) keywords are recognized in the snippet you posted above, but "type" for instance isn't. The lang-go.js has no keywords defined at all. Maybe something is leaking through that shouldn't.

Whatever. I've changed the plugin to include an updated prettify, and to use run_prettify, and now Gitblit produces the same syntax coloring as above. Give release v2.11.3.162.3 a try; if it solves the problem for you, too, I'll promote that from prerelease to release.

To clarify: the plugin does not pull in prettify from cdn.rawgit.com; it includes its own copy. Helps avoid trouble when running behind strange corporate firewalls that block cdn.rawgit.com.

7AC commented 8 years ago

You're right, same goes for func. I agree with you this seems like a bug in code-prettify rather than a feature, I should take the time to write my own Go lexer and post a merge request. Thanks for looking into this!

tomaswolf commented 8 years ago

The point is that you didn't specify any language in your run_prettify URL. Since go isn't one of the built-in languages, prettify doesn't have the go syntax coloring and falls back to a default coloring, which has some common keywords.

If you invoke run_prettify via the URL https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=go you will get the defined syntax highlighting for the go language, which, as I pointed out above, is very minimal and is what plugin v2.11.3.162.2 shows. This minimal syntax coloring is by design in prettify, and everything in Gitblit and in the plugin thus was working correctly.

I'll delete the v2.11.3.162.3 pre-release of the gerrit-gitblit-plugin, and close this issue as invalid.