Skip to content

Code Block Rendering Problem #902

@xing5

Description

@xing5

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions