Kramdown内容表不会显示在HTML块内

时间:2017-05-10 21:37:07

标签: jekyll github-pages kramdown

我正在关注此question,但它似乎并没有对我生效。任何帮助将不胜感激。

_includes /的layout.html

<main>
<div>
<!-- Sidebar -->
<aside markdown="1">
<h4>Table of Contents</h4>
* ToC
{:toc}
</aside>
<!-- END Sidebar -->

<!-- Main content -->
<article>
{{ content }}
</article>
<!-- END Main content -->
</div>
</main>

_config.yml

markdown: kramdown

结果:

enter image description here

更新

_layouts / site.html

<aside markdown="1">
mark**down**
</aside>

它只是如上所示。在配置中打开Kramdown。

3 个答案:

答案 0 :(得分:2)

使用pure liquid ToC by allejo解决。

% capture tocWorkspace %}
{% comment %}
    "...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe

    Usage:
        {% include toc_pure_liquid.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3  %}

    Parameters:
        * html     (string) - the HTML of compiled markdown generated by kramdown in Jekyll

    Optional Parameters:
        * sanitize (bool)   : false  - when set to true, the headers will be stripped of any HTML in the TOC
        * class    (string) :   ''   - a CSS class assigned to the TOC
        * id       (string) :   ''   - an ID to assigned to the TOC
        * h_min    (int)    :   1    - the minimum TOC header level to use; any header lower than this value will be ignored
        * h_max    (int)    :   6    - the maximum TOC header level to use; any header greater than this value will be ignored

    Output:
        An unordered list representing the table of contents of a markdown block. This snippet will only generate the table of contents and will NOT output the markdown given to it
{% endcomment %}

{% capture my_toc %}{% endcapture %}
{% assign minHeader = include.h_min | default: 1 %}
{% assign maxHeader = include.h_max | default: 6 %}
{% assign nodes = include.html | split: '<h' %}
{% for node in nodes %}
    {% if node == "" %}
        {% continue %}
    {% endif %}
    {% assign headerLevel = node | replace: '"', '' | slice: 0, 1 %}
    {% assign headerLevel = headerLevel | times: 1 %}
    {% assign indentAmount = headerLevel | minus: minHeader | add: 1 %}
    {% assign _workspace = node | split: '</h' %}
    {% unless headerLevel >= minHeader %}
        {% continue %}
    {% endunless %}
    {% if headerLevel > maxHeader %}
        {% continue %}
    {% endif %}
    {% assign _idWorkspace = _workspace[0] | split: '"' %}
    {% assign html_id = _idWorkspace[1] %}
    {% capture _hAttrToStrip %}{{ headerLevel }} id="{{ html_id }}">{% endcapture %}
    {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
    {% assign space = '' %}
    {% for i in (1..indentAmount) %}
        {% assign space = space | prepend: '  ' %}
    {% endfor %}
    {% capture my_toc %}{{ my_toc }}
{{ space }}- [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}](#{{ html_id }}){% endcapture %}
    {% endfor %}
    {% if include.class %}
        {% capture my_toc %}{:.{{ include.class }}}
{{ my_toc | lstrip }}{% endcapture %}
    {% endif %}
    {% if include.id %}
        {% capture my_toc %}{: #{{ include.id }}}
{{ my_toc | lstrip }}{% endcapture %}
    {% endif %}
{% endcapture %}{% assign tocWorkspace = '' %}
{{ my_toc | markdownify }}

答案 1 :(得分:1)

理论上它应该以这种方式工作,(它对我来说也不起作用)但你可以用`markdown =&#34; 1&#34;强制处理块内的代码。像这样:

<aside markdown="1">
<h4>Table of Contents</h4>
* ToC
{:toc}
</aside>

请确保您不要缩进aside标记内的代码,否则它将被解析为kramdown代码。

  

默认情况下,kramdown将所有块HTML标记和所有XML标记解析为   原始HTML块。但是,这可以配置   parse_block_html。如果将其设置为true,则在HTML中进行语法分析   块已全局启用。也可以启用/禁用   使用markdown属性在每个标记的标记上进行语法解析:

     

如果HTML标记的属性为markdown =&#34; 0&#34;,则标记将被解析为原始HTML块。

     

如果HTML标记具有markdown =&#34; 1&#34;属性,则使用此标记中解析语法的默认机制。

更新

我已检查过您的回购,need toindex.html重命名为index.md,因此kramdown会解析它,然后您也可以将该行添加到_config.yml在html块中解析markdown。

答案 2 :(得分:0)

Jekyll只解析.md.mardown个文件。

降价解析器不会删除

.html个文件。

如果您将文件从.html重命名为.md,则会将其作为kramdown处理。

但是你会有缩进问题。

混合html和markdown并不容易; - )