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 Block Rendering Problem #902

Closed
xing5 opened this Issue Nov 7, 2014 · 1 comment

Comments

1 participant
@xing5

xing5 commented Nov 7, 2014

Input:

/**
 * Establishes a contract for reading events stored in arbitrary formats from
 * reliable, resettable streams.
 */
@InterfaceAudience.Public
@InterfaceStability.Evolving
public interface EventDeserializer extends Resettable, Closeable {

Output (wrong format around span.javadoc):

<div class="line"><span class="javadoc">/**</div>
<div class="line"> * Establishes a contract for reading events stored in arbitrary formats from</div>
<div class="line"> * reliable, resettable streams.</div>
<div class="line"> */</span></div>
<div class="line"><span class="annotation">@InterfaceAudience</span>.Public</div>
<div class="line"><span class="annotation">@InterfaceStability</span>.Evolving</div>
<div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">EventDeserializer</span> <span class="keyword">extends</span> <span class="title">Resettable</span>, <span class="title">Closeable</span></span>{</div>

Both backtick and code block plugins in Hexo wrap each line with a div.line, but the output from Highlightjs could contain html tags that cross multiple lines. Take the code above as a example, the output from Highlightjs is:

<span class="hljs-javadoc">/**
 * Establishes a contract for reading events stored in arbitrary formats from
 * reliable, resettable streams.
 */</span>
<span class="hljs-annotation">@InterfaceAudience</span>.Public
<span class="hljs-annotation">@InterfaceStability</span>.Evolving
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">EventDeserializer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Resettable</span>, <span class="hljs-title">Closeable</span> </span>{

Hexo splits the output from highlightjs and wrap every line with a div.line. I think Hexo does so to support the line numbers because Highlightjs doesn't (http://highlightjs.readthedocs.org/en/latest/line-numbers.html). However, even if you configure the line-number to false in highlight section of _config.yml, Hexo still does the wrapping.

I did some small modification to cancel the wrapping, if someone wants to do this as well, please look into lib/plugins/filter/backtick_code_block.js and lib/plugins/tag/code.js, these two files pass configurations to lib/util/highlight.js, where the wrapping happens.

@xing5

This comment has been minimized.

Show comment
Hide comment
@xing5

xing5 Nov 7, 2014

#904

Got a solution.

xing5 commented Nov 7, 2014

#904

Got a solution.

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