【发布时间】:2009-03-06 12:35:12
【问题描述】:
我目前正在运行一个基于 PHP 的内容管理系统,它在 Markdown Extra 的帮助下生成其 HTML 内容。大多数内容由标题和子标题构成,导致页面很长。在每一页的开头,我借助一个列表和Markdown Extra's Header Id Attribute 创建了一个目录。
为了缩短页面视图的长度,我想在第一级标题上使用 jQuery 的 Tabs Plugin。
问题在于 Markdown Extra 的输出与 jQuery Tabs Plugin 所期望的不兼容,因为 Markdown Extra 没有将部分的内容包装到单独的 div 标记中。
有没有办法让这两个库一起工作?
编辑
这是 HTML 输出的样子:
<p>Some intro text...</p>
<h3>Table of content</h3>
<ul>
<li><a href="#sub1">Topic 1</a></li>
<li><a href="#sub2">Topic 2</a></li>
<li><a href="#sub3">Topic 3</a></li>
</ul>
<h3 id="sub1">Topic 1</h3>
<p>The content of this topic.</p>
<h3 id="sub2">Topic 2</h3>
<p>The content of this topic.</p>
<h3 id="sub3">Topic 3</h3>
<p>The content of this topic.</p>
.. 这是对应的 Markdown 代码:
Some intro text...
###Table of content###
* [Topic 1](#sub1)
* [Topic 2](#sub2)
* [Topic 3](#sub3)
###Topic 1### {#sub1}
The content of this topic.
###Topic 2### {#sub2}
The content of this topic.
###Topic 3### {#sub3}
The content of this topic.
解决方案
在 cobbal 的帮助下,我做了这个 jQuery 语句,它将 Markdown 标记转换为 Tabs 插件可以使用的东西:
$("#tabs :header").each(function()
{
var id = $(this).attr("id");
if(id=="") return;
var div = $("<div>");
var tagName = this.tagName;
$(this).nextAll().each(function()
{
if(this.tagName==tagName) return false;
div.append(this);
});
$(this).removeAttr("id");
div.attr("id", id);
$(this).before(div);
div.prepend(this);
});
但事实上,我需要转换标记以适应 Tabs 插件,而不仅仅是告诉 Tabs 插件它应该以不同的方式选择其内容,这一事实可能使该解决方案不是理想的解决方案。
【问题讨论】:
-
你能发布一个markdown Extra输出的代码示例吗?
标签: javascript jquery tabs markdown