Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add highlight for golang code, golang doc/blog or other document web page #13178

Closed
ghost opened this issue Nov 7, 2015 · 10 comments
Closed

Comments

@ghost
Copy link

ghost commented Nov 7, 2015

Proposal: Add highlight for golang code for golang doc/blog or other document web page.
The current document, blog and other document, even online source code browser doese not have code highlight.

See following page, do you feel it ?

Example none highlight page

Blog page: https://blog.golang.org/context
Packge page: https://golang.org/pkg/bufio/#example_Scanner_custom
Source code page: https://golang.org/src/bufio/scan.go

Ok,let's testing the highlight result.

Testing highlight result

  1. Install google chrome browser
  2. Open one of the url address previous section
  3. Press F12 open chrome develop tools
  4. find <pre> tags, change it to <pre class="prettyprint">
  5. switch to chrome console, type following code
var script = document.createElement('script');script.type='text/javascript';
script.src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js";
document.head.appendChild(script);
  1. you will see the rendered result

download

How to do this?

The highlight is powered by google's dog food:
https://github.com/google/code-prettify

To use it very simple

  1. Add class="prettyprint" to the <pre> tag
  2. Load js at the button of each page
<script type="text/javascript">
var script = document.createElement('script');script.type='text/javascript';
script.src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js";
document.head.appendChild(script);
</script>
@ghost ghost changed the title Proposal: Add highlight for golang code for golang doc/blog or other document web page Proposal: Add highlight for golang code, golang doc/blog or other document web page Nov 7, 2015
@cznic
Copy link
Contributor

cznic commented Nov 7, 2015

Please no.

@adg
Copy link
Contributor

adg commented Nov 9, 2015

I don't understand the logic of the highlighting in the screenshot you provided. Some identifiers are black and some are purple. Why? It doesn't follow any logic that I can discern. Overall, that screenshot is less legible than the status quo in my opinion.

The current docs highlight comments. The code/comment distinction is objective, and so is therefore an uncontroversial stance. The rest is a matter of opinion. Historically the project does not encourage syntax highlighting.

@ghost
Copy link
Author

ghost commented Nov 9, 2015

The code highlight style is powered by google's implement https://github.com/google/code-prettify

Code highlight in IDE were good for reading code.
Emacs,VIM or other IDE both have code highlight .
Not just plain text.

Why not support code highlight?

What Text Editor you guys using? No any color ? just black and white text?

@ghost
Copy link
Author

ghost commented Nov 9, 2015

Code highlight can make code more easily to read and understand. will save our time to read and understand the code. why you think that was nonsense and useless?

@dominikh
Copy link
Member

dominikh commented Nov 9, 2015

Emacs,VIM or other IDE both have code highlight

They also easily allow changing the color scheme. Not everybody likes the colours that you, or some service, pick.

They even allow modifying the patterns used for highlighting.

What Text Editor you guys using? No any color ? just black and white text?

There is a large enough group of programmers that prefer no syntax highlighting whatsoever, among them a large portion of the Go team.

Personally I recommend that you use something like greasemonkey, or the equivalent for your browser, and add syntax highlighting to any page you wish. That way, you get to control all aspects of the syntax highlighting.

Code highlight can make code more easily to read and understand

That is subjective. Also, it is more relevant for languages with too complex syntax. Go is a very simple language syntactically. One shouldn't require colours to tell a few syntactic elements apart.

Also, as adg pointed out, the highlighting in your screenshot is inconsistent. It is either not designed for Go specifically, or it is inadequate.

@ghost
Copy link
Author

ghost commented Nov 9, 2015

Thanks @dominikh , I made a script , https://github.com/netroby/golang-org-code-highlight-userscript
By using it under chrome browser, you need install tampermonkey extension to load userscript

@adg
Copy link
Contributor

adg commented Nov 9, 2015

why you think that was nonsense and useless?

That's not what I said.

@rakyll
Copy link
Contributor

rakyll commented Nov 11, 2015

Code highlight can make code more easily to read and understand.

Not at all times. I use the lack of syntax highlighting as a readability test. I find standard library godoc and examples quite readable without syntax highlighting. It is a sign that the language and the standard library APIs are simple enough. Maybe we should always keep godoc this way to have a reality check with the verbosity.

@ghost
Copy link
Author

ghost commented Nov 17, 2015

Thanks for you time, i choose to die.

@ghost ghost closed this as completed Nov 17, 2015
@richox
Copy link

richox commented Aug 30, 2016

i choose to die, too

@golang golang locked and limited conversation to collaborators Aug 30, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants