Markdown到HTML的可折叠标头 [英] Collapsible header in Markdown to html

查看:217
本文介绍了Markdown到HTML的可折叠标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们内部的git-lab Wiki与Markdown一起使用.我做了几篇文章的摘要,并希望将它们发布到我们的Wiki中,这样的话,如果我单击标题,标题应该展开并且文本应该变得可见,基本上就像这样

Our internal git-lab wiki works with Markdown. I made several summaries of articles and want to post them in our wiki, in such a way that if I click on the header, it should unfold and the text should become visible, basically like in this example

Markdown是否具有此展开/折叠/折叠功能?

Does Markdown have this expand/collapse/fold function?

推荐答案

简短的回答:不,Markdown不能直接提供类似的功能,但是通过一些工作,您也许可以构建出可以使用的功能.

Short Answer: No, Markdown does not offer a feature like that directly, but with some work you might be able to build something that works.

要使这样的功能正常工作,您将需要一些CSS和/或JavaScript来控制动画等.虽然您可以使该功能在任何HTML上运行,但在Markdown输出中并不是特别容易

For a feature like that to work you would need some CSS and/or JavaScript to control the animations, etc. While you might be able to get such a feature to work on any HTML, it is not particularly easy on Markdown output.

理想情况下,每个可折叠部分都将用div包裹:

Ideally, each collapsible section would be wrapped in a div:

<div id="section1">
  <h1>Section 1</h1>
  <p>Section 1 content</p>
  <div id="section1-1">
    <h2>Section1-1</h2>
    <p>section 1-1 content</p>
  </div>
    <div id="section1-2">
    <h2>Section1-2</h2>
    <p>section 1-2 content</p>
  </div>
</div>

然后,您可以使用一些CSS/JavaScript折叠各个部分.但是,Markdown没有节的概念.除了上面的内容,Markdown会为您提供这个简单的文档:

Then you can use some CSS/JavaScript to collapse the individual sections. However, Markdown does not have a concept of sections. Instead of the above, Markdown would give you this flat document:

<h1>Section 1</h1>
<p>Section 1 content</p>
<h2>Section1-1</h2>
<p>section 1-1 content</p>
<h2>Section1-2</h2>
<p>section 1-2 content</p>

一种解决方案将需要遍历整个文档,将其分解为各个部分,并将每个部分包装在div中.您可以找到夫妇 示例作为Python-Markdown解析器的扩展.但是,如果有关于您所处环境的任何信息,则将您指向正确的方向要困难一些.此外,Stackoverflow不应被视为工具推荐站点.但是,通过观察其他人如何解决该问题(在我所指出的示例中),您应该能够找到类似的解决方案.

A solution would require looping through the entire document, breaking it up into the various sections and wrapping each section in divs. You can find a couple examples of that as Extensions to the Python-Markdown Parser. However, with any information regarding the environment you are working in, It is a little more difficult to point you in the correct direction. Besides, Stackoverflow is not supposed to be a tool recommendation site. However, by observing how others have solved the problem (in the examples I pointed to) you should be able to work out a similar solution.

一旦您正确包装了各个部分,然后使用一些JavaScript折叠/折叠各个部分即可解决其余问题.但是,这是一个单独的问题,在这里已被多次询问和回答.请参阅侧栏中列出的一些相关"问题,以获取针对该部分问题的解决方案.

Once you get the sections properly wrapped, then a little JavaScript to fold/collapse the individual sections will take care of the rest. However, that is a separate issue which has been asked and answered many times here. See some of the "Related" questions listed on the sidebar for solutions to that part of the problem.

甚至有可能存在一些JavaScript库,这些JavaScript库将采用纯HTML内容,进行部分包装并全部实现折叠/折叠功能.但是,这样的库可能会有点沉重,并且会降低您的网站速度,因此请继续执行阳离子操作.

It is even possible that some JavaScript libraries exist which will take the plain HTML content, do the section wrapping and implement the fold/collapse feature all in one. However, such a library may be a little heavy and slow down your site, so proceed with cation.

这篇关于Markdown到HTML的可折叠标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆