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

Code highlight #3

Open
alexrs opened this issue Aug 4, 2016 · 2 comments
Open

Code highlight #3

alexrs opened this issue Aug 4, 2016 · 2 comments

Comments

@alexrs
Copy link
Owner

alexrs commented Aug 4, 2016

PROBLEM: The code is displayed like the rest of the answer, but we all know that it's the most important part, so it should be highlighted.

POSSIBLE SOLUTION: Get the code of the answer parsing the HTML and highlight it. (We can develop a library! Or port this one to Golang!)

@Virtual-Machine
Copy link
Contributor

Virtual-Machine commented Aug 5, 2016

Just some food for thought for cross platform support and implementing full syntax highlighting.

1.) It appears that Powershell and Command Prompt on Windows will not support using ansi escape codes for colourizing output out of the box. Will the solution cover Windows and *nix shells?

2.) The current raw output of the query does not provide enough information to do syntax highlighting on the code. Not too familiar with the SO api but there may be a parameter to get more detailed html. Based on the output I see currently, there is no classname on the pre element to indicate the language of the codeblock. Assumptions here could lead to improper highlighting, if for example on a reference page to ruby, there is a codeblock of javascript, shell code, sql, etc.

3.) Any attempt to implement full syntax highlighting to cover all languages without a dependancy or library seems overkill. Each language would have to be parsed to properly determine keywords, strings, comments, type identifiers etc... and then the proper escape sequence would have to be prepended to the given token in a possibly cross-platform way.

4.) In what way would the user control this colour output and adjust colour themes. Should it take advantage of 256 colour functionality in terminals that are capable, or should it play it safe and use the user defined colour sequences?

5.) Should colour output be default or behind a flag?

Of course the highlighting could take a page from how2 and merely highlight the entire block a single colour, or implement a simple scheme where only primitives and keywords are highlighted in each supported language.

@alexrs
Copy link
Owner Author

alexrs commented Aug 7, 2016

I will try to answer point by point:

  1. I'm not interested in giving support to Windows. This is a pet project so I'm more interested in supporting those platforms I normally use: macOS and Linux.

  2. I'm not using the SO API. The way pop works is the following:

    • Make a request to Google specifying that StackOverflow is the website I'm interested in.
    • Get the links returned by that request. Select the first one and make a request to SO.
    • Parse the HTML obtained by the previous request, parse it and get the first answer (the most voted one)
    • Display the answer

    I'm not using the SO API because the search doesn't work well. I don't know if once I get the question URL from Google, I can use the SO API to get more info about the question. I'll take a look. Anyway, there are some techniques to recognise which programming language has been used, although I'm not an expert in this topic. I'll do some research!

  3. I know it seems overkill. It could be a parallel project that could be interesting to develop.

  4. Nowadays, most terminals of moderns SO (as I have said before, macOS and Linux) support 256 colours. Anyway, this point is not the one I'm most concern about.

  5. Color output should be behind a flag, but the user can also set an environment variable such as POP_COLORIZE_OUTPUT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants