diff --git a/Capitalized-file.py.md b/Capitalized-file.py.md new file mode 100644 index 0000000..6d071f4 --- /dev/null +++ b/Capitalized-file.py.md @@ -0,0 +1,14 @@ +**Table of Contents** + +* [Header 1](#header-1) +* [Header 22](#header-22) + + + +# Header 1 + +For files with capitalized characters, ToC must be generated. + +# Header 22 + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a913f92 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +**Table of Contents** + +* [tomancaklab.github.io](#tomancaklabgithubio) +* [Test Drive](#test-drive) + + + +# tomancaklab.github.io +The website of the Tomancak Lab + + +Reproduced verbatim from the authors' [answer](https://stackoverflow.com/a/29012394/307454) on Stackoverflow: + +> My colleague @schmiedc and I have created a GreaseMonkey script that installs a new TOC button left of the h1 button which uses the excellent markdown-js library to add/refresh a table of contents. +> The advantage over solutions like doctoc is that it integrates into GitHub's wiki editor and does not need users to work on their command-line (and require users to install tools like node.js). In Chrome, it works by drag 'n dropping into the Extensions page, in Firefox you will need to install the GreaseMonkey extension. +> It will work with plain markdown (i.e. it does not handle code blocks correctly, as that is a GitHub extension to markdown). Contributions welcome. + + +# Test Drive + +Test drive the script here https://github.com/kgashok/tomancaklab.github.io/wiki diff --git a/file1 b/file1 new file mode 100644 index 0000000..fba6d5d --- /dev/null +++ b/file1 @@ -0,0 +1 @@ +Intentionally left blank diff --git a/gfm-add-toc.user.js b/gfm-add-toc.user.js index 5a3e0a9..bfee1f6 100644 --- a/gfm-add-toc.user.js +++ b/gfm-add-toc.user.js @@ -3,40 +3,64 @@ // @namespace tomancaklab // @include http://github.com/*/wiki/*/_edit* // @include https://github.com/*/wiki/*/_edit* +// @include https://github.com/*/edit* // @grant none // ==/UserScript== + (function(){ + var editingWiki = window.location.pathname.match(/.*\/wiki\/.*\/_edit#?$/); + var editingMDfile = window.location.pathname.match(/.*\/edit\/.*\.md$/); if (window.location.host != 'github.com' || - !window.location.pathname.match(/.*\/wiki\/.*\/_edit#?$/)) - return; // not editing a GitHub wiki page + !(editingWiki || editingMDfile)){ + console.log("not on github!"); + return; // not editing a GitHub wiki page or github repo file + } + + var textarea, childElement, h1Button, editButton, buttonClass; + if (editingWiki) { + textarea = document.getElementById('gollum-editor-body'); + childElement = h1Button = document.getElementById('function-h1'); + buttonClass = 'btn btn-sm BtnGroup-item function-button'; + } + else if (editingMDfile) { + //var fileInput = document.getElementsByClassName('form-control js-blob-filename js-breadcrumb-nav')[0]; + var fileInput = document.querySelector(".js-blob-filename.js-breadcrumb-nav"); + var fileNameClassName = 'blob_contents_' + fileInput.value; + fileNameClassName = fileNameClassName.toLowerCase().replace(/\./g,'-'); + console.log(fileNameClassName); + textarea = document.getElementById(fileNameClassName); + //var y = document.getElementsByClassName("btn-link preview tabnav-tab js-blob-edit-preview")[0]; + //var y = document.querySelector("button.btn-link.preview.tabnav-tab.js-blob-edit-preview"); + childElement = editButton = document.querySelector(".js-blob-edit-preview"); + buttonClass = 'btn-link code selected tabnav-tab js-blob-edit-code'; + } - var textarea = document.getElementById('gollum-editor-body'); - var h1Button = document.getElementById('function-h1'); - if (!textarea || !h1Button) { - console.log("Could not find text area or

button"); - console.log(textarea); - console.log(h1Button); + if (!textarea || !childElement) { + console.log("Could not find text area or

button or \"Edit File\" button"); + console.log("text area:", textarea); + console.log("h1:", h1Button); + console.log("Edit:", editButton); return; } var self = this; - var button = document.createElement('a'); + var button = document.createElement("button"); + button.type = 'button'; button.id = 'function-toc'; - button.href = '#'; - button.className = 'minibutton function-button'; + button.className = buttonClass; button.setAttribute('tabindex', '-1'); button.setAttribute('title', 'Refresh table of contents'); - button.setAttribute('role', 'button'); - button.innerHTML = 'TOC' + button.innerHTML = 'ToC'; button.onclick = function() { self.insertTOC(textarea); }; - h1Button.parentNode.insertBefore(button, h1Button); - /* GitHub disables this button ;-) */ - setTimeout(function() { button.className = 'minibutton function-button'; }, 100); + childElement.parentNode.insertAdjacentElement('afterbegin', button); + /* GitHub disables this button on Firefox; need to re-enable it again ;-) */ + if (h1Button) + setTimeout(function() { button.className = 'btn btn-sm BtnGroup-item function-button'; }, 100); /* Helper to generate the Table of Contents entries */ var toPlainText = function(list) { @@ -66,7 +90,7 @@ var md = textarea.value; /* Strip out existing TOC, if any */ - var tocStart = '** Table of contents **\n\n'; + var tocStart = '**Table of Contents**\n\n'; if (md.startsWith(tocStart)) md = md.substring(tocStart.length).replace(/[^]*?\n\n/m, ''); @@ -82,7 +106,7 @@ var anchor = plainText.toLowerCase() .replace(/ /g, '-') .replace(/[^-A-Za-z0-9]/g, ''); - toc += '* [' + plainText + '](#' + anchor + ')\n'; + toc += '* [' + plainText + '](#' + anchor + ') \n'; } }); toc += '\n'; diff --git a/lab7-kgashok.py.md b/lab7-kgashok.py.md new file mode 100644 index 0000000..0d59d37 --- /dev/null +++ b/lab7-kgashok.py.md @@ -0,0 +1,25 @@ +**Table of Contents** + +* [Header 1](#header-1) +* [Header 2](#header-2) + * [Header 33](#header-33) + * [Header 44](#header-44) + * [Header 55](#header-55) + * [Header 66](#header-66) + * [Header 77](#header-77) + + + +# Header 1 + +# Header 2 + +## Header 33 + +## Header 44 + +## Header 55 + +## Header 66 + +## Header 77