Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, March 8, 2017

Markdown to create pages and table of contents?

Markdown to create pages and table of contents?


I started to use mardown to take notes.

I use marked to view my markdown notes and its beautiful.

But as my notes get longer I find it difficult to find what I want.

I know markdown can create tables, but is it able to create table of contents, that jumps to sections, or define page sections in markdown?

Alternatively, are there markdown readers/editors that could do such things. Search would be good feature to have too.

In short, I want to make it my awesome note taking tool and functions much like writing a book etc.

Answer by mxro for Markdown to create pages and table of contents?


MultiMarkdown Composer does seem to generate a table of contents to assist while editing.

There might also be the one or the other library, who can generate TOCs: see Python Markdown TOC Extension.

Answer by sdaau for Markdown to create pages and table of contents?


I just coded an extension for python-markdown, which uses its parser to retrieve headings, and outputs a TOC as Markdown-formatted unordered list with local links. The file is

... and it should be placed in markdown/extensions/ directory in the markdown installation. Then, all you have to do, is type anchor tags with an id="..." attribute as a reference - so for an input text like this:

$ cat test.md   Hello  =====    ## SECTION ONE ##    something here    ### ehSECTION TWO ###    something else    #### SECTION THREE    nothing here    ### SECTION FOUR    also...  

... the extension can be called like this:

$ python -m markdown -x md_toc test.md   * Hello      * [SECTION ONE](#sect one)          * [SECTION TWO](#sect two)              * SECTION THREE          * [SECTION FOUR](#four)  

... and then you can paste back this toc in your markdown document (or have a shortcut in your text editor, that calls the script on the currently open document, and then inserts the resulting TOC in the same document).

Note that older versions of python-markdown don't have a __main__.py module, and as such, the command line call as above will not work for those versions.

Answer by user2502476 for Markdown to create pages and table of contents?


Um... use Markdown's headings!?

That is:

# This is the equivalent of < h1 >

## This is the equivalent of < h2>

### This is the equivalent of < h3>

Many editors will show you a TOC. You can also grep for the heading tags and create your own.

Hope that helps!

--JF

Answer by albertodebortoli for Markdown to create pages and table of contents?


You could try this ruby script to generate the TOC from a markdown file.

#!/usr/bin/env ruby    File.open("your_file.md", 'r') do |f|    f.each_line do |line|      forbidden_words = ['Table of contents', 'define', 'pragma']      next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ }        title = line.gsub("#", "").strip      href = title.gsub(" ", "-").downcase      puts "  " * (line.count("#")-1) + "* [#{title}](\##{href})"    end  end  

Answer by jonschlinkert for Markdown to create pages and table of contents?


If you want to use a javascript/node.js tool, take a look at markdown-toc.

Answer by dgn for Markdown to create pages and table of contents?


Depending on your workflow, you might want to look at strapdown

That's a fork of the original one (http://strapdownjs.com) that adds the generation of the table of content.

There's an apache config file on the repo (might not be properly updated yet) to wrap plain markdown on the fly, if you prefer not writing in html files.

Answer by Martin for Markdown to create pages and table of contents?


I just started doing the same thing (take notes in Markdown). I use Sublime Text 2 with the MarkdownPreview plugin. The built-in markdown parser supports [TOC].

Answer by Rick for Markdown to create pages and table of contents?


You can give this a try.

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

Answer by Luca Davanzo for Markdown to create pages and table of contents?


There are 2 way to create your TOC (summary) in your markdown document.

1. Manually

# My Table of content  - [Section 1](#id-section1)  - [Section 2](#id-section2)    
## Section 1
## Section 2

2. Programmatically

You can use for example a script that generate summary for you, take a look to my project on github - summarizeMD -

I've tried also other script/npm module (for example doctoc) but no one reproduce a TOC with working anchors.

Answer by Antonio Maiorano for Markdown to create pages and table of contents?


I wrote a python script that parses a markdown file and outputs a table of contents as a markdown list: md-to-toc

Unlike other scripts I've found, md-to-toc correctly supports duplicate titles. It also doesn't require an internet connection, so it works on any md file, not just those available from a public repo.

Answer by Tumtum for Markdown to create pages and table of contents?


Here's a useful method. Should produce clickable references in any MarkDown editor.

# Table of contents  1. [Introduction](#introduction)  2. [Some paragraph](#paragraph1)      1. [Sub paragraph](#subparagraph1)  3. [Another paragraph](#paragraph2)    ## This is the introduction   Some introduction text, formatted in heading 2 style    ## Some paragraph   The first paragraph text    ### Sub paragraph   This is a sub paragraph, formatted in heading 3 style    ## Another paragraph   The second paragraph text  

Produces:

Table of contents

  1. Introduction
  2. Some paragraph
    1. Sub paragraph
  3. Another paragraph

This is the introduction

Some introduction text, formatted in heading 2 style

Some paragraph

The first paragraph text

Sub paragraph

This is a sub paragraph, formatted in heading 3 style

Another paragraph

The second paragraph text

Answer by dmigous for Markdown to create pages and table of contents?


Based on albertodebortoli answer created the function with additional checks and substitution of punctuation marks.

# @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  

Answer by msanford for Markdown to create pages and table of contents?


For the benefit of those of us making README.md files in Atom (how I found this thread):

apm install markdown-toc  

https://atom.io/packages/markdown-toc

Answer by Paul Jurczak for Markdown to create pages and table of contents?


Typora generates Table of Content by adding [TOC] to your document.

Answer by Zhuang Ma for Markdown to create pages and table of contents?


Anchor tags generated by different Markdown parsers are not even.

If you are working with Markdown parsers GFM (GitHub Flavored Markdown) or Redcarpet, I wrote a Vim plugin to handle table of contents.

Features

  1. Generate table of contents for Markdown files.

    Supported Markdown parsers:

    • GFM (GitHub Flavored Markdown)
    • Redcarpet
  2. Update existing table of contents.

  3. Auto update existing table of contents on save.

Screenshots

vim-markdown-toc

Usage

Generate table of contents

Move the cursor to the line you want to append table of contents, then type a command below suit you. The command will generate headings after the cursor into table of contents.

  1. :GenTocGFM

    Generate table of contents in GFM link style.

    This command is suitable for Markdown files in GitHub repositories, like README.md, and Markdown files for GitBook.

  2. :GenTocRedcarpet

    Generate table of contents in Redcarpet link style.

    This command is suitable for Jekyll or anywhere else use Redcarpet as its Markdown parser.

    You can view here to know differences between GFM and Redcarpet style toc links.

Update existing table of contents manually

Generally you don't need to do this, existing table of contents will auto update on save by default. If you want do it manually, just use :UpdateToc command.

Downloads and documents

https://github.com/mzlogin/vim-markdown-toc

Answer by dosmanak for Markdown to create pages and table of contents?


I am not sure, what is the official documentation for markdown. Cross-Reference can be written just in brackets [Heading], or with empty brackets [Heading][].

Both works using pandoc. So I created a quick bash script, that will replace $TOC in md file with its TOC. (You will need envsubst, that might not be part of your distro)

#!/bin/bash  filename=$1  __TOC__=$(grep "^##" $filename | sed -e 's/ /1. /;s/^##//;s/#/   /g;s/\. \(.*\)$/. [\1][]/')  export __TOC__  envsubst '$__TOC__' < $filename  

Answer by Michael R for Markdown to create pages and table of contents?


MultiMarkdown 4.7 has a {{TOC}} macro that inserts a table of contents.

Answer by Christophe Roussy for Markdown to create pages and table of contents?


If you happen to use Eclipse you can use the Ctrl+O (outline) shortcut, this will show the equivalent of the table of contents and allow to search in section titles (autocomplete).

You can also open the Outline view (Window -> Show View -> Outline) but it has no autocomplete search.

Answer by M.Geiger for Markdown to create pages and table of contents?


You could also use pandoc, the "swiss-army knife" for converting "one markup format into another". It can automatically generate a table of content in the output document if you supply the --toc argument.

Hint: If you want a table of contents in html output, you also need to supply -s which generates a standalone document.

Example shell command line:

./pandoc -s --toc input.md -o output.html  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.