markdown-it-ftoc
Version:
markdown-it plugin to add toc and anchor links in headings
282 lines (199 loc) • 5.91 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>markdown-it-ftoc Demo</title>
<meta name="description" content="markdown-it plugin to add toc and anchor links in headings">
<meta name="keywords" content="markdown-it,markdown-it-toc,markdown-it-ftoc">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.markdown-body {
padding: 16px;
width: 100%;
max-width: 560px;
box-shadow: 2px 2px 6px #ddd;
margin: 20px auto;
}
.markdown-body pre {
width: 100%;
overflow: auto;
}
.markdown-body img {
max-width: 100%;
}
.markdown-toc {
display: block;
margin-bottom: 20px;
}
ul {
list-style-type: none;
margin-bottom: 0;
list-style-position: inside;
margin-left: 16px;
}
li {
word-break: break-all;
}
.toc-wrap {
display: none;
}
@media screen and (min-width: 768px) {
.markdown-body {
margin-left: 200px;
}
.markdown-body .markdown-toc {
display: none;
}
.toc-wrap {
display: block;
position: fixed;
width: 200px;
left: 0;
top: 4px;
padding: 16px;
}
}
</style>
</head>
<body>
<div class="app">
<div class="toc-wrap"></div>
<div class="main markdown-body"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/8.4.2/markdown-it.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it-emoji/1.4.0/markdown-it-emoji.min.js"></script>
<script src="./index.min.js"></script>
<script>
var content = `@[toc](table fo contents)
## usage
\`\`\`javascript
var md = window.markdownit({
html: true,
linkify: true,
typographer: true
})
var tocWrap = document.querySelector('.toc-wrap')
var mainContainer = document.querySelector('.main')
md = md.use(window.markdownItFtoc, {
tocFirstLevel: 2,
tocCallback: function (tocHtml) {
tocWrap.innerHTML = tocHtml
}
})
var html = md.render(content)
mainContainer.innerHTML = html
\`\`\`
more apis [here](https://github.com/fchengjin/markdown-it-ftoc#options)
## attention
## 中文
## 标题
> The following content is meaningless,just for demo
> 以下内容无意义,只是为了demo演示
## Typographic replacements
Enable typographer option to see result.
(c) (C) (r) (R) (tm) (TM) (p) (P) +-
test.. test... test..... test?..... test!....
!!!!!! ???? ,, -- ---
"Smartypants, double quotes" and 'single quotes'
## Emphasis
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
~~Strikethrough~~
## Blockquotes
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.
## Lists
Unordered
+ Create a list by starting a line with \`+\`, \`-\`, or \`*\`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!
Ordered
1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa
1. You can use sequential numbers...
1. ...or keep all the numbers as \`1.\`
Start numbering with offset:
57. foo
1. bar
## Code
Inline \`code\`
Indented code
// Some comments
line 1 of code
line 2 of code
line 3 of code
Block code "fences"
\`\`\`
Sample text here...
\`\`\`
Syntax highlighting
\`\`\`js
var foo = function (bar) {
return bar++;
};
console.log(foo(5));
\`\`\`
## Tables
| Option | Description |
| ------ | ----------- |
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
Right aligned columns
| Option | Description |
| ------:| -----------:|
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
## Links
[link text](http://dev.nodeca.com)
[link with title](http://nodeca.github.io/pica/demo/ "title text!")
Autoconverted link https://github.com/nodeca/pica (enable linkify to see)
## Images


Like links, Images also have a footnote style syntax
![Alt text][id]
With a reference later in the document defining the URL location:
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
## Plugins
The killer feature of \`markdown-it\` is very effective support of
[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin).
### Emojies
> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:
>
> Shortcuts (emoticons): :-) :-( 8-) ;)
see [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji.
`
var md = window.markdownit({
html: true,
linkify: true,
typographer: true
})
var tocWrap = document.querySelector('.toc-wrap')
var mainContainer = document.querySelector('.main')
md = md.use(window.markdownitEmoji)
.use(window.markdownItFtoc, {
tocFirstLevel: 2,
tocCallback: function (tocHtml) {
tocWrap.innerHTML = tocHtml
}
})
var html = md.render(content)
mainContainer.innerHTML = html
</script>
</body>
</html>