ep_markdown_toc 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ # Auto publishing
2
+ To publish a new version of this plugin to NPM just bump the version number in package.json and travis will auto publish for you.
package/LICENSE ADDED
@@ -0,0 +1,89 @@
1
+
2
+ Apache License, Version 2.0
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
17
+
18
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
19
+
20
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
21
+
22
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
23
+
24
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
25
+
26
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
27
+
28
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
29
+
30
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
31
+
32
+ 2. Grant of Copyright License.
33
+
34
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
35
+
36
+ 3. Grant of Patent License.
37
+
38
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
39
+
40
+ 4. Redistribution.
41
+
42
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
43
+
44
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
45
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
46
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
47
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
48
+
49
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+
51
+ 5. Submission of Contributions.
52
+
53
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
54
+
55
+ 6. Trademarks.
56
+
57
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
58
+
59
+ 7. Disclaimer of Warranty.
60
+
61
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
62
+
63
+ 8. Limitation of Liability.
64
+
65
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 9. Accepting Warranty or Additional Liability.
68
+
69
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ APPENDIX: How to apply the Apache License to your work
74
+
75
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
76
+
77
+ Copyright [yyyy] [name of copyright owner]
78
+
79
+ Licensed under the Apache License, Version 2.0 (the "License");
80
+ you may not use this file except in compliance with the License.
81
+ You may obtain a copy of the License at
82
+
83
+ http://www.apache.org/licenses/LICENSE-2.0
84
+
85
+ Unless required by applicable law or agreed to in writing, software
86
+ distributed under the License is distributed on an "AS IS" BASIS,
87
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88
+ See the License for the specific language governing permissions and
89
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ ## Markdown editing in Etherpad
2
+
3
+ This plugin enhances Etherpad for Markdown-style writing.
4
+ It does this in multiple ways:
5
+ - It enables automatic generation of a Table of Contents based on Markdown-style hashsign headings (#, ##, etc.) in Etherpad documents (can be disabled through settings). === style headings are not supported at the moment, and likely will never be.
6
+ - It styles the headings to make it easier to scan long documents for chapters (can be disabled through settings)
7
+ - It adds a button to the toolbar that shows a quick cheatsheet for Markdown syntax
8
+ - It removes the default text styling buttons from the toolbar (can be reenabled through settings)
9
+
10
+ It was developed as a compagnion to [Octomode](https://cc.vvvvvvaria.org/wiki/Octomode), a collective editing space for PDF making, using Etherpad, Paged.js and Flask.
11
+ It borrows heavily from the excellent [ep_headings2](https://github.com/ether/ep_headings2) plugin.
12
+
13
+ ## Requirements
14
+
15
+ Etherpad 2.3.0 (maybe lower, untested)
16
+
17
+ ## Licence
18
+ This repository is published under the [CC4r*](LICENSE) license.
package/ep.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "parts": [
3
+ {
4
+ "name": "ep_markdown_toc",
5
+ "hooks": {
6
+ "eejsBlock_styles": "ep_markdown_toc/index",
7
+ "eejsBlock_editbarMenuRight": "ep_markdown_toc/index",
8
+ "eejsBlock_afterEditbar": "ep_markdown_toc/index",
9
+ "eejsBlock_mySettings": "ep_markdown_toc/index"
10
+ },
11
+ "client_hooks": {
12
+ "postAceInit": "ep_markdown_toc/static/js/client_hooks",
13
+ "aceEditorCSS": "ep_markdown_toc/static/js/client_hooks",
14
+ "postToolbarInit": "ep_markdown_toc/static/js/client_hooks",
15
+ "aceInitialized": "ep_markdown_toc/static/js/client_hooks",
16
+ "aceEditEvent": "ep_markdown_toc/static/js/client_hooks",
17
+ "aceAttribsToClasses": "ep_markdown_toc/static/js/client_hooks",
18
+ "acePostWriteDomLineHTML" : "ep_markdown_toc/static/js/client_hooks"
19
+ }
20
+ }
21
+ ]
22
+ }
package/index.js ADDED
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const eejs = require('ep_etherpad-lite/node/eejs/');
4
+
5
+ // console.log("[ep_markdown_toc] STARTED");
6
+
7
+ exports.eejsBlock_styles = (hook, context) => {
8
+ context.content += '<link href="../static/plugins/ep_markdown_toc/static/css/toc.css" rel="stylesheet">';
9
+ context.content += '<link href="../static/plugins/ep_markdown_toc/static/css/popup.css" rel="stylesheet">';
10
+ };
11
+
12
+
13
+ exports.eejsBlock_editbarMenuRight = (hookName, args, cb) => {
14
+ // console.log("MENU RIGHT");
15
+ args.content = eejs.require('ep_markdown_toc/templates/markdownButton.ejs') + args.content;
16
+ return cb();
17
+ };
18
+
19
+ exports.eejsBlock_afterEditbar = (hookName, args, cb) => {
20
+ args.content += eejs.require('ep_markdown_toc/templates/tocContainer.ejs');
21
+ args.content += eejs.require('ep_markdown_toc/templates/markdownPopup.ejs');
22
+ return cb();
23
+ };
24
+
25
+ exports.eejsBlock_mySettings = (hookName, args, cb) => {
26
+ args.content += eejs.require('ep_markdown_toc/templates/tocSettings.ejs');
27
+ return cb();
28
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "ep_markdown_toc.showMarkdown" : "Show Markdown"
3
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "ep_markdown_toc",
3
+ "description": "Provides markdown-based heading detection and TOC for Etherpad, used in Octomode.",
4
+ "version": "1.0.4",
5
+ "author": {
6
+ "name": "hrk",
7
+ "email": "heerko@hackersanddesigners.nl"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/ether/ep_markdown_toc.git"
12
+ },
13
+ "dependencies": {
14
+ "showdown": "*"
15
+ },
16
+ "contributors": [],
17
+ "license": "Apache-2.0",
18
+ "funding": {
19
+ "type": "individual",
20
+ "url": "https://etherpad.org/"
21
+ },
22
+ "devDependencies": {
23
+ "eslint": "^8.57.0",
24
+ "eslint-config-etherpad": "^4.0.4",
25
+ "typescript": "^5.4.2",
26
+ "@types/mocha": "^10.0.6",
27
+ "@types/node": "^20.12.4"
28
+ },
29
+ "engines": {
30
+ "node": ">=18.0.0"
31
+ },
32
+ "scripts": {
33
+ "lint": "eslint .",
34
+ "lint:fix": "eslint --fix ."
35
+ }
36
+ }
@@ -0,0 +1,30 @@
1
+ #markdown-cheat {
2
+ position: absolute;
3
+ right: 10px;
4
+ top: 40px;
5
+ z-index: 1000;
6
+ background: #fff;
7
+ border: 1px solid #ccc;
8
+ border-radius: 4px;
9
+ max-width: 400px;
10
+ font-family: monospace;
11
+ font-size: 12px;
12
+ padding: 10px;
13
+ }
14
+
15
+ #markdown-cheat a {
16
+ color: var(--primary-color);
17
+ }
18
+
19
+ #markdown-cheat h2 {
20
+ margin-top: 0;
21
+ }
22
+
23
+ #markdown-cheat .popup-content {
24
+ max-height: 60vh;
25
+ overflow-y: auto;
26
+ }
27
+
28
+ #markdown-cheat .popup-content pre {
29
+ white-space: break-spaces;
30
+ }
@@ -0,0 +1,66 @@
1
+ #toc-container {
2
+ position: fixed;
3
+ top: 60px;
4
+ left: 5px;
5
+ background: white;
6
+ padding: 0.5em;
7
+ border: 1px solid #ccc;
8
+ height: auto;
9
+ max-height: 90vh;
10
+ overflow: auto;
11
+ font-size: 0.9em;
12
+ z-index: 9999;
13
+ }
14
+
15
+ .hide-toc #toc-container {
16
+ opacity: 0;
17
+ transform: scale(.7);
18
+ transition: all .3s cubic-bezier(.74,-.05,.27,1.75);
19
+ visibility: hidden;
20
+ }
21
+
22
+ #markdown-toc {
23
+ padding: 5px;
24
+ min-width: 185px;
25
+ max-width: 185px;
26
+ list-style-type: none;
27
+ }
28
+
29
+ #markdown-toc a {
30
+ cursor: pointer;
31
+ color: var(--primary-color);
32
+ text-decoration: none;
33
+ display: inline-block;
34
+ white-space: break-spaces;
35
+ }
36
+
37
+ #markdown-toc a:hover {
38
+ text-decoration: underline;
39
+ }
40
+
41
+ #markdown-cheat h3,
42
+ #markdown-cheat h4 {
43
+ margin-top: .5rem;
44
+ }
45
+
46
+ /*
47
+ Add a margin for the TOC when enabled
48
+ */
49
+ .hide-toc #editorcontainer { margin-left: 200px; }
50
+
51
+ /*
52
+ For hiding the regular Ace/Etherpad editor buttons.
53
+ TODO: We might be able to this through manipulating the settings instead
54
+ */
55
+ .hide-buttons #editbar .menu_left [data-key="bold"],
56
+ .hide-buttons #editbar .menu_left [data-key="italic"],
57
+ .hide-buttons #editbar .menu_left [data-key="underline"],
58
+ .hide-buttons #editbar .menu_left [data-key="strikethrough"],
59
+ .hide-buttons #editbar .menu_left [data-key="bold"],
60
+ .hide-buttons #editbar .menu_left [data-key="insertorderedlist"],
61
+ .hide-buttons #editbar .menu_left [data-key="insertunorderedlist"],
62
+ .hide-buttons #editbar .menu_left [data-key="indent"],
63
+ .hide-buttons #editbar .menu_left [data-key="outdent"],
64
+ .hide-buttons #editbar .menu_left [data-key="bold"] + li {
65
+ display: none !important;
66
+ }
@@ -0,0 +1,19 @@
1
+ .style-md-headings .markdown-heading {
2
+ font-weight: bold;
3
+ }
4
+
5
+ .style-md-headings .markdown-heading-level-1 {
6
+ font-size: 2.5rem;
7
+ }
8
+
9
+ .style-md-headings .markdown-heading-level-2 {
10
+ font-size: 2.0rem;
11
+ }
12
+
13
+ .style-md-headings .markdown-heading-level-3 {
14
+ font-size: 1.5rem;
15
+ }
16
+
17
+ .style-md-headings .markdown-heading-level-4 {
18
+ font-size: 1rem;
19
+ }
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+
3
+ let _editorInfo = null; // Both no longer used atm, but leaving them for now.
4
+ let _ace;
5
+ const tags = ['h1', 'h2', 'h3', 'h4'];
6
+
7
+ /* Load the css in the editor iframe */
8
+ exports.aceEditorCSS = function() {
9
+ return ["ep_markdown_toc/static/css/toc_editor.css"];
10
+ };
11
+
12
+ /**
13
+ * Init TOC functionality on editor ready
14
+ */
15
+ exports.postAceInit = (hook, context) => {
16
+ // store a reference to the editor for later
17
+ _ace = context.ace;
18
+ updateTOC();
19
+ };
20
+
21
+ /**
22
+ * Debounced handler for editor content changes, to update the TOC
23
+ */
24
+ exports.aceEditEvent = (hook, context) => {
25
+ const callstack = context.callstack;
26
+ if (callstack.type === 'handleKeyEvent' || callstack.type === 'idleWorkTimer') {
27
+ clearTimeout(window.tocTimeout);
28
+ window.tocTimeout = setTimeout(() => {
29
+ updateTOC();
30
+ }, 100);
31
+ }
32
+ };
33
+
34
+ /*
35
+ Detect markdown headings and add dynamic DOM classes for headings
36
+ */
37
+ exports.acePostWriteDomLineHTML = (hook, context) => {
38
+ try {
39
+ // console.log(context);
40
+ if (!context || !context.node) return;
41
+ // Remove previous heading classes
42
+ context.node.classList.remove('markdown-heading');
43
+ context.node.className = context.node.className.replace(/\bmarkdown-heading-level-\d\b/g, '');
44
+
45
+ // search for markdown # headings in the text
46
+ const text = context.text || context.node.textContent || '';
47
+ const match = text.match(/^(#{1,6})\s+/);
48
+ if (match) {
49
+ // console.log("matched!")
50
+ const level = match[1].length;
51
+ context.node.classList.add('markdown-heading');
52
+ context.node.classList.add(`markdown-heading-level-${level}`);
53
+ }
54
+ } catch (e) {
55
+ // Fail silently
56
+ }
57
+ };
58
+
59
+ /*
60
+ Save reference to editorInfo, maybe remove?
61
+ */
62
+ exports.aceInitialized = (hook, context) => {
63
+ _editorInfo = context.editorInfo;
64
+ };
65
+
66
+ /*
67
+ Setup the tool button and settings ui
68
+ */
69
+ exports.postToolbarInit = () => {
70
+ $('#markdown-cheat-toggle').on('click', () => {
71
+ $('#markdown-cheat').toggleClass('popup-show');
72
+ });
73
+
74
+ initSettingsUI();
75
+ };
76
+
77
+ const scrollToLine = (lineNumber) => {
78
+ // Get the editor iframes
79
+ const padOuter = document.querySelector('iframe[name="ace_outer"]');
80
+ const padInner = padOuter?.contentDocument?.querySelector('iframe[name="ace_inner"]');
81
+
82
+ if (!padInner?.contentWindow?.document) {
83
+ console.warn('Could not find inner frame document');
84
+ return;
85
+ }
86
+
87
+ padInner.contentWindow.focus();
88
+ const lineElement = padInner.contentWindow.document.querySelectorAll('div')[lineNumber];
89
+ if (lineElement) {
90
+ setTimeout(() => {
91
+ lineElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
92
+ }, 100);
93
+ } else {
94
+ console.warn('Could not find line element');
95
+ }
96
+ };
97
+
98
+ const updateTOC = () => {
99
+ const container = document.getElementById('markdown-toc');
100
+ if (!container) return;
101
+
102
+ // Get pad outer and inner iframe
103
+ const padOuter = document.querySelector('iframe[name="ace_outer"]');
104
+ const padInner = padOuter?.contentDocument?.querySelector('iframe[name="ace_inner"]');
105
+ if (!padInner?.contentDocument) {
106
+ return;
107
+ }
108
+
109
+ const innerDoc = padInner.contentDocument;
110
+ const lines = Array.from(innerDoc.querySelectorAll('.ace-line'));
111
+ const headings = [];
112
+
113
+ lines.forEach((div, index) => {
114
+ const text = div.textContent || '';
115
+ const match = text.match(/^(#{1,6})\s+(.*)/);
116
+ if (match) {
117
+ const level = match[1].length;
118
+ const headingText = match[2];
119
+ headings.push({ level, text: headingText, lineNumber: index });
120
+ }
121
+ });
122
+
123
+ // Update TOC content
124
+ const tocContainer = document.getElementById('markdown-toc');
125
+ if (!tocContainer) return;
126
+ while (tocContainer.firstChild) {
127
+ tocContainer.removeChild(tocContainer.firstChild);
128
+ }
129
+
130
+ headings.forEach(h => {
131
+ const li = document.createElement('li');
132
+ const link = document.createElement('a');
133
+ link.textContent = `- ${h.text}`;//`${'–'.repeat(h.level - 1)} ${h.text}`;
134
+ link.href = '#';
135
+ link.style.marginLeft = `${(h.level - 1) * .75}em`;
136
+ link.dataset.line = h.lineNumber.toString();
137
+
138
+ link.onclick = (e) => {
139
+ e.preventDefault();
140
+ e.stopPropagation();
141
+ scrollToLine(h.lineNumber);
142
+ };
143
+
144
+ li.appendChild(link);
145
+ tocContainer.appendChild(li);
146
+ });
147
+ };
148
+
149
+
150
+ /* getting and setting the preferences from the cookie.
151
+ TODO: hiding the text styling buttons with css for now,
152
+ but it maybe possible to manipulate the list from settings.json?
153
+ */
154
+ function initSettingsUI() {
155
+ const padcookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie;
156
+
157
+ let prefs = padcookie.getPref('userPrefs') || {};
158
+
159
+ // defaults for first load
160
+ if (typeof prefs.hideToc === 'undefined') {
161
+ prefs.hideToc = false; // defaults to false
162
+ padcookie.setPref('userPrefs', prefs);
163
+ }
164
+ if (typeof prefs.hideButtons === 'undefined') {
165
+ prefs.hideButtons = true; // defaults to true
166
+ padcookie.setPref('userPrefs', prefs);
167
+ }
168
+ if (typeof prefs.styleHeadings === 'undefined') {
169
+ prefs.styleHeadings = true; // also true
170
+ padcookie.setPref('userPrefs', prefs);
171
+ }
172
+
173
+ // apply the headings class to the inner iframe if set
174
+ const padOuter = document.querySelector('iframe[name="ace_outer"]');
175
+ const padInner = padOuter?.contentDocument?.querySelector('iframe[name="ace_inner"]');
176
+ const innerHtml = padInner?.contentDocument?.documentElement;
177
+ if (innerHtml && prefs.styleHeadings !== false) {
178
+ innerHtml.classList.add('style-md-headings');
179
+ }
180
+
181
+ function bindToggleSetting(optionId, className, prefKey) {
182
+ const enabled = prefs[prefKey] === true;
183
+ $(optionId).prop('checked', enabled);
184
+ $('html').toggleClass(className, enabled);
185
+
186
+ $(optionId).on('change', function () {
187
+ const isChecked = $(this).is(':checked');
188
+ prefs[prefKey] = isChecked;
189
+ padcookie.setPref('userPrefs', prefs);
190
+ $('html').toggleClass(className, isChecked);
191
+ // we need the class on the inner iframe, so this ugliness:
192
+ if (className === 'style-md-headings') {
193
+ const padOuter = document.querySelector('iframe[name="ace_outer"]');
194
+ const padInner = padOuter?.contentDocument?.querySelector('iframe[name="ace_inner"]');
195
+ const innerHtml = padInner?.contentDocument?.documentElement;
196
+ if (innerHtml) {
197
+ innerHtml.classList.toggle('style-md-headings', isChecked);
198
+ }
199
+ }
200
+ });
201
+ }
202
+
203
+ bindToggleSetting('#options-hideToc', 'hide-toc', 'hideToc');
204
+ bindToggleSetting('#options-hideButtons', 'hide-buttons', 'hideButtons');
205
+ bindToggleSetting('#options-styleHeadings', 'style-md-headings', 'styleHeadings');
206
+ }
207
+
208
+ /* functions stolen from ep_headings2 */
209
+
210
+ const range = (start, end) => Array.from(
211
+ Array(Math.abs(end - start) + 1),
212
+ (_, i) => start + i
213
+ );
214
+
215
+ // Our heading attribute will result in a heaading:h1... :h6 class
216
+ exports.aceAttribsToClasses = (hookName, context) => {
217
+ if (context.key === 'heading') {
218
+ return [`heading:${context.value}`];
219
+ }
220
+ };
@@ -0,0 +1,5 @@
1
+ <li>
2
+ <button id="markdown-cheat-toggle" title="Markdown Cheatsheet">
3
+ <span style="font-weight: bold;">#MD?</span>
4
+ </button>
5
+ </li>
@@ -0,0 +1,55 @@
1
+ <div id="markdown-cheat" class="popup toolbar-popup">
2
+ <div class="popup-content">
3
+ <h2>Markdown Cheatsheet</h2>
4
+ <p>A quick reference for the most common Markdown formatting tags. Learn more: <a
5
+ href="https://garrettgman.github.io/rmarkdown/authoring_pandoc_markdown.html" target="_blank">Pandoc Markdown
6
+ Authoring Guide</a></p>
7
+ </p>
8
+ <h3>Headings</h3>
9
+ <pre><code># Heading 1
10
+ ## Heading 2
11
+ ### Heading 3
12
+ ### Heading 3
13
+ </code></pre>
14
+ <h3>Styling text</h3>
15
+ <pre><code>
16
+ For a paragraph break, follow a line by two or more spaces.
17
+
18
+ **bold**
19
+ *italic*
20
+ ~~strikethrough~~
21
+
22
+ `inline code`
23
+
24
+ ```
25
+ code block
26
+ ```
27
+
28
+ > blockquote
29
+ </code></pre>
30
+ <h3>Lists</h3>
31
+ <pre><code>
32
+ - Unordered list
33
+ 1. Ordered list
34
+ </code></pre>
35
+ <h3>Links & Images</h3>
36
+ <pre><code>
37
+ [link text](https://example.com)
38
+ ![alt](img.jpg)
39
+ ![alt](img.jpg){.class}
40
+ </code></pre>
41
+
42
+ <pre><code>
43
+ horizontal rule
44
+ ---
45
+
46
+ ::: intro
47
+ This is the intro block.
48
+ :::
49
+
50
+ ::: main
51
+ This is the main block.
52
+ :::
53
+ </code></pre>
54
+ </div>
55
+ </div>
@@ -0,0 +1,5 @@
1
+ <div id="toc-container">
2
+ <ul class="popup-content" id="markdown-toc">
3
+
4
+ </ul>
5
+ </div>
@@ -0,0 +1,17 @@
1
+ <fieldset>
2
+ <legend>MD TOC Settings</legend>
3
+ <p>
4
+ <input type="checkbox" id="options-hideToc" />
5
+ <label for="options-hideToc" aria-label="Hide TOC">Hide TOC</label>
6
+ </p>
7
+
8
+ <p>
9
+ <input type="checkbox" id="options-hideButtons" />
10
+ <label for="options-hideButtons" aria-label="Hide text styling buttons">Hide text styling buttons</label>
11
+ </p>
12
+
13
+ <p>
14
+ <input type="checkbox" id="options-styleHeadings" />
15
+ <label for="options-styleHeadings" aria-label="Enable/Disable styling of the markdown headings">Style Markdown headings</label>
16
+ </p>
17
+ </fieldset>