提交 a2b07e2a 编写于 作者: 偏右

Merge pull request #408 from ant-design/feature-header-anchor

Add link anchor to every title in markdown document
......@@ -610,6 +610,22 @@ footer ul li > a {
margin: 0;
}
.markdown .anchor {
opacity: 0;
transition: opacity 0.3s ease;
margin-left: 8px;
}
.markdown h1:hover .anchor,
.markdown h2:hover .anchor,
.markdown h3:hover .anchor,
.markdown h4:hover .anchor,
.markdown h5:hover .anchor,
.markdown h6:hover .anchor {
opacity: 1;
display: inline-block;
}
#api ~ ul > li > p > strong ~ code {
background: #fff;
color: #CC7300;
......
......@@ -12,7 +12,7 @@
</a>
{%- endif %}
</h1>
{{ post.html }}
{{ post.html|add_anchor }}
</article>
{%- if post.meta.template === 'component' %}
{%- include "demos.html" %}
......
......@@ -18,7 +18,7 @@
<section class="main-container">
<article class="markdown">
<h1>{{ post.title }} {{ post.meta.chinese }}</h1>
{{ post.html }}
{{ post.html|add_anchor }}
</article>
</section>
{% endblock %}
......
......@@ -172,6 +172,13 @@ module.exports = function(nico) {
result.push(p);
});
return result;
},
add_anchor: function(content) {
for (var i = 1; i <= 6; i++) {
var reg = new RegExp('(<h' + i + '\\sid="(.*?)">.*?)(<\/h' + i + '>)', 'g');
content = content.replace(reg, '$1<a href="#$2" class="anchor">#</a> $3');
}
return content;
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册