Skip to content

Commit

Permalink
feat: 添加 chapterTextFilter 参数,用于处理 chapters 菜单中显示的文本;
Browse files Browse the repository at this point in the history
  • Loading branch information
yaohaixiao committed Aug 15, 2023
1 parent 663fe66 commit 7d57fb1
Show file tree
Hide file tree
Showing 21 changed files with 341 additions and 149 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ const outline = new Outline({
// 当导航菜单隐藏或者显示后,触发的回调函数
afterToggle: null,
// 当点击上下滚动按钮,导航菜单或者文章中的 # 图标,滚动结束后触发的回调函数
afterScroll: null
afterScroll: null,
// 文档的标题文本过滤回调函数
// API 文档中,正文的方法会添加参数等信息,例如:getChapters(headings, showCode, chapterTextFilter)
// 而在 chapters 导航菜单,我希望显示为 getChapters(),这时我们就可以借助 chapterTextFilter 回调函数
// 对原始的文本进行过滤,返回我们期望的 getChapters() 文本
chapterTextFilter: null
});

// 可以在创建导航后,重置配置信息,重新生成新的导航
Expand Down
2 changes: 1 addition & 1 deletion anchors.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion anchors.min.js.map

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions api/pug/options/chpaterTextFilter.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
section.section
header.section__header
h3#option-chapterTextFilter.section__h3 chapterTextFilter
div.section__content
h4.section__h4 Description
dl.section__dl
dt.section__dt Type:
dd.section__dd Function
dl.section__dl
dt.section__dt Default:
dd.section__dd null
p 可选,API 文档中,正文的方法会添加参数等信息,例如:getChapters(headings, showCode, chapterTextFilter)。而在 chapters 导航菜单,我希望显示为 getChapters(),这时我们就可以借助 chapterTextFilter 回调函数。对原始的文本进行过滤,返回我们期望的 getChapters() 文本。
h4.section__h4 Parameters
h5.section__h4 text
dl.section__dl
dt.section__dt Type:
dd.section__dd String
p chapterTextFilter() 回调函数有一个参数 text,返回的是当前 hx 标题中的文本。
pre.section__pre
code.section__code.
const defaults = Outline.DEFAULTS
let outline

defaults.selector = 'h2,h3'
defaults.title = false
defaults.showCode = false
defaults.position = 'sticky'
defaults.parentElement = '#aside'
defaults.scrollElement = '#main'
defaults.articleElement = '#article'
defaults.homepage = './index.html'
defaults.git = 'https://github.com/yaohaixiao/outline.js'
defaults.tags = 'https://github.com/yaohaixiao/outline.js/tags'
defaults.issues = 'https://github.com/yaohaixiao/outline.js/issues'
defaults.print = {
element: '#article',
title: 'Outline.js'
}
defaults.chapterTextFilter = (text) => {
return text.replace(/\(.*?\)/, '()')
}
outline = new Outline(Outline.DEFAULTS)
1 change: 1 addition & 0 deletions api/pug/options/section.pug
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ section.section
include afterScroll
include afterSticky
include afterToggle
include chpaterTextFilter
1 change: 0 additions & 1 deletion api/pug/preload.pug
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
link(rel="preload" href="css/docs.min.css" as="style")
link(rel="preload" href="js/docs.min.js" as="script")
45 changes: 23 additions & 22 deletions api/pug/properties/defaults.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ section.section
code.section__code.
Outline.DEFAULTS = {
articleElement: '#article',
selector: 'h2,h3,h4,h5,h6',
title: '目录',
scrollElement: 'html,body',
position: 'relative',
parentElement: '#aside',
placement: 'rtl',
showCode: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
git: '',
tags: '',
issues: '',
tools: [],
print: {
element: '',
title: ''
},
customClass: '',
afterSticky: null,
afterToggle: null,
afterScroll: null
selector: 'h2,h3,h4,h5,h6',
title: '目录',
scrollElement: 'html,body',
position: 'relative',
parentElement: '#aside',
placement: 'rtl',
showCode: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
git: '',
tags: '',
issues: '',
tools: [],
print: {
element: '',
title: ''
},
customClass: '',
afterSticky: null,
afterToggle: null,
afterScroll: null,
chapterTextFilter: null
}
3 changes: 3 additions & 0 deletions api/pug/script.pug
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ script.
element: '#article',
title: 'Outline.js'
}
defaults.chapterTextFilter = (text) => {
return text.replace(/\(.*?\)/, '()')
}
outline = new Outline(Outline.DEFAULTS)
})()
66 changes: 44 additions & 22 deletions docs/fixed.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,52 @@
$header.classList.add(HEADER_STICKY)
}
}
outline = new Outline(Outline.DEFAULTS)</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3" id="option-chapterTextFilter">chapterTextFilter</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Function</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">null</dd></dl><p>可选,API 文档中,正文的方法会添加参数等信息,例如:getChapters(headings, showCode, chapterTextFilter)。而在 chapters 导航菜单,我希望显示为 getChapters(),这时我们就可以借助 chapterTextFilter 回调函数。对原始的文本进行过滤,返回我们期望的 getChapters() 文本。</p><h4 class="section__h4">Parameters</h4><h5 class="section__h4">text</h5><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">String</dd></dl><p>chapterTextFilter() 回调函数有一个参数 text,返回的是当前 hx 标题中的文本。</p><pre class="section__pre"><code class="section__code">const defaults = Outline.DEFAULTS
let outline

defaults.selector = 'h2,h3'
defaults.title = false
defaults.showCode = false
defaults.position = 'sticky'
defaults.parentElement = '#aside'
defaults.scrollElement = '#main'
defaults.articleElement = '#article'
defaults.homepage = './index.html'
defaults.git = 'https://github.com/yaohaixiao/outline.js'
defaults.tags = 'https://github.com/yaohaixiao/outline.js/tags'
defaults.issues = 'https://github.com/yaohaixiao/outline.js/issues'
defaults.print = {
element: '#article',
title: 'Outline.js'
}
defaults.chapterTextFilter = (text) => {
return text.replace(/\(.*?\)/, '()')
}
outline = new Outline(Outline.DEFAULTS)</code></pre></div></section></section><section class="section"><header class="section__header"><h2 class="section__title">Properties</h2></header><div class="section__content"><p>outline.js 重构后,对外放 4 个重要的属性:anchors、drawer、chapters 和 toolbar。它们都是独立的对象实例,提供了 outline.js 所有的能力(属性和方法)。</p></div><section class="section"><header class="section__header"><h3 class="section__h3" id="property-defaults">DEFAULTS</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="api-param-value">Object</dd></dl><p>静态属性,存储的是 Outline 对象默认配置选项:</p><pre class="section__pre"><code class="section__code">Outline.DEFAULTS = {
articleElement: '#article',
selector: 'h2,h3,h4,h5,h6',
title: '目录',
scrollElement: 'html,body',
position: 'relative',
parentElement: '#aside',
placement: 'rtl',
showCode: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
git: '',
tags: '',
issues: '',
tools: [],
print: {
element: '',
title: ''
},
customClass: '',
afterSticky: null,
afterToggle: null,
afterScroll: null
selector: 'h2,h3,h4,h5,h6',
title: '目录',
scrollElement: 'html,body',
position: 'relative',
parentElement: '#aside',
placement: 'rtl',
showCode: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
git: '',
tags: '',
issues: '',
tools: [],
print: {
element: '',
title: ''
},
customClass: '',
afterSticky: null,
afterToggle: null,
afterScroll: null,
chapterTextFilter: null
}</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3" id="property-attrs">attrs</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Object</dd></dl><p>存储的是 Outline 对象当前使用中的配置选项:</p><p>说明:建议使用 attr(prop) 方法来获取属性,避免直接调用属性。</p><pre class="section__pre"><code class="section__code">// 设置默认配置项
const outline = new Outline(Outline.DEFAULTS)

Expand Down
66 changes: 44 additions & 22 deletions docs/flex.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,30 +298,52 @@
$header.classList.add(HEADER_STICKY)
}
}
outline = new Outline(Outline.DEFAULTS)</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3" id="option-chapterTextFilter">chapterTextFilter</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Function</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">null</dd></dl><p>可选,API 文档中,正文的方法会添加参数等信息,例如:getChapters(headings, showCode, chapterTextFilter)。而在 chapters 导航菜单,我希望显示为 getChapters(),这时我们就可以借助 chapterTextFilter 回调函数。对原始的文本进行过滤,返回我们期望的 getChapters() 文本。</p><h4 class="section__h4">Parameters</h4><h5 class="section__h4">text</h5><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">String</dd></dl><p>chapterTextFilter() 回调函数有一个参数 text,返回的是当前 hx 标题中的文本。</p><pre class="section__pre"><code class="section__code">const defaults = Outline.DEFAULTS
let outline

defaults.selector = 'h2,h3'
defaults.title = false
defaults.showCode = false
defaults.position = 'sticky'
defaults.parentElement = '#aside'
defaults.scrollElement = '#main'
defaults.articleElement = '#article'
defaults.homepage = './index.html'
defaults.git = 'https://github.com/yaohaixiao/outline.js'
defaults.tags = 'https://github.com/yaohaixiao/outline.js/tags'
defaults.issues = 'https://github.com/yaohaixiao/outline.js/issues'
defaults.print = {
element: '#article',
title: 'Outline.js'
}
defaults.chapterTextFilter = (text) => {
return text.replace(/\(.*?\)/, '()')
}
outline = new Outline(Outline.DEFAULTS)</code></pre></div></section></section><section class="section"><header class="section__header"><h2 class="section__title">Properties</h2></header><div class="section__content"><p>outline.js 重构后,对外放 4 个重要的属性:anchors、drawer、chapters 和 toolbar。它们都是独立的对象实例,提供了 outline.js 所有的能力(属性和方法)。</p></div><section class="section"><header class="section__header"><h3 class="section__h3" id="property-defaults">DEFAULTS</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="api-param-value">Object</dd></dl><p>静态属性,存储的是 Outline 对象默认配置选项:</p><pre class="section__pre"><code class="section__code">Outline.DEFAULTS = {
articleElement: '#article',
selector: 'h2,h3,h4,h5,h6',
title: '目录',
scrollElement: 'html,body',
position: 'relative',
parentElement: '#aside',
placement: 'rtl',
showCode: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
git: '',
tags: '',
issues: '',
tools: [],
print: {
element: '',
title: ''
},
customClass: '',
afterSticky: null,
afterToggle: null,
afterScroll: null
selector: 'h2,h3,h4,h5,h6',
title: '目录',
scrollElement: 'html,body',
position: 'relative',
parentElement: '#aside',
placement: 'rtl',
showCode: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
git: '',
tags: '',
issues: '',
tools: [],
print: {
element: '',
title: ''
},
customClass: '',
afterSticky: null,
afterToggle: null,
afterScroll: null,
chapterTextFilter: null
}</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3" id="property-attrs">attrs</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Object</dd></dl><p>存储的是 Outline 对象当前使用中的配置选项:</p><p>说明:建议使用 attr(prop) 方法来获取属性,避免直接调用属性。</p><pre class="section__pre"><code class="section__code">// 设置默认配置项
const outline = new Outline(Outline.DEFAULTS)

Expand Down

0 comments on commit 7d57fb1

Please sign in to comment.