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

feat: add highlight.js #303

Merged
merged 1 commit into from
Dec 2, 2022
Merged

feat: add highlight.js #303

merged 1 commit into from
Dec 2, 2022

Conversation

clason
Copy link
Member

@clason clason commented Nov 23, 2022

used for syntax highlighting of annotated code examples

neovim.min.css provided by @rockerBOO

Dark theme:

Screenshot 2022-11-26 at 11 41 18

Light theme:

Screenshot 2022-11-26 at 11 41 04

closes #302

@clason clason marked this pull request as draft November 23, 2022 14:10
@clason clason marked this pull request as ready for review November 23, 2022 21:29
@rockerBOO
Copy link
Contributor

Made a demo using tokyo night dark/light. I think this is the most popular colorscheme for Neovim right now.

https://codepen.io/rockerboo/pen/KKeRERd

And a repo for building it out. I have a neovim.min.css you should be able to drop in. We can further tweak the colors as we go.

https://github.com/rockerBOO/neovim-highlight-colorscheme

@rockerBOO
Copy link
Contributor

Screenshot 2022-11-25 at 15-48-29 Neovim highlightjs
Screenshot 2022-11-25 at 15-47-10 Neovim highlightjs

@rockerBOO
Copy link
Contributor

Also base 16 based colors so theres a bunch of options out there like the ones in https://github.com/RRethy/nvim-base16

@clason
Copy link
Member Author

clason commented Nov 25, 2022

Thanks! I stuck with these since Justin seems very keen on the general colorscheme, so I wanted to exactly match the background. (And I kinda prefer the light green to your grey...)

Highlight.js has a bunch of base16 styles which I looked through as well.

Anyway, I personally don't have any strong preferences and will happily use whatever style is preferred!

@rockerBOO
Copy link
Contributor

Ok perfect, I can fix the light scheme some.

I also noticed we are already plumbed for highlighting on the site right now. Possibly something in jekyll adding the tags in the code. Maybe we can style that up instead/as well. I think having a non-JS highlighting is better generally, but we can apply highlight.js where this is not available.

From /news/

<div class="highlight"><pre class="highlight"><code><span class="c1">-- Using a Lua function in a key mapping prior to 0.7</span>
<span class="kd">local</span> <span class="k">function</span> <span class="nf">say_hello</span><span class="p">()</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">"Hello world!"</span><span class="p">)</span>
<span class="k">end</span>

<span class="n">_G</span><span class="p">.</span><span class="n">my_say_hello</span> <span class="o">=</span> <span class="n">say_hello</span>

<span class="n">vim</span><span class="p">.</span><span class="n">api</span><span class="p">.</span><span class="n">nvim_set_keymap</span><span class="p">(</span><span class="s2">"n"</span><span class="p">,</span> <span class="s2">"&lt;leader&gt;H"</span><span class="p">,</span> <span class="s2">"&lt;Cmd&gt;call v:lua.my_say_hello()&lt;CR&gt;"</span><span class="p">,</span> <span class="p">{</span><span class="n">noremap</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
</code></pre></div>

We can tweak the colors some to match the some green/blue we use away from tokyo night.

I'll look into the highlighter working on the website.

@clason
Copy link
Member Author

clason commented Nov 25, 2022

I also noticed we are already plumbed for highlighting on the site right now

That doesn't sound right. I don't see any actual syntax highlighting working. (We also need to support explicit language annotations, since our snippets are usually too short to automatically recognize vimscript.)

But, sure, if there's a lighter alternative to highlight.js, I don't mind!

@rockerBOO
Copy link
Contributor

It seems to support the same way github works, ```lua

Uses https://github.com/rouge-ruby/rouge , see _config.yaml for highlighter

We can use https://github.com/rouge-ruby/rouge#command-line to generate the css and then include that css file.

Color changes

Here are the new colors for light dark using our accent-bg-color from the site. Updated css at rockerBOO/neovim-highlight-colorscheme

Screenshot 2022-11-25 at 16-53-11 Screenshot
Screenshot 2022-11-25 at 16-53-02 Screenshot

@clason
Copy link
Member Author

clason commented Nov 25, 2022

Here are the new colors for light dark using our accent-bg-color from the site.

Nice!

It seems to support the same way github works, ```lua

so instead of <pre><code> ... </code></pre> blocks, I should just use wrap the markdown fenced block in <pre>...</pre>?

@rockerBOO
Copy link
Contributor

It seems to support the same way github works, ```lua

so instead of <pre><code> ... </code></pre> blocks, I should just use wrap the markdown fenced block in <pre>...<pre>?

Not sure what you mean here. If we use the jekyll/rogue option we are good with just adding the css. If theres a place outside that we can use highlight.js to handle that.

Did a quick pass for the jekyll/rogue option at #304

@clason
Copy link
Member Author

clason commented Nov 25, 2022

I mean, how should the html sources look like? We want to add language annotations in general, and I need to change the HTML generator to do that. I've done this for highlight.js, but I have no idea what the Jekyll one expects.

@rockerBOO
Copy link
Contributor

jekyll has a plugin that is already doing it. See the HTML for this page https://neovim.io/news/, the code blocks have the spans inside the pre.

@clason
Copy link
Member Author

clason commented Nov 25, 2022

Yeah, I don't see any syntax highlighting there. Just a bunch of random spans.

Again, I want to manually annotate the code blocks as "vim", "lua", "python", ..., and highlight them accordingly. I don't think we can rely on automatic language detection.

@rockerBOO
Copy link
Contributor

Yeah the span are what I am styling in that PR I linked above, #304.

The spans are from rogue which used the pygment format. You can see colorschemes using that format.

The spans are generated from the type of file it's highlighting, and inside our posts/ markdown we'd use the github syntax and it'll do the rest.

The fenced areas in the latest news items.

@clason
Copy link
Member Author

clason commented Nov 25, 2022

That was exactly what I was asking. So I should use Markdown fenced codeblocks instead of <code>...</code> blocks in the generated HTML.

@clason
Copy link
Member Author

clason commented Nov 25, 2022

Unfortunately, the generator script doesn't like backticks...

@rockerBOO
Copy link
Contributor

I have been mentioning mostly about neovim.github.io, but I think you're working with the doc generator for the neovim docs? So I would imagine that would be different, and also not have the rogue/jekyll things.

I would keep the HTML like suggested with highlight.js.

<pre><code class="language-html">...</code></pre>

And now I understand why it will be hard to know what language it is showing with snippets and the vimdoc.

Well, now we should be good on the colors for the moment.

@clason
Copy link
Member Author

clason commented Nov 25, 2022

I have been mentioning mostly about neovim.github.io, but I think you're working with the doc generator for the neovim docs?

No, that part is working fine. I'm talking here only about neovim.github.io/doc/ (although of course I can only test locally by running jekyll serve --host, where the backticks don't work). The docs already have the annotation (see the linked Neovim PR near the top here); the question is how to make Jekyll use it. I got it working with highlight.js, but I'm happy to use anything else -- if someone tells me how to ;)

@clason
Copy link
Member Author

clason commented Nov 25, 2022

In any case, I'll happily switch to your css tomorrow :)

@rockerBOO
Copy link
Contributor

Ok neovim.github.io/doc/, this individual page is made by jekyll but other paths under, like https://neovim.io/doc/user/, are generated in that other vimdoc script. jekyll doesn't touch those other pages, so we can't use the rogue syntax highlighter from jekyll for those. At least not easily.

So highlight.js for the reference manual and the rogue highlighting for the main site. My other PR will handle the main site.

@clason
Copy link
Member Author

clason commented Nov 26, 2022

Ah, ok, thank you for explaining, now I understand!

Then let's proceed like you suggest:

  1. merge this PR (with your updated CSS) for /doc/user
  2. merge your PR for the main site
  3. tweak both themes (or use the same for both) to taste

used for syntax highlighting of annotated code examples

theme by @rockerBOO
@clason clason merged commit ccf6a75 into neovim:master Dec 2, 2022
@clason clason deleted the highlight.js branch December 2, 2022 15:00
@justinmk
Copy link
Member

justinmk commented Dec 8, 2022

Is it time to start a section in the readme mentioning various components like this?

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

Successfully merging this pull request may close these issues.

Use highlight.js for syntax highlighted code blocks?
3 participants