* Updated patch for org-info-src.js
@ 2022-12-24 15:26 David O'Toole
0 siblings, 0 replies; only message in thread
From: David O'Toole @ 2022-12-24 15:26 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 405 bytes --]
Hi everyone,
As you may recall, I have been working on org-info-js. I have fixed at
least one bug since my last patch, where org-info-js had gotten out of sync
with the details of Org HTML export. I also split several "paragraphs" of
code out into their own functions so that I could call them from elsewhere.
Thus I am submitting an updated patch for your consideration. I hope you
will find it useful.
[-- Attachment #1.2: Type: text/html, Size: 501 bytes --]
[-- Attachment #2: org-info-src.js.diff --]
[-- Type: text/x-patch, Size: 17347 bytes --]
diff -u /home/dto/Downloads/org-info-src.js /home/dto/notebook/org-info-src.js
--- /home/dto/Downloads/org-info-src.js 2022-12-10 11:47:20.086746072 -0500
+++ /home/dto/notebook/org-info-src.js 2022-12-24 10:18:38.010260115 -0500
@@ -28,30 +28,87 @@
* </script>
*
*
- * The script is now roughly devided in sections by form-feeds. Editors can
- * move section wise using the common emacs commands for this purpos ('C-x ]'
- * and 'C-x ]').
+ * The script is now roughly divided into sections by
+ * form-feeds. Editors can move section-wise using the common emacs
+ * commands for this purpose ('C-x ]' and 'C-x ]').
*
* The sections are:
* 1. This comment block.
- * 2. Everything around =OrgNodes=.
- * 3. =org_html_manager= constructor and setup.
- * 4. =org_html_manager= folding and view related stuff.
- * 5. =org_html_manager= history related methods.
- * 6. =org_html_manager= minibuffer handling.
- * 7. =org_html_manager= user input.
- * 8. =org_html_manager= search functonality.
- * 9. =org_html_manager= misc.
- * 10. Global functions.
+ * 2. Content hooks
+ * 3. Everything around =OrgNodes=.
+ * 4. =org_html_manager= constructor and setup.
+ * 5. =org_html_manager= folding and view related stuff.
+ * 6. =org_html_manager= history related methods.
+ * 7. =org_html_manager= minibuffer handling.
+ * 8. =org_html_manager= user input.
+ * 9. =org_html_manager= search functonality.
+ * 10. =org_html_manager= misc.
+ * 11. Global functions.
*/
+/**
+ * This program has been modified from its original version to add
+ * hooks for per-page HTML injection and per-click navigation event
+ * response. A patch is being submitted to upstream.
+ * - David T. O'Toole <deeteeoh1138@gmail.com>
+ */
\f
+var OrgInfoCurrentSectionNumber = 0;
+
+/**
+ * The following variable should hold a function which accepts an
+ * integer pageNumber and should return HTML to be inserted in the
+ * OrgInfo header of each page.
+ */
+var OrgInfoPageInsertFunction = function(pageNumber) {return '';};
+
+
+/**
+ * The following variable should hold a function which accepts an
+ * integer pageNumber and performs a user-defined action after the
+ * page has flipped.
+ *
+ */
+var OrgInfoAfterNavigateFunction = function(pageNumber) {};
+
+/**
+ * The following variable should hold a function which performs a
+ * user-defined action after Plain View has been activated.
+ *
+ */
+
+var OrgInfoAfterPlainViewFunction = function() {};
+
+/**
+ * The following variable should hold a function which performs a
+ * user-defined action after Info View has been activated.
+ *
+ */
+
+var OrgInfoAfterInfoViewFunction = function() {};
+
+/**
+ * The following variable should hold a function which performs a
+ * user-defined action after the document is ready.
+ */
+
+var OrgInfoAfterReadyFunction = function() {};
+
+/**
+ * Custom keybindings for Z, K, and Y.
+ */
+var OrgInfoUserKeyZ = function () {};
+var OrgInfoUserKeyK = function () {};
+var OrgInfoUserKeyY = function () {};
+
+\f
+
/**
* Creates a new OrgNode.
- * An OrgOutline stores some refs to its assoziated node in the document tree
+ * An OrgOutline stores some refs to its associated node in the document tree
* along with some additional properties.
*/
function OrgNode ( _div, _heading, _link, _depth, _parent, _base_id, _toc_anchor)
@@ -87,8 +144,17 @@
var fid = _base_id.substring(4);
folder = document.getElementById("text-"+fid); // try old schema
}
- if(null != folder)
- t.FOLDER = folder;
+
+ if(null == folder)
+ {
+ if (null != t.BASE_ID) {
+ var did = OrgInfoRecoverSectionID(document.getElementById(t.BASE_ID).textContent);
+ folder = document.getElementById("text-"+did);
+ }
+ }
+
+ if(null != folder)
+ { t.FOLDER = folder;}
t.isTargetFor = new Object();
t.isTargetFor['#' + t.BASE_ID] = 2;
@@ -434,7 +500,7 @@
var v = sets[i].substring(pos+1);
var k = sets[i].substring(0, pos);
switch(k) {
- // Explicitely allow overwrites.
+ // Explicitly allow overwrites.
// Fall through:
case 'TOC':
case 'TOC_DEPTH':
@@ -634,6 +700,7 @@
}
t.HOOKS.run_hooks = true; // Unblock all hooks.
t.runHooks('onReady', this.NODE);
+ OrgInfoAfterReadyFunction();
},
@@ -734,7 +801,7 @@
t.cutToc(theIndex, 1);
}
- // Move the title into the first visible section.
+ // Move the title into the first visible section.urrentpage
// TODO: show title above everything if FIXED_TOC !!!
t.TITLE = document.getElementsByClassName("title")[0];
if(t.INNER_TITLE && !t.FIXED_TOC && t.VIEW != t.SLIDE_VIEW) {
@@ -754,7 +821,7 @@
t.BODY.insertBefore(t.WINDOW, t.NODE.DIV);
- return true;
+ return true;
},
/**
@@ -904,14 +971,16 @@
for(var i = 0; i < this.SECS.length; ++i)
{
this.SECS[i].IDX = i;
- var html = '<table class="org-info-js_info-navigation" width="100%" border="0" style="border-bottom:1px solid black;">'
- +'<tr><td colspan="3" style="text-align:left;border-style:none;vertical-align:bottom;">'
- +'<span style="float:left;display:inline;text-align:left;">'
- +'Top: <a accesskey="t" href="javascript:org_html_manager.navigateTo(0);">'+index_name+'</a></span>'
- +'<span style="float:right;display:inline;text-align:right;font-size:70%;">'
- + this.LINKS
- +'<a accesskey="m" href="javascript:org_html_manager.toggleView('+i+');">toggle view</a></span>'
- +'</td></tr><tr><td style="text-align:left;border-style:none;vertical-align:bottom;width:22%">';
+ var html =
+ OrgInfoPageInsertFunction(i)
+ + '<table class="org-info-js_info-navigation" width="100%" border="0" style="border-bottom:1px solid black;">'
+ +'<tr><td colspan="3" style="text-align:left;border-style:none;vertical-align:bottom;">'
+ + '<span style="float:left;display:inline;text-align:left;">'
+ + 'Top: <a accesskey="t" href="javascript:org_html_manager.navigateTo(0);">'+index_name+'</a></span>'
+ + '<span style="float:right;display:inline;text-align:right;font-size:70%;">'
+ + this.LINKS
+ + '<a accesskey="m" href="javascript:org_html_manager.toggleView('+i+');">toggle view</a></span>'
+ + '</td></tr><tr><td style="text-align:left;border-style:none;vertical-align:bottom;width:22%">';
if(i>0)
html += '<a accesskey="p" href="'+this.SECS[i-1].L
@@ -930,10 +999,10 @@
if(i>0 && this.SECS[i].PARENT.PARENT) // != this.ROOT)
html += '<a href="'+this.SECS[i].PARENT.L
+'" title="Go to: '+this.removeTags(this.SECS[i].PARENT.HEADING.innerHTML)+'">'
- +'<span style="font-variant:small-caps;font-style:italic;">'
+ +'<span class="org-info-js_parent-heading" style="font-variant:small-caps;font-style:italic;">'
+this.SECS[i].PARENT.HEADING.innerHTML+'</span></a>';
else
- html += '<span style="font-variant:small-caps;font-style:italic;">'+this.SECS[i].HEADING.innerHTML+'</span>';
+ html += '<span class="org-info-js_parent-heading" style="font-variant:small-caps;font-style:italic;">'+this.SECS[i].HEADING.innerHTML+'</span>';
// Right:
html += '</td><td style="text-align:right;vertical-align:bottom;border-style:none;width:22%">';
@@ -1136,7 +1205,9 @@
t.showSection(sec);
if(t.POSTAMBLE) OrgNode.showElement(t.POSTAMBLE);
if(t.NODE.IDX == 0) window.scrollTo(0, 0);
- else t.NODE.DIV.scrollIntoView(true);
+ else t.NODE.DIV.scrollIntoView(true);
+ // call hook
+ OrgInfoAfterPlainViewFunction();
},
infoView: function (sec, skip_show_section)
@@ -1157,6 +1228,8 @@
if(!skip_show_section)
t.showSection(sec);
window.scrollTo(0, 0);
+ // call hook
+ OrgInfoAfterInfoViewFunction();
},
slideView: function (sec, skip_show_section)
@@ -1259,7 +1332,21 @@
t.NODE = t.SECS[section];
OrgNode.showElement(t.NODE.BUTTONS);
},
-
+
+ unfoldAll: function ()
+ {
+ var t = this;
+ if(t.ROOT.DIRTY) {
+ t.ROOT.STATE = OrgNode.STATE_UNFOLDED;
+ }
+ for(var i=0;i<t.SECS.length;++i) {
+ t.SECS[i].STATE = OrgNode.STATE_FOLDED;
+ t.SECS[i].fold(false);
+ }
+ t.ROOT.STATE = OrgNode.STATE_UNFOLDED;
+ t.ROOT.DIRTY = false;
+ },
+
toggleGlobaly: function ()
{
var t = this;
@@ -1321,7 +1408,7 @@
var T = this;
var i = T.NODE.IDX + 1;
if(i<T.SECS.length) T.navigateTo(i);
- else T.warn("Already last section.");
+ else T.warn("This is already the last section.");
},
previousSection: function()
@@ -1329,7 +1416,7 @@
var t = this;
var i = t.NODE.IDX;
if(i>0) t.navigateTo(i-1);
- else t.warn("Already first section.");
+ else t.warn("This is already the first section.");
},
@@ -1345,6 +1432,8 @@
if(t.VIEW == t.SLIDE_VIEW) t.adjustSlide(sec);
t.pushHistory(sec, t.NODE.IDX);
t.showSection(sec);
+ OrgInfoCurrentSectionNumber = sec;
+ OrgInfoAfterNavigateFunction();
},
@@ -1386,7 +1475,7 @@
else if(t.HFO && history.length) history.forward();
else {
t.HFO=1;
- t.warn("History: No where to foreward go from here. Any key and `B' to move to next file in history.");
+ t.warn("History: There is nowhere to go forward to from here. Press `B' to move to the next page in your browser history.");
}
} else {
if(t.HISTORY[t.HIST_INDEX - 1]) {
@@ -1406,7 +1495,7 @@
else if(t.HBO && history.length) history.back();
else {
t.HBO=1;
- t.warn("History: No where to back go from here. Any key and `b' to move to previous file in history.");
+ t.warn("History: Nowhere to go back to from here. Press `b' to move to the previous page in your browser history.");
}
}
},
@@ -1549,18 +1638,23 @@
if (1 == s.length) // one char wide commands
{
- if ('b' == s) {
+ if ('z' == s) {
+ OrgInfoUserKeyZ();
+ }
+ else if ('k' == s) {
+ OrgInfoUserKeyK();
+ }
+ else if ('y' == s) {
+ OrgInfoUserKeyY();
+ }
+ else if ('b' == s) {
t.popHistory();
}
else if ('B' == s) {
t.popHistory(true);
}
else if ('c' == s) {
- t.removeSearchHighlight();
- if(t.VIEW == t.INFO_VIEW || t.VIEW == t.SLIDE_VIEW) {
- // redisplay in info view mode:
- t.showSection(t.NODE.IDX);
- }
+ OrgInfoDoRemoveSearchHighlight(this);
}
else if ('i' == s) {
if(! t.FIXED_TOC) {
@@ -1584,7 +1678,7 @@
else if(t.NODE.IDX < t.SECS.length - 1) {
t.navigateTo(t.NODE.IDX + 1);
} else {
- t.warn("Already last section.");
+ t.warn("This is already the last section.");
return; // rely on what happends if messaging
}
}
@@ -1600,14 +1694,14 @@
++idx;
}
}
- t.warn("No next sibling.");
+ t.warn("There is no next sibling.");
return; // rely on what happends if messaging
}
else if ('p' == s) {
if(t.NODE.IDX > 0) {
t.navigateTo(t.NODE.IDX - 1);
} else {
- t.warn("Already first section.");
+ t.warn("This is already the first section.");
return; // rely on what happends if messaging
}
}
@@ -1623,7 +1717,7 @@
--idx;
}
}
- t.warn("No previous sibling.");
+ t.warn("There is no previous sibling.");
}
else if ('q' == s) {
if(window.confirm("Really close this file?")) {
@@ -1811,56 +1905,15 @@
}
else if(command == 's') { // search
- if("" == result) return false;
- if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight();
- var restore = t.OCCUR;
- var plus = 0;
- if(result == t.OCCUR) plus++;
- t.OCCUR = result;
- t.makeSearchRegexp();
- for(var i = t.NODE.IDX + plus; i < t.SECS.length; ++i) {
- if(t.searchTextInOrgNode(i)) {
- t.OCCUR = result;
- t.hideConsole();
- t.navigateTo(t.SECS[i].IDX);
- return;
- }
- }
- t.warn("Search forwards: text not found.", false, t.OCCUR);
- t.OCCUR = restore;
- return;
+ OrgInfoDoSearch(this, result);
}
else if(command == 'S') { // repeat search
- for(var i = t.NODE.IDX + 1; i < t.SECS.length; ++i) {
- if(t.searchTextInOrgNode(i)) {
- t.hideConsole();
- t.navigateTo(t.SECS[i].IDX);
- return;
- }
- }
- t.warn("Search forwards: text not found.", false, t.OCCUR);
- return;
+ OrgInfoDoRepeatSearch(this);
}
else if(command == 'r') { // search backwards
- if("" == result) return false;
- if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight();
- var restore = t.OCCUR;
- t.OCCUR = result;
- var plus = 0;
- if(result == t.OCCUR) plus++;
- t.makeSearchRegexp();
- for(var i = t.NODE.IDX - plus; i > -1; --i) {
- if(t.searchTextInOrgNode(i)) {
- t.hideConsole();
- t.navigateTo(t.SECS[i].IDX);
- return;
- }
- }
- t.warn("Search backwards: text not found.", false, t.OCCUR);
- t.OCCUR = restore;
- return;
+ OrgInfoDoSearchBackward(this, result);
}
else if(command == 'R') { // repeat search backwards
@@ -2004,7 +2057,13 @@
t.SECS[i].HAS_HIGHLIGHT = true;
t.SEARCH_HIGHLIGHT_ON = true;
}
- if(t.SEARCH_REGEX.test(t.SECS[i].FOLDER.innerHTML)) {
+
+ if (t.SECS[i].FOLDER == null)
+ {
+ ret = false;
+ }
+
+ else if (t.SEARCH_REGEX.test(t.SECS[i].FOLDER.innerHTML)) {
ret = true;
t.setSearchHighlight(t.SECS[i].FOLDER);
t.SECS[i].HAS_HIGHLIGHT = true;
@@ -2031,10 +2090,11 @@
var tmp = t.SECS[i].HEADING.innerHTML;
t.SECS[i].HEADING.innerHTML = tmp.replace(t.SEARCH_HL_REGEX, '$2');
}
+ if (null != t.SECS[i].FOLDER) {
while(t.SEARCH_HL_REGEX.test(t.SECS[i].FOLDER.innerHTML)) {
var tmp = t.SECS[i].FOLDER.innerHTML;
t.SECS[i].FOLDER.innerHTML = tmp.replace(t.SEARCH_HL_REGEX, '$2');
- }
+ }}
t.SECS[i].HAS_HIGHLIGHT = false;
}
}
@@ -2262,9 +2322,12 @@
\f
+var OrgInfoDisableKeybindings = null;
function OrgHtmlManagerKeyEvent (e)
{
+ if (OrgInfoDisableKeybindings == true) return;
+
var c;
if (!e) e = window.event;
if (e.which) c = e.which;
@@ -2291,3 +2354,81 @@
{
org_html_manager.init();
}
+
+\f
+
+function OrgInfoDoSearch (t, result)
+{
+ if("" == result) return false;
+ if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight();
+ var restore = t.OCCUR;
+ var plus = 0;
+ if(result == t.OCCUR) plus++;
+ t.OCCUR = result;
+ t.makeSearchRegexp();
+ for(var i = t.NODE.IDX + plus; i < t.SECS.length; ++i) {
+ if(t.searchTextInOrgNode(i)) {
+ t.OCCUR = result;
+ t.hideConsole();
+ t.navigateTo(t.SECS[i].IDX);
+ return;
+ }
+ }
+ t.warn("Search forwards: text not found.", false, t.OCCUR);
+ t.OCCUR = restore;
+ return;
+}
+
+function OrgInfoDoRepeatSearch (t)
+{
+ for(var i = t.NODE.IDX + 1; i < t.SECS.length; ++i) {
+ if(t.searchTextInOrgNode(i)) {
+ t.hideConsole();
+ t.navigateTo(t.SECS[i].IDX);
+ return;
+ }
+ }
+ t.warn("Search forwards: text not found.", false, t.OCCUR);
+ return;
+}
+
+function OrgInfoRecoverSectionID(heading) {
+ var firstChar = heading[0];
+ if (firstChar >= '0' && firstChar <= '9') {
+ var strings = heading.split(' ');
+ var id = strings[0].replaceAll('.', '-');
+ var len = id.length;
+ var idf = id.slice(0, len-1);
+ return idf;
+ }
+ return null;
+}
+
+function OrgInfoDoSearchBackward(t, result) {
+ if("" == result) return false;
+ if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight();
+ var restore = t.OCCUR;
+ t.OCCUR = result;
+ var plus = 0;
+ if(result == t.OCCUR) plus++;
+ t.makeSearchRegexp();
+ for(var i = t.NODE.IDX - plus; i > -1; --i) {
+ if(t.searchTextInOrgNode(i)) {
+ t.hideConsole();
+ t.navigateTo(t.SECS[i].IDX);
+ return;
+ }
+ }
+ t.warn("Search backwards: text not found.", false, t.OCCUR);
+ t.OCCUR = restore;
+ return;
+}
+
+function OrgInfoDoRemoveSearchHighlight(t) {
+ t.removeSearchHighlight();
+ if(t.VIEW == t.INFO_VIEW || t.VIEW == t.SLIDE_VIEW) {
+ // redisplay in info view mode:
+ t.showSection(t.NODE.IDX);
+ }
+}
+
Diff finished. Sat Dec 24 10:18:46 2022
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-24 15:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-24 15:26 Updated patch for org-info-src.js David O'Toole
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).