Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Markdown 标记以创建页面和目录?_Markdown_Tableofcontents - Fatal编程技术网

Markdown 标记以创建页面和目录?

Markdown 标记以创建页面和目录?,markdown,tableofcontents,Markdown,Tableofcontents,我开始用降价记笔记 我使用marked查看我的降价笔记和它的美丽 但随着我的笔记越来越长,我发现很难找到我想要的东西 我知道markdown可以创建表,但是它能够创建目录,跳转到节,或者在markdown中定义页面节吗 或者,是否有降价读者/编辑可以做这样的事情。搜索也是一个很好的功能 简而言之,我想让它成为我最棒的笔记工具和功能,就像写书一样。似乎确实生成了一个目录来帮助编辑 可能还有一个或另一个库可以生成TOC:请参阅。我刚刚为python标记编写了一个扩展,它使用解析器检索标题,并输出一个

我开始用降价记笔记

我使用marked查看我的降价笔记和它的美丽

但随着我的笔记越来越长,我发现很难找到我想要的东西

我知道markdown可以创建表,但是它能够创建目录,跳转到节,或者在markdown中定义页面节吗

或者,是否有降价读者/编辑可以做这样的事情。搜索也是一个很好的功能

简而言之,我想让它成为我最棒的笔记工具和功能,就像写书一样。

似乎确实生成了一个目录来帮助编辑


可能还有一个或另一个库可以生成TOC:请参阅。

我刚刚为
python标记编写了一个扩展,它使用解析器检索标题,并输出一个TOC作为标记格式的无序列表,带有本地链接。文件是

  • (曾)
。。。它应该放在markdown安装的
markdown/extensions/
目录中。然后,您所要做的就是键入带有
id=“…”
属性作为参考的锚定
标记-对于这样的输入文本:

$ cat test.md 
Hello
=====

## <a id="sect one"></a>SECTION ONE ##

something here

### <a id='sect two'>eh</a>SECTION TWO ###

something else

#### SECTION THREE

nothing here

### <a id="four"></a>SECTION FOUR

also...
<div id="heading--1-1"/>
### 1.1. Markdown formatting cheatsheet
。。。然后,您可以将此toc粘贴回标记文档中(或者在文本编辑器中有一个快捷方式,该快捷方式调用当前打开的文档上的脚本,然后在同一文档中插入生成的toc)

请注意,
python markdown
的旧版本没有
\uuuu main\uuuu.py
模块,因此,上面的命令行调用对于这些版本不起作用

您可以尝试从降价文件生成TOC

 #!/usr/bin/env ruby

require 'uri'

fileName = ARGV[0]
fileName = "README.md" if !fileName

File.open(fileName, 'r') do |f|
  inside_code_snippet = false
  f.each_line do |line|
    forbidden_words = ['Table of contents', 'define', 'pragma']
    inside_code_snippet = !inside_code_snippet if line.start_with?('```')
    next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ } || inside_code_snippet

    title = line.gsub("#", "").strip
    href = URI::encode title.gsub(" ", "-").downcase
    puts "  " * (line.count("#")-1) + "* [#{title}](\##{href})"
  end
end

如果您想使用javascript/node.js工具,请查看

根据您的工作流程,您可能需要查看

这是原始目录()的一个分支,它添加了内容表的生成


repo上有一个apache配置文件(可能还没有正确更新),如果您不喜欢用html文件编写,可以动态地包装普通标记。

我刚刚开始做同样的事情(在标记中记笔记)。我使用升华文本2和。内置的标记解析器支持
[TOC]

您可以尝试一下

# Table of Contents
1. [Example](#example)
2. [Example2](#example2)
3. [Third Example](#third-example)
4. [Fourth Example](#fourth-examplehttpwwwfourthexamplecom)


## Example
## Example2
## Third Example
## [Fourth Example](http://www.fourthexample.com) 

有两种方法可以在降价文档中创建您的TOC(摘要)

1.人工
#我的目录
-[第1节](#id-第1节)
-[第2节](#id-第2节)
##第一节
##第二节
2.编程的 例如,您可以使用生成摘要的脚本,查看github上的我的项目--


我也尝试过其他脚本/npm模块(例如),但没有人使用工作锚重现TOC。

我编写了一个python脚本,解析标记文件并输出目录作为标记列表:


与我发现的其他脚本不同,md-to-toc正确地支持重复的标题。它也不需要互联网连接,所以它适用于任何md文件,而不仅仅是那些可以从公共回购协议获得的文件

这里有一个有用的方法。应该在任何标记编辑器中生成可单击的引用

# Table of contents
1. [Introduction](#introduction)
2. [Some paragraph](#paragraph1)
    1. [Sub paragraph](#subparagraph1)
3. [Another paragraph](#paragraph2)

## This is the introduction <a name="introduction"></a>
Some introduction text, formatted in heading 2 style

## Some paragraph <a name="paragraph1"></a>
The first paragraph text

### Sub paragraph <a name="subparagraph1"></a>
This is a sub paragraph, formatted in heading 3 style

## Another paragraph <a name="paragraph2"></a>
The second paragraph text
#目录
1.[导言](#导言)
2.[某些段落](#第1段)
1.[分段](#第1分段)
3.[另一段](#第2段)
##这是导言
  • 这是导言 一些介绍文本,格式为标题2样式

    某段 第一段案文

    分段 这是一个分段,格式为标题3样式

    另一段
    基于albertodebortoli答案的第二段文本

    创建了带有额外检查和标点符号替换的函数

    # @fn       def generate_table_of_contents markdown # {{{
    # @brief    Generates table of contents for given markdown text
    #
    # @param    [String]  markdown Markdown string e.g. File.read('README.md')
    #
    # @return   [String]  Table of content in markdown format.
    #
    def generate_table_of_contents markdown
      table_of_contents = ""
      i_section = 0
      # to track markdown code sections, because e.g. ruby comments also start with #
      inside_code_section = false
      markdown.each_line do |line|
        inside_code_section = !inside_code_section if line.start_with?('```')
    
        forbidden_words = ['Table of contents', 'define', 'pragma']
        next if !line.start_with?('#') || inside_code_section || forbidden_words.any? { |w| line =~ /#{w}/ }
    
        title = line.gsub("#", "").strip
        href = title.gsub(/(^[!.?:\(\)]+|[!.?:\(\)]+$)/, '').gsub(/[!.,?:; \(\)-]+/, "-").downcase
    
        bullet = line.count("#") > 1 ? " *" : "#{i_section += 1}."
        table_of_contents << "  " * (line.count("#") - 1) + "#{bullet} [#{title}](\##{href})\n"
      end
      table_of_contents
    end
    
    #@fn def生成内容标记的表{{{
    #@brief为给定的标记文本生成目录
    #
    #@param[String]标记字符串标记字符串,例如File.read('README.md')
    #
    #@return[String]降价格式的内容表。
    #
    def生成内容标记的表格
    表_of_contents=“”
    i_段=0
    #跟踪标记代码部分,因为例如ruby注释也以#
    内部代码部分=错误
    markdown.每行做一行|
    内部代码部分=!内部代码部分如果行。以?(“````开头)
    禁止使用的单词=[“目录”、“定义”、“布拉格”]
    下一个if!line.以“(“#”)| | | |内部代码| |部分| |禁止的|单词开头。任何{{w | line=~/{w}
    title=line.gsub(“#“,”).strip
    href=title.gsub(/(^[!。?:\(\)]+[!。?:\(\)]+$)/,'').gsub(/[!,?:;\(\)-]+/,“-”).downcase
    bullet=line.count(“#”)大于1?”*:“#{i#u节+=1}。”
    
    为方便我们制作
    README.md
    文件(我是如何找到这个线程的):


    通过向文档中添加
    [TOC]
    来生成内容表。

    由不同的标记解析器生成的锚定标记并不均匀

    如果您正在使用Markdown解析器GFM(GitHub风格的Markdown)或Red地毯,我编写了一个Vim插件来处理目录

    特征
  • 生成标记文件的目录

    支持的标记分析器:

    • GFM(GitHub风味降价)
    • 红地毯
  • 更新现有目录

  • 保存时自动更新现有目录

  • 截图

    用法 生成目录

    将光标移动到要附加目录的行,然后在下面键入适合您的命令。该命令将在光标插入目录后生成标题

  • :GenTocGFM

    生成GFM链接样式的目录

    此命令适用于GitHub存储库中的标记文件(如README.md)和GitBook的标记文件

  • :GenTocR
    
    # @fn       def generate_table_of_contents markdown # {{{
    # @brief    Generates table of contents for given markdown text
    #
    # @param    [String]  markdown Markdown string e.g. File.read('README.md')
    #
    # @return   [String]  Table of content in markdown format.
    #
    def generate_table_of_contents markdown
      table_of_contents = ""
      i_section = 0
      # to track markdown code sections, because e.g. ruby comments also start with #
      inside_code_section = false
      markdown.each_line do |line|
        inside_code_section = !inside_code_section if line.start_with?('```')
    
        forbidden_words = ['Table of contents', 'define', 'pragma']
        next if !line.start_with?('#') || inside_code_section || forbidden_words.any? { |w| line =~ /#{w}/ }
    
        title = line.gsub("#", "").strip
        href = title.gsub(/(^[!.?:\(\)]+|[!.?:\(\)]+$)/, '').gsub(/[!.,?:; \(\)-]+/, "-").downcase
    
        bullet = line.count("#") > 1 ? " *" : "#{i_section += 1}."
        table_of_contents << "  " * (line.count("#") - 1) + "#{bullet} [#{title}](\##{href})\n"
      end
      table_of_contents
    end
    
    apm install markdown-toc
    
    ./pandoc -s --toc input.md -o output.html
    
    ext install yzhang.markdown-all-in-one
    
    ext install markdown-toc
    
    # Table of Contents
    1. [Example](#example)
    2. [Example2](#example2)
    3. [Third Example](#third-example)
    
    ## Example [](#){name=example}
    ## Example2 [](#){name=example2}
    ## [Third Example](#){name=third-example}
    
    echo "## Contents" ; echo ; 
    cat FILE.md | grep '^## ' | grep -v Contents | sed 's/^## //' | 
      while read -r title ; do 
        link=$(echo $title | tr 'A-Z ' 'a-z-') ; 
        echo "- [$title](#$link)" ; 
        done
    
    # Lorem Ipsum
    
    Lorem ipsum dolor sit amet, mei alienum adipiscing te, has no possit delicata. Te nominavi suavitate sed, quis alia cum no, has an malis dictas explicari. At mel nonumes eloquentiam, eos ea dicat nullam. Sed eirmod gubergren scripserit ne, mei timeam nonumes te. Qui ut tale sonet consul, vix integre oportere an. Duis ullum at ius.
    
    ## Et cum
    
    Et cum affert dolorem habemus. Sale malis at mel. Te pri copiosae hendrerit. Cu nec agam iracundia necessitatibus, tibique corpora adipisci qui cu. Et vix causae consetetur deterruisset, ius ea inermis quaerendum.
    
    ### His ut
    
    His ut feugait consectetuer, id mollis nominati has, in usu insolens tractatos. Nemore viderer torquatos qui ei, corpora adipiscing ex nec. Debet vivendum ne nec, ipsum zril choro ex sed. Doming probatus euripidis vim cu, habeo apeirian et nec. Ludus pertinacia an pro, in accusam menandri reformidans nam, sed in tantas semper impedit.
    
    ### Doctus voluptua
    
    Doctus voluptua his eu, cu ius mazim invidunt incorrupte. Ad maiorum sensibus mea. Eius posse sonet no vim, te paulo postulant salutatus ius, augue persequeris eum cu. Pro omnesque salutandi evertitur ea, an mea fugit gloriatur. Pro ne menandri intellegam, in vis clita recusabo sensibus. Usu atqui scaevola an.
    
    ## Id scripta
    
    Id scripta alterum pri, nam audiam labitur reprehendunt at. No alia putent est. Eos diam bonorum oportere ad. Sit ad admodum constituto, vide democritum id eum. Ex singulis laboramus vis, ius no minim libris deleniti, euismod sadipscing vix id.
    
    $ mdtoc.rb FILE.md 
    #### Table of contents
    
    1. [Et cum](#et-cum)
        * [His ut](#his-ut)
        * [Doctus voluptua](#doctus-voluptua)
    2. [Id scripta](#id-scripta)
    
    $ cat README.md | ./gh-md-toc -
    
    # Table of Contents
    1. [Title](#title) <br>
        1.1. [sub-title](#sub_title) <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.1.1. [sub-sub-title](#sub_sub_title)
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.1.1.1. [sub-sub-sub-title](#sub_sub_sub_title)
    
    # Title <a name="title"></a>
    Heading 1
    
    ## Sub-Title <a name="sub_title"></a>
    Heading 2
    
    ### Sub-Sub-Title <a name="sub_sub_title"></a>
    Heading 3
    
    #### Sub-Sub-Sub-Title <a name="sub_sub_sub_title"></a>
    Heading 4
    
    ## Content
    
    **[1. Markdown](#heading--1)**
    
      * [1.1. Markdown formatting cheatsheet](#heading--1-1)
      * [1.2. Markdown formatting details](#heading--1-2)
    
    **[2. BBCode formatting](#heading--2)**
    
      * [2.1. Basic text formatting](#heading--2-1)
    
          * [2.1.1. Not so basic text formatting](#heading--2-1-1)
    
      * [2.2. Lists, Images, Code](#heading--2-2)
      * [2.3. Special features](#heading--2-3)
    
    ----
    
    <div id="heading--1-1"/>
    ### 1.1. Markdown formatting cheatsheet
    
    ### 1.1. Markdown formatting cheatsheet <a name="heading--1-1"/>
    
    {
      "defaults": {
        "autoanchor": true,
        "autolink": true,
        "bracket": "round",
        "levels": [1,2,3,4,5,6],
        "indent": "\t",
        "remove_image": true,
        "link_prefix": "",
        "bullets": ["-"],
        "lowercase": "only_ascii",
        "style": "ordered",
        "uri_encoding": true,
        "markdown_preview": ""
      },
      "id_replacements": [
        {
          "pattern": "\\s+",
          "replacement": "-"
        },
        {
          "pattern": "&lt;|&gt;|&amp;|&apos;|&quot;|&#60;|&#62;|&#38;|&#39;|&#34;|!|#|$|&|'|\\(|\\)|\\*|\\+|,|/|:|;|=|\\?|@|\\[|\\]|`|\"|\\.|\\\\|<|>|{|}|™|®|©|%",
          "replacement": ""
        }
      ],
      "logging": false
    }