mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-30 10:30:08 +00:00
added page toc plugin
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
0211c76b1d
commit
811ed21223
37
pwiki/dom/toc.js
Executable file
37
pwiki/dom/toc.js
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
/**********************************************************************
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
**********************************************************************/
|
||||||
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||||
|
(function(require){ var module={} // make module AMD/node compatible...
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
var makeToc =
|
||||||
|
module.makeToc =
|
||||||
|
function(){
|
||||||
|
return [...document.querySelectorAll('toc')]
|
||||||
|
.map(function(toc){
|
||||||
|
toc.innerHTML = ''
|
||||||
|
var parent = toc.parentElement
|
||||||
|
var base = pwiki.path
|
||||||
|
;[...parent.querySelectorAll('[id]')]
|
||||||
|
.filter(function(n){
|
||||||
|
return /^h[0-9]$/i.test(n.nodeName) })
|
||||||
|
.forEach(function(section){
|
||||||
|
var e = document.createElement('a')
|
||||||
|
e.classList.add(section.nodeName.toLowerCase())
|
||||||
|
e.setAttribute('href', '#'+ base +'#'+ section.id)
|
||||||
|
e.innerHTML = section.innerHTML
|
||||||
|
toc.appendChild(e) })
|
||||||
|
return toc }) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* vim:set ts=4 sw=4 : */ return module })
|
||||||
@ -1795,7 +1795,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
await data()
|
await data()
|
||||||
: typeof(data) == 'function' ?
|
: typeof(data) == 'function' ?
|
||||||
data
|
data
|
||||||
: 'text' in data ?
|
: data && 'text' in data ?
|
||||||
data.text
|
data.text
|
||||||
: null
|
: null
|
||||||
if(data instanceof Array
|
if(data instanceof Array
|
||||||
@ -2021,6 +2021,7 @@ object.Constructor('CachedPage', Page, {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
var toc = require('./dom/toc')
|
||||||
var wikiword = require('./dom/wikiword')
|
var wikiword = require('./dom/wikiword')
|
||||||
//var textarea = require('./dom/textarea')
|
//var textarea = require('./dom/textarea')
|
||||||
|
|
||||||
@ -2035,6 +2036,7 @@ object.Constructor('pWikiPageElement', Page, {
|
|||||||
|
|
||||||
|
|
||||||
domFilters: {
|
domFilters: {
|
||||||
|
toc: toc.makeToc,
|
||||||
// XXX see Page.filters.wikiword for notes...
|
// XXX see Page.filters.wikiword for notes...
|
||||||
wikiword: wikiword.wikiWordText,
|
wikiword: wikiword.wikiWordText,
|
||||||
//textarea: textarea.setupTextarea,
|
//textarea: textarea.setupTextarea,
|
||||||
@ -2263,6 +2265,7 @@ module.System = {
|
|||||||
@load(./edit)
|
@load(./edit)
|
||||||
|
|
||||||
<macro texteditor>
|
<macro texteditor>
|
||||||
|
<toc></toc>
|
||||||
<div class="editor"
|
<div class="editor"
|
||||||
wikiwords="no"
|
wikiwords="no"
|
||||||
contenteditable
|
contenteditable
|
||||||
|
|||||||
28
pwiki2.html
28
pwiki2.html
@ -150,6 +150,34 @@ body.loading .page.spinner span {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* TOC */
|
||||||
|
toc {
|
||||||
|
--toc-level-offset: 2em;
|
||||||
|
}
|
||||||
|
toc a {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
toc .h1 {
|
||||||
|
margin-left: 0em;
|
||||||
|
}
|
||||||
|
toc .h2 {
|
||||||
|
margin-left: calc(var(--toc-level-offset) * 1);
|
||||||
|
}
|
||||||
|
toc .h3 {
|
||||||
|
margin-left: calc(var(--toc-level-offset) * 2);
|
||||||
|
}
|
||||||
|
toc .h4 {
|
||||||
|
margin-left: calc(var(--toc-level-offset) * 3);
|
||||||
|
}
|
||||||
|
toc .h5 {
|
||||||
|
margin-left: calc(var(--toc-level-offset) * 4);
|
||||||
|
}
|
||||||
|
toc .h5 {
|
||||||
|
margin-left: calc(var(--toc-level-offset) * 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.error .msg {
|
.error .msg {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: red;
|
color: red;
|
||||||
|
|||||||
@ -38,8 +38,6 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX macros: else/default macro args essentially mean the same thing, should we
|
|
||||||
* unify them to use the same name???
|
|
||||||
* XXX parser: error handling: revise page quoting...
|
* XXX parser: error handling: revise page quoting...
|
||||||
* ...need a standard mechanism to quote urls, url-args and paths...
|
* ...need a standard mechanism to quote urls, url-args and paths...
|
||||||
* XXX BUG? can't use < and > (both?) in page title...
|
* XXX BUG? can't use < and > (both?) in page title...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user