Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
计算机应用开发
前端
Vuepress
提交
c3696d25
V
Vuepress
项目概览
计算机应用开发
/
前端
/
Vuepress
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vuepress
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c3696d25
编写于
6月 03, 2018
作者:
U
ULIVZ
提交者:
GitHub
6月 03, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: headers badge (#540)
上级
4e7f3da8
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
68 addition
and
16 deletion
+68
-16
docs/guide/markdown.md
docs/guide/markdown.md
+1
-1
lib/app/app.js
lib/app/app.js
+2
-0
lib/default-theme/Badge.vue
lib/default-theme/Badge.vue
+30
-0
lib/default-theme/styles/theme.styl
lib/default-theme/styles/theme.styl
+1
-0
lib/default-theme/styles/toc.styl
lib/default-theme/styles/toc.styl
+3
-0
lib/markdown/index.js
lib/markdown/index.js
+3
-2
lib/util/index.js
lib/util/index.js
+5
-5
lib/util/parseHeaders.js
lib/util/parseHeaders.js
+16
-8
lib/util/shared.js
lib/util/shared.js
+7
-0
未找到文件。
docs/guide/markdown.md
浏览文件 @
c3696d25
...
...
@@ -224,7 +224,7 @@ export default {
}
```
## Import Code Snippets
## Import Code Snippets
<Badge text="Experimental" type="warn"/> <Badge text="0.0.11+" type="tip"/>
You can import code snippets from existing files via following syntax:
...
...
lib/app/app.js
浏览文件 @
c3696d25
...
...
@@ -2,6 +2,7 @@ import Vue from 'vue'
import
Router
from
'
vue-router
'
import
Content
from
'
./Content
'
import
OutboundLink
from
'
../default-theme/OutboundLink.vue
'
import
Badge
from
'
../default-theme/Badge.vue
'
import
ClientOnly
from
'
./ClientOnly
'
import
dataMixin
from
'
./dataMixin
'
import
store
from
'
./store
'
...
...
@@ -30,6 +31,7 @@ Vue.mixin(dataMixin(siteData))
// component for rendering markdown content and setting title etc.
Vue
.
component
(
'
Content
'
,
Content
)
Vue
.
component
(
'
OutboundLink
'
,
OutboundLink
)
Vue
.
component
(
'
Badge
'
,
Badge
)
// component for client-only content
Vue
.
component
(
'
ClientOnly
'
,
ClientOnly
)
...
...
lib/default-theme/Badge.vue
0 → 100644
浏览文件 @
c3696d25
<
script
>
export
default
{
functional
:
true
,
props
:
[
'
type
'
,
'
text
'
],
render
(
h
,
{
props
,
slots
})
{
return
h
(
'
span
'
,
{
class
:
[
'
badge
'
,
props
.
type
]
},
props
.
text
||
slots
().
default
)
}
}
</
script
>
<
style
lang=
"stylus"
>
@import './styles/config.styl'
.badge
display inline-block
vertical-align top
font-size 14px
height 18px
line-height 18px
border-radius 9px
padding 0 5px
color white
margin-right 5px
&.tip
background-color #42b983
&.warning, &.warn
background-color darken(#ffe564, 35%)
</
style
>
lib/default-theme/styles/theme.styl
浏览文件 @
c3696d25
...
...
@@ -4,6 +4,7 @@
@require './custom-blocks'
@require './arrow'
@require './wrapper'
@require './toc'
html, body
padding 0
...
...
lib/default-theme/styles/toc.styl
0 → 100644
浏览文件 @
c3696d25
.table-of-contents
.badge
vertical-align middle
lib/markdown/index.js
浏览文件 @
c3696d25
...
...
@@ -11,11 +11,12 @@ const emoji = require('markdown-it-emoji')
const
anchor
=
require
(
'
markdown-it-anchor
'
)
const
toc
=
require
(
'
markdown-it-table-of-contents
'
)
const
_slugify
=
require
(
'
./slugify
'
)
const
parseHeaders
=
require
(
'
../util/parseHeaders
'
)
const
{
parseHeaders
,
removeTailHtml
}
=
require
(
'
../util/parseHeaders
'
)
const
{
compose
}
=
require
(
'
../util/shared
'
)
module
.
exports
=
({
markdown
=
{}}
=
{})
=>
{
// allow user config slugify
const
slugify
=
markdown
.
slugify
||
_slugify
const
slugify
=
markdown
.
slugify
||
compose
(
removeTailHtml
,
_slugify
)
const
md
=
require
(
'
markdown-it
'
)({
html
:
true
,
...
...
lib/util/index.js
浏览文件 @
c3696d25
const
parseHeaders
=
require
(
'
./parseHeaders
'
)
const
{
deeplyParseHeaders
}
=
require
(
'
./parseHeaders
'
)
exports
.
normalizeHeadTag
=
function
(
tag
)
{
if
(
typeof
tag
===
'
string
'
)
{
...
...
@@ -32,11 +32,11 @@ exports.inferTitle = function (frontmatter) {
return
'
Home
'
}
if
(
frontmatter
.
data
.
title
)
{
return
p
arseHeaders
(
frontmatter
.
data
.
title
)
return
deeplyP
arseHeaders
(
frontmatter
.
data
.
title
)
}
const
match
=
frontmatter
.
content
.
trim
().
match
(
/^#+
\s
+
(
.*
)
/
)
if
(
match
)
{
return
p
arseHeaders
(
match
[
1
])
return
deeplyP
arseHeaders
(
match
[
1
])
}
}
...
...
@@ -68,11 +68,11 @@ exports.extractHeaders = function (content, include = [], md) {
const
res
=
[]
tokens
.
forEach
((
t
,
i
)
=>
{
if
(
t
.
type
===
'
heading_open
'
&&
include
.
includes
(
t
.
tag
))
{
const
title
=
parseHeaders
(
tokens
[
i
+
1
].
content
)
const
title
=
tokens
[
i
+
1
].
content
const
slug
=
t
.
attrs
.
find
(([
name
])
=>
name
===
'
id
'
)[
1
]
res
.
push
({
level
:
parseInt
(
t
.
tag
.
slice
(
1
),
10
),
title
,
title
:
deeplyParseHeaders
(
title
)
,
slug
:
slug
||
md
.
slugify
(
title
)
})
}
...
...
lib/util/parseHeaders.js
浏览文件 @
c3696d25
const
{
compose
}
=
require
(
'
./shared
'
)
const
parseEmojis
=
str
=>
{
const
emojiData
=
require
(
'
markdown-it-emoji/lib/data/full.json
'
)
return
String
(
str
).
replace
(
/:
(
.+
?)
:/g
,
(
placeholder
,
key
)
=>
emojiData
[
key
]
||
placeholder
)
...
...
@@ -17,13 +19,19 @@ const removeMarkdownToken = str => String(str)
.
replace
(
/
\*(
.*
)\*
/
,
'
$1
'
)
// *
.
replace
(
/_
(
.*
)
_/
,
'
$1
'
)
// _
// put here to avoid circular references
const
compose
=
(...
processors
)
=>
{
if
(
processors
.
length
===
0
)
return
input
=>
input
if
(
processors
.
length
===
1
)
return
processors
[
0
]
return
processors
.
reduce
((
prev
,
next
)
=>
{
return
(...
args
)
=>
next
(
prev
(...
args
))
})
exports
.
removeTailHtml
=
(
str
)
=>
{
return
String
(
str
).
replace
(
/<.*>
\s
*$/g
,
''
)
}
module
.
exports
=
compose
(
unescapeHtml
,
parseEmojis
,
removeMarkdownToken
)
// only remove some md tokens.
exports
.
parseHeaders
=
compose
(
unescapeHtml
,
parseEmojis
,
removeMarkdownToken
)
// also clean html in headers.
exports
.
deeplyParseHeaders
=
compose
(
exports
.
parseHeaders
,
exports
.
removeTailHtml
)
lib/util/shared.js
0 → 100644
浏览文件 @
c3696d25
exports
.
compose
=
(...
processors
)
=>
{
if
(
processors
.
length
===
0
)
return
input
=>
input
if
(
processors
.
length
===
1
)
return
processors
[
0
]
return
processors
.
reduce
((
prev
,
next
)
=>
{
return
(...
args
)
=>
next
(
prev
(...
args
))
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录