Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: wiki - add toc to wiki pages and rendered md files #7182

Closed
wants to merge 25 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6325510
add toc to wikipages and rendered md files
Cherrg Jun 11, 2019
0a9fb89
move style settings from js to css files
Cherrg Jun 11, 2019
0e08aa9
fix dark theme border color
Cherrg Jun 11, 2019
994bf33
change padding on TOC headlines
Cherrg Jun 12, 2019
f60056b
add md and wikifile TOC settings to repository options
Cherrg Jun 12, 2019
a9dce7f
handle options on template and update js
Cherrg Jun 12, 2019
e971230
Update index.js
Cherrg Jun 13, 2019
a889262
add float clear element
Cherrg Jun 13, 2019
77fb621
move TOC settings in app.ini from section 'repository' to 'markdown'
Cherrg Jun 13, 2019
c8e7b8a
Merge branch 'master' into gitea_md_wiki_auto_toc
techknowlogick Jun 13, 2019
06238aa
remove german translation
Cherrg Jun 13, 2019
c486aca
add configuration flag to set TOC extensions
Cherrg Jun 13, 2019
1417170
Merge branch 'master' into gitea_md_wiki_auto_toc
Cherrg Jun 13, 2019
83e4c6e
Merge branch 'gitea_md_wiki_auto_toc' of github.com:Cherrg/gitea into…
Cherrg Jun 13, 2019
588fcca
move toc beside markdown container on large screens
Cherrg Jun 13, 2019
e91b8c5
rename configuration variables 'markdown' to 'markup'
Cherrg Jun 14, 2019
8dd08af
set fixed width on small mobile screens
Cherrg Jun 17, 2019
71e0165
Merge branch 'master' into gitea_md_wiki_auto_toc
Cherrg Jun 22, 2019
21b1f99
Merge branch 'master' into gitea_md_wiki_auto_toc
Cherrg Jun 27, 2019
22b82ff
fix css lint errors
Cherrg Jun 27, 2019
0607c0a
rename migration file
Cherrg Jul 6, 2019
e0939ab
Merge branch 'master' into gitea_md_wiki_auto_toc
Cherrg Jul 6, 2019
bd83992
git rename migration file to resolve confilcts
Cherrg Jul 8, 2019
9fbb263
Merge branch 'master' into gitea_md_wiki_auto_toc
Cherrg Jul 8, 2019
f870a41
Merge branch 'master' into gitea_md_wiki_auto_toc
Cherrg Nov 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3034,3 +3034,95 @@ function onOAuthLoginClick() {
oauthNav.show();
},5000);
}
(function() {
// html listings ----------------------------------------------------
let openedLists, listEopen;
// close list
const _closeList = function (count) {
let out = '';
if(count == false || count == 0 || count == 'undefined' || typeof(count) == 'undefined' ) {
count = openedLists.length;
} else {
count = Math.min(count, openedLists.length);
}
while (count > 0){
out += '</li>' + openedLists.pop();
listEopen = true;
count--;
}
return out;
};
// open list
const _openList = function () {
let out = '<ul>';
openedLists.push('</ul>');
listEopen = false;
return out;
};
// handle list element
// create valid html list
const __list = function (line, level, id) {
let out = '';
let diff = level - openedLists.length;
if(diff > 0) { //open new level
out += _openList();
out += __list(line,level, id);
} else if(diff < 0 ) {
out += _closeList(-diff);
out += __list(line, level, id);
} else { // only add list element
out += ((listEopen)?'</li>':'') + '<li><a href="#' + id + '" rel="nofollow">' + line + '</a>';
listEopen = true;
}
return out;
};
/**
* find headlines and create list ----------------------------------
* @param target Element target container where toc should be created
*/
const create_toc_inside = function(target) {
let rm;
if(target != null) {
if( (rm = target.querySelector('.auto-toc-wrapper')) != null ) {
rm.parentNode.removeChild(rm);
}
openedLists = []; listEopen = false;
// get content and create html
const elms = target.querySelectorAll('h1,h2,h3,h4,h5');
let html = '';
for(let i = 0; i < elms.length; i++){
let l = elms[i].tagName.substr(1); //level
let t = elms[i].innerText.trim().trim(''); //text
let id = elms[i].id;
// create html
if(t.length > 0 && l >= 1) {
html += __list( t, l, id);
} else {
html += _closeList(0) + l;
}
}
html += _closeList(0);
//create elements
let d = document.createElement('div');
d.id = 'auto-toc';
d.className = 'anchor-wrap';
d.innerHTML = '<h2>Table of Contents</h2>';
let d2 = document.createElement('div');
d2.className = 'auto-toc-container';
d2.innerHTML = html;
d2.insertBefore(d, d2.firstChild);
let c = document.createElement('div');
c.className = 'auto-toc-wrapper';
c.appendChild(d2);
//inject toc
target.insertBefore(c, target.firstChild);
//set style
c.style.cssText = "float:right;background:#fff;padding:0 0 7px 20px;position:relative;z-index:1";
Cherrg marked this conversation as resolved.
Show resolved Hide resolved
d2.style.cssText = "padding:7px;border:1px solid #333;border-radius:5px";
}
};
// create toc ----------------------------------
create_toc_inside(document.querySelector('.file-view.markdown')); // md
create_toc_inside(document.querySelector('.segment.markdown')); // wiki pages
})();