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

How to generate highlightjs's style of codeblock #2145

Closed
xcatliu opened this issue Sep 6, 2016 · 10 comments
Closed

How to generate highlightjs's style of codeblock #2145

xcatliu opened this issue Sep 6, 2016 · 10 comments

Comments

@xcatliu
Copy link

xcatliu commented Sep 6, 2016

Using the default config will generate code block like this:

<figure class="highlight plain"><table><tbody>
  <tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">@<span class="keyword">import</span> <span class="string">'mobi.css/src/mobi'</span>;</div></pre></td></tr>
</tbody></table></figure>

Is there a way to generate code block like the official highlightjs's stlye?

<pre><code class="hljs scss">
  @<span class="hljs-keyword">import</span> <span class="hljs-string">'mobi.css/src/mobi'</span>;
</code></pre>
@stackOverMind
Copy link

gutter can be removed by setting:

highlight:
  enable: true
  line_number: false
  auto_detect: false
  tab_replace:

@xcatliu
Copy link
Author

xcatliu commented Sep 7, 2016

@stackOverMind Setting line-number to false will only disable lines, but the generated code is still <figure><table>, how to generate <pre><code> like http://highlightjs.org did? Then I can reuse all the styles that http://highlightjs.org provides.

@leggetter
Copy link

@xcatliu The code for highlight is available via https://github.com/hexojs/hexo-util/blob/master/lib/highlight.js

So, you could take that and customise it to suit your needs. I think that's something we may do as we want to make the code highlighting functionality more of our own.

Maybe build your own tag that uses the functionality.

@bensmithett
Copy link

I had this problem too. It seems like hexo was configured to use the old non-hljs style way back in 001b89d to fix #434.

I think this block is the problem - seems odd to kill highlight's default, good-for-css-architecture behaviour in hexo to fix a CSS problem in some hexo themes.

Happy to PR up a change reversing this if anyone involved thinks it's a good idea?

@NoahDragon
Copy link
Member

@bensmithett Agree. The classPrefix: '' should be configurable in _config.yml.

@mathiasbynens
Copy link

mathiasbynens commented Jul 11, 2017

+1 to somehow making it easy to customize highlight output. Being able to define a custom util.highlight would be an elegant solution.

In my case, I want something like:

<pre><code class="language-%language%">%code%</code></pre>

The classPrefix thing is a separate (but related) issue.

@matthidinger
Copy link

I see the latest version of the code has references to <pre><code> but I can't quite figure out how to activate it. Is the workaround mentioned in this issue still necessary or has another trick been added?

@alxbl
Copy link
Contributor

alxbl commented Jul 22, 2019

@matthidinger Hey, sorry for the late reply, I've been busy with other stuff. Unless the highlighting code has changed since, the PR I made (hexojs/hexo-util#30) should still work, that is, you can add hljs: true in your highlight section to get the rendering with Highlight.js.

I'm not an active contributor so I haven't been keeping up with latest development, but if it doesn't work for you, let me know and I'll look into it.

Cheers,
Alex

@stevenjoezhang
Copy link
Member

hljs: true worked like a charm. Maybe this issue can be closed.

@SukkaW
Copy link
Member

SukkaW commented Dec 23, 2019

# _config.yml
highlight:
  enable: true
  hljs: true
  wrap: true

The config should be all right then. Works on Hexo 4.0.0 or later.

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

No branches or pull requests

10 participants