Kramdown table 内容未显示在 HTML 块内

Kramdown table of content doesn't display inside HTML block

我一直在关注这个 ,但它似乎对我没有生效。任何帮助将不胜感激。

_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

结果:

更新

_layouts/site.html

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

它只是呈现如上。 Kramdown 在配置中打开。

理论上它应该那样工作,(它对我也不起作用)但是你可以像这样强制处理带有 `markdown="1" 的块内的代码:

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

确保您没有缩进 aside 标签内的代码,否则它将被解析为 kramdown 代码。

By default, kramdown parses all block HTML tags and all XML tags as raw HTML blocks. However, this can be configured with the parse_block_html. If this is set to true, then syntax parsing in HTML blocks is globally enabled. It is also possible to enable/disable syntax parsing on a tag per tag basis using the markdown attribute:

If an HTML tag has an attribute markdown="0", then the tag is parsed as raw HTML block.

If an HTML tag has an attribute markdown="1", then the default mechanism for parsing syntax in this tag is used.

更新

我已经检查了你的 repo,你 need toindex.html 重命名为 index.md 这样 kramdown 会解析它然后你也可以将行添加到 _config.yml 到解析 html 块内的降价。

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

.html markdown 解析器不处理文件。

如果您将文件从 .html 重命名为 .md,它将被处理为 kramdown。

但是你会遇到缩进问题。

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

使用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 }}