-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
TOC for Wiki Pages #822
Comments
It seems it's already supported? |
A table of contents is supported in Gittea? I mean an TOC based on headings in the Wiki Pages. |
could you see https://try.gitea.io/lunny/vscode/wiki, is the right bar what you want? |
@lunny although this is an cool feature (is this already implemented?) i mean such thing like this: https://i.stack.imgur.com/IgJJd.png |
@MorphBonehunter yes, https://try.gitea.io/lunny/vscode/wiki is the demo of the master. I see what's you want. The content is generated automatically by a special syntax? |
@lunny yes that's what i thought about. Maybe this isn't possible with an markup renderer atm.
and the
Maybe this could not realized and we are bound to such things like https://github.com/thlorenz/doctoc and have to generate the TOC befor commit. |
TOC is really important. Documentation (written in English) is IMHO just as important as the code, which is "a kind of" of English too. With code, we have all sorts of neat code browsers. With documentation, a TOC is a navigation aid, which helps review the content. The search feature is also critical but that's covered by another issue #3760 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions. |
It's a pity that so little attention is paid to one of the most critical factors of a successful software project: the documentation. When multiple pages are authored, TOCs are a critical part of the overall structure. IMHO this issue deserves far more attention than what it has got so far. |
@fangchin feel free to submit PR for this |
@lafriks I will discuss with my team and get a better idea about the scope. If we cannot work on a PR ourselves, I will see if we see other options. The overall progress of this project has been delightful, but IMHO the documentation handling side (wiki, doc search) etc has not been on par with the code handling side. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions. |
is there any work on it? Should we keep this item as |
FWIW, it is possible to script a similar feature if interested: When editing the wiki on the Web interface, gitea clones a temporary copy of it on disk. If you create a custom pre-commit hook and make sure your gitea user has something like this in their ~/.gitconfig:
And stick the script in hooks/pre-commit. Then it will be installed when gitea creates a temporary clone of the wiki to edit. Each page save is a commit to the temporary repo, so that script would be run on each save. You can then manipulate any data from the wiki since it is just a bunch of text files which provides almost infinite flexibility for this case. Heres a small example of one that would update the sidebar with the last 3 changed pages on each page save (added some comments):
You can easily have it go through all of the files and extract headers as well to create a TOC that you can then inject into any file. |
Hello everybody, i've modified some JS i've written some time ago to create the toc - if there is a rendered md file. Feel free to use this code. If there should be a option inside repository settings to enable/disable the script, I couln't create the pull request. (My golang is too bad.) Requirements:
Benefints:
Disadvantage:
Here is the Code:
Result - build in wiki pages (md): Edit: I noticed this issue is for wiki pages, i've only tested on md files (this was what i was looking for in google search). |
see go-gitea#822 Signed-off-by: Michael Gnehr <[email protected]>
any news? or plan to merge this feature ? anything ? |
1.16.5 (and maybe earlier releases, too) changed the classes used for the entities this script targets - "markdown" was changed to "markup". I also wrapped the actual creation of the TOC elements and DOM insertion in an Updated script is below: (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 (level) {
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(level);
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 = '';
if(elms.length > 4) {
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";
d2.style.cssText = "padding:7px;border:1px solid #333;border-radius:5px";
}
}
};
// create toc ----------------------------------
create_toc_inside(document.querySelector('.file-view.markup')); // md
create_toc_inside(document.querySelector('.segment.markup')); // wiki pages
})(); |
@GlitterHorn Hello, How to use these codes? |
Automatically add sidebar in the wiki view containing a TOC for the wiki page. Fix go-gitea#822 Signed-off-by: Andrew Thornton <[email protected]>
Details on customizing Gitea are here. What I did was create a javascript file containing the above script, and saved it to <script src="/assets/js/toc.js"></script> Reboot Gitea, and the script should now load with wiki pages, and render the TOC. |
How to disable right TOC menu? |
+1 to this. Users/Clients may benefit from having the option to disable the table of contents. |
[x]
):Description
This is an "clone" of gogs issue 3931
Having an TOC in Wiki Pages could be helpfull.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: