From dc0db685154253b95d4273196e239493817c29d1 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+SamTV12345@users.noreply.github.com> Date: Wed, 21 Jun 2023 14:13:31 +0200 Subject: [PATCH] Added docs as asciidoctor with cross platform support. (#5733) * Added docs as asciidoctor with cross platform support. * Fixed release script with new doc building mechanism. --- Makefile | 32 -- doc/api/api.adoc | 19 + doc/api/api.md | 10 - ...eset_library.md => changeset_library.adoc} | 34 +- doc/api/{editbar.md => editbar.adoc} | 22 +- doc/api/editorInfo.adoc | 125 ++++ doc/api/editorInfo.md | 79 --- ...ed_parameters.md => embed_parameters.adoc} | 29 +- ..._client-side.md => hooks_client-side.adoc} | 90 +-- ...{hooks_overview.md => hooks_overview.adoc} | 23 +- ..._server-side.md => hooks_server-side.adoc} | 238 ++++---- doc/api/{http_api.md => http_api.adoc} | 317 ++++++----- doc/api/{pluginfw.md => pluginfw.adoc} | 10 +- doc/api/{toolbar.md => toolbar.adoc} | 23 +- doc/assets/style.css | 18 +- doc/cookies.adoc | 74 +++ doc/cookies.md | 18 - doc/{database.md => database.adoc} | 37 +- doc/docker.adoc | 534 ++++++++++++++++++ doc/docker.md | 257 --------- doc/{documentation.md => documentation.adoc} | 4 +- doc/index.adoc | 25 + doc/index.md | 9 - doc/{localization.md => localization.adoc} | 86 +-- doc/{plugins.md => plugins.adoc} | 58 +- doc/{skins.md => skins.adoc} | 2 +- doc/{stats.md => stats.adoc} | 7 +- doc/template.html | 23 - make_docs.js | 58 ++ src/bin/release.js | 12 +- 30 files changed, 1412 insertions(+), 861 deletions(-) delete mode 100644 Makefile create mode 100644 doc/api/api.adoc delete mode 100644 doc/api/api.md rename doc/api/{changeset_library.md => changeset_library.adoc} (57%) rename doc/api/{editbar.md => editbar.adoc} (73%) create mode 100644 doc/api/editorInfo.adoc delete mode 100644 doc/api/editorInfo.md rename doc/api/{embed_parameters.md => embed_parameters.adoc} (84%) rename doc/api/{hooks_client-side.md => hooks_client-side.adoc} (94%) mode change 100755 => 100644 rename doc/api/{hooks_overview.md => hooks_overview.adoc} (89%) rename doc/api/{hooks_server-side.md => hooks_server-side.adoc} (93%) rename doc/api/{http_api.md => http_api.adoc} (84%) rename doc/api/{pluginfw.md => pluginfw.adoc} (86%) rename doc/api/{toolbar.md => toolbar.adoc} (80%) create mode 100644 doc/cookies.adoc delete mode 100644 doc/cookies.md rename doc/{database.md => database.adoc} (80%) create mode 100644 doc/docker.adoc delete mode 100644 doc/docker.md rename doc/{documentation.md => documentation.adoc} (91%) create mode 100644 doc/index.adoc delete mode 100644 doc/index.md rename doc/{localization.md => localization.adoc} (77%) rename doc/{plugins.md => plugins.adoc} (93%) rename doc/{skins.md => skins.adoc} (99%) rename doc/{stats.md => stats.adoc} (60%) delete mode 100644 doc/template.html create mode 100644 make_docs.js diff --git a/Makefile b/Makefile deleted file mode 100644 index bc79166b..00000000 --- a/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -doc_sources = $(wildcard doc/*/*.md) $(wildcard doc/*.md) -outdoc_files = $(addprefix out/,$(doc_sources:.md=.html)) - -docassets = $(addprefix out/,$(wildcard doc/assets/*)) - -VERSION = $(shell node -e "console.log( require('./src/package.json').version )") -UNAME := $(shell uname -s) - -ensure_marked_is_installed: - set -eu; \ - hash npm; \ - if [ $(shell npm list --prefix src/bin/doc >/dev/null 2>/dev/null; echo $$?) -ne "0" ]; then \ - npm ci --prefix=src/bin/doc; \ - fi - -docs: ensure_marked_is_installed $(outdoc_files) $(docassets) - -out/doc/assets/%: doc/assets/% - mkdir -p $(@D) - cp $< $@ - -out/doc/%.html: doc/%.md - mkdir -p $(@D) - node src/bin/doc/generate.js --format=html --template=doc/template.html $< > $@ -ifeq ($(UNAME),Darwin) - sed -i '' 's/__VERSION__/${VERSION}/' $@ -else - sed -i 's/__VERSION__/${VERSION}/' $@ -endif - -clean: - rm -rf out/ diff --git a/doc/api/api.adoc b/doc/api/api.adoc new file mode 100644 index 00000000..f73724d0 --- /dev/null +++ b/doc/api/api.adoc @@ -0,0 +1,19 @@ +include::./embed_parameters.adoc[] + +include::./http_api.adoc[] + +include::./hooks_overview.adoc[] + +include::./hooks_client-side.adoc[] + +include::./hooks_server-side.adoc[] + +include::./editorInfo.adoc[] + +include::./changeset_library.adoc[] + +include::./pluginfw.adoc[] + +include::./toolbar.adoc[] + +include::./editbar.adoc[] diff --git a/doc/api/api.md b/doc/api/api.md deleted file mode 100644 index d124e4c3..00000000 --- a/doc/api/api.md +++ /dev/null @@ -1,10 +0,0 @@ -@include embed_parameters -@include http_api -@include hooks_overview -@include hooks_client-side -@include hooks_server-side -@include editorInfo -@include changeset_library -@include pluginfw -@include toolbar -@include editbar \ No newline at end of file diff --git a/doc/api/changeset_library.md b/doc/api/changeset_library.adoc similarity index 57% rename from doc/api/changeset_library.md rename to doc/api/changeset_library.adoc index 7929aa48..99ae7737 100644 --- a/doc/api/changeset_library.md +++ b/doc/api/changeset_library.adoc @@ -1,14 +1,15 @@ -# Changeset Library +== Changeset Library -The [changeset -library](https://github.com/ether/etherpad-lite/blob/develop/src/static/js/Changeset.js) +The https://github.com/ether/etherpad-lite/blob/develop/src/static/js/Changeset.js[changeset +library] provides tools to create, read, and apply changesets. -## Changeset +=== Changeset -```javascript +[source,javascript] +---- const Changeset = require('ep_etherpad-lite/static/js/Changeset'); -``` +---- A changeset describes the difference between two revisions of a document. When a user edits a pad, the browser generates and sends a changeset to the server, @@ -17,28 +18,29 @@ is accessible). A transmitted changeset looks like this: -``` +[source] +---- 'Z:z>1|2=m=b*0|1+1$\n' -``` +---- -## Attribute Pool +=== Attribute Pool -```javascript +[source,javascript] +---- const AttributePool = require('ep_etherpad-lite/static/js/AttributePool'); -``` +---- Changesets do not include any attribute key–value pairs. Instead, they use -numeric identifiers that reference attributes kept in an [attribute -pool](https://github.com/ether/etherpad-lite/blob/develop/src/static/js/AttributePool.js). +numeric identifiers that reference attributes kept in an https://github.com/ether/etherpad-lite/blob/develop/src/static/js/AttributePool.js[attribute pool]. This attribute interning reduces the transmission overhead of attributes that are used many times. There is one attribute pool per pad, and it includes every current and historical attribute used in the pad. -## Further Reading +=== Further Reading Detailed information about the changesets & Easysync protocol: -* [Easysync Protocol](https://github.com/ether/etherpad-lite/blob/develop/doc/easysync/easysync-notes.pdf) -* [Etherpad and EasySync Technical Manual](https://github.com/ether/etherpad-lite/blob/develop/doc/easysync/easysync-full-description.pdf) +* https://github.com/ether/etherpad-lite/blob/develop/doc/easysync/easysync-notes.pdf[Easysync Protocol] +* https://github.com/ether/etherpad-lite/blob/develop/doc/easysync/easysync-full-description.pdf[Etherpad and EasySync Technical Manual] diff --git a/doc/api/editbar.md b/doc/api/editbar.adoc similarity index 73% rename from doc/api/editbar.md rename to doc/api/editbar.adoc index f448a218..8dc865f8 100644 --- a/doc/api/editbar.md +++ b/doc/api/editbar.adoc @@ -1,28 +1,30 @@ -# Editbar +== Editbar src/static/js/pad_editbar.js -## isEnabled() +=== isEnabled() -## disable() +=== disable() -## toggleDropDown(dropdown) +=== toggleDropDown(dropdown) Shows the dropdown `div.popup` whose `id` equals `dropdown`. -## registerCommand(cmd, callback) +=== registerCommand(cmd, callback) Register a handler for a specific command. Commands are fired if the corresponding button is clicked or the corresponding select is changed. -## registerAceCommand(cmd, callback) +=== registerAceCommand(cmd, callback) Creates an ace callstack and calls the callback with an ace instance (and a toolbar item, if applicable): `callback(cmd, ace, item)`. Example: -``` + +[source, javascript] +---- toolbar.registerAceCommand("insertorderedlist", function (cmd, ace) { ace.ace_doInsertOrderedList(); }); -``` +---- -## registerDropdownCommand(cmd, dropdown) +=== registerDropdownCommand(cmd, dropdown) Ties a `div.popup` where `id` equals `dropdown` to a `command` fired by clicking a button. -## triggerCommand(cmd[, item]) +=== triggerCommand(cmd[, item]) Triggers a command (optionally with some internal representation of the toolbar item that triggered it). diff --git a/doc/api/editorInfo.adoc b/doc/api/editorInfo.adoc new file mode 100644 index 00000000..9ea4fccd --- /dev/null +++ b/doc/api/editorInfo.adoc @@ -0,0 +1,125 @@ +== editorInfo + +=== editorInfo.ace_replaceRange(start, end, text) +This function replaces a range (from `start` to `end`) with `text`. + +=== editorInfo.ace_getRep() +Returns the `rep` object. + +=== editorInfo.ace_getAuthor() + +=== editorInfo.ace_inCallStack() + +=== editorInfo.ace_inCallStackIfNecessary(?) + +=== editorInfo.ace_focus(?) + +=== editorInfo.ace_importText(?) + +=== editorInfo.ace_importAText(?) + +=== editorInfo.ace_exportText(?) + +=== editorInfo.ace_editorChangedSize(?) + +=== editorInfo.ace_setOnKeyPress(?) + +=== editorInfo.ace_setOnKeyDown(?) + +=== editorInfo.ace_setNotifyDirty(?) + +=== editorInfo.ace_dispose(?) + +=== editorInfo.ace_setEditable(bool) + +=== editorInfo.ace_execCommand(?) + +=== editorInfo.ace_callWithAce(fn, callStack, normalize) + +=== editorInfo.ace_setProperty(key, value) + +=== editorInfo.ace_setBaseText(txt) + +=== editorInfo.ace_setBaseAttributedText(atxt, apoolJsonObj) + +=== editorInfo.ace_applyChangesToBase(c, optAuthor, apoolJsonObj) + +=== editorInfo.ace_prepareUserChangeset() + +=== editorInfo.ace_applyPreparedChangesetToBase() + +=== editorInfo.ace_setUserChangeNotificationCallback(f) + +=== editorInfo.ace_setAuthorInfo(author, info) + +=== editorInfo.ace_fastIncorp(?) + +=== editorInfo.ace_isCaret(?) + +=== editorInfo.ace_getLineAndCharForPoint(?) + +=== editorInfo.ace_performDocumentApplyAttributesToCharRange(?) + +=== editorInfo.ace_setAttributeOnSelection(attribute, enabled) + +Sets an attribute on current range. +Example: `call.editorInfo.ace_setAttributeOnSelection("turkey::balls", true); // turkey is the attribute here, balls is the value +Notes: to remove the attribute pass enabled as false + +=== editorInfo.ace_toggleAttributeOnSelection(?) + +=== editorInfo.ace_getAttributeOnSelection(attribute, prevChar) +Returns a boolean if an attribute exists on a selected range. +prevChar value should be true if you want to get the previous Character attribute instead of the current selection for example +if the caret is at position 0,1 (after first character) it's probable you want the attributes on the character at 0,0 +The attribute should be the string name of the attribute applied to the selection IE subscript +Example usage: Apply the activeButton Class to a button if an attribute is on a highlighted/selected caret position or range. +Example `var isItThere = documentAttributeManager.getAttributeOnSelection("turkey::balls", true);` + +See the ep_subscript plugin for an example of this function in action. +Notes: Does not work on first or last character of a line. Suffers from a race condition if called with aceEditEvent. + +=== editorInfo.ace_performSelectionChange(?) + +=== editorInfo.ace_doIndentOutdent(?) + +=== editorInfo.ace_doUndoRedo(?) + +=== editorInfo.ace_doInsertUnorderedList(?) + +=== editorInfo.ace_doInsertOrderedList(?) + +=== editorInfo.ace_performDocumentApplyAttributesToRange() + +=== editorInfo.ace_getAuthorInfos() +Returns an info object about the author. Object key = author_id and info includes author's bg color value. +Use to define your own authorship. + +=== editorInfo.ace_performDocumentReplaceRange(start, end, newText) +This function replaces a range (from [x1,y1] to [x2,y2]) with `newText`. + +=== editorInfo.ace_performDocumentReplaceCharRange(startChar, endChar, newText) +This function replaces a range (from y1 to y2) with `newText`. + +=== editorInfo.ace_renumberList(lineNum) +If you delete a line, calling this method will fix the line numbering. + +=== editorInfo.ace_doReturnKey() +Forces a return key at the current caret position. + +=== editorInfo.ace_isBlockElement(element) +Returns true if your passed element is registered as a block element + +=== editorInfo.ace_getLineListType(lineNum) +Returns the line's html list type. + +=== editorInfo.ace_caretLine() +Returns X position of the caret. + +=== editorInfo.ace_caretColumn() +Returns Y position of the caret. + +=== editorInfo.ace_caretDocChar() +Returns the Y offset starting from [x=0,y=0] + +=== editorInfo.ace_isWordChar(?) diff --git a/doc/api/editorInfo.md b/doc/api/editorInfo.md deleted file mode 100644 index 834f5ac3..00000000 --- a/doc/api/editorInfo.md +++ /dev/null @@ -1,79 +0,0 @@ -# editorInfo - -## editorInfo.ace_replaceRange(start, end, text) -This function replaces a range (from `start` to `end`) with `text`. - -## editorInfo.ace_getRep() -Returns the `rep` object. - -## editorInfo.ace_getAuthor() -## editorInfo.ace_inCallStack() -## editorInfo.ace_inCallStackIfNecessary(?) -## editorInfo.ace_focus(?) -## editorInfo.ace_importText(?) -## editorInfo.ace_importAText(?) -## editorInfo.ace_exportText(?) -## editorInfo.ace_editorChangedSize(?) -## editorInfo.ace_setOnKeyPress(?) -## editorInfo.ace_setOnKeyDown(?) -## editorInfo.ace_setNotifyDirty(?) -## editorInfo.ace_dispose(?) -## editorInfo.ace_setEditable(bool) -## editorInfo.ace_execCommand(?) -## editorInfo.ace_callWithAce(fn, callStack, normalize) -## editorInfo.ace_setProperty(key, value) -## editorInfo.ace_setBaseText(txt) -## editorInfo.ace_setBaseAttributedText(atxt, apoolJsonObj) -## editorInfo.ace_applyChangesToBase(c, optAuthor, apoolJsonObj) -## editorInfo.ace_prepareUserChangeset() -## editorInfo.ace_applyPreparedChangesetToBase() -## editorInfo.ace_setUserChangeNotificationCallback(f) -## editorInfo.ace_setAuthorInfo(author, info) -## editorInfo.ace_fastIncorp(?) -## editorInfo.ace_isCaret(?) -## editorInfo.ace_getLineAndCharForPoint(?) -## editorInfo.ace_performDocumentApplyAttributesToCharRange(?) -## editorInfo.ace_setAttributeOnSelection(attribute, enabled) -Sets an attribute on current range. -Example: `call.editorInfo.ace_setAttributeOnSelection("turkey::balls", true); // turkey is the attribute here, balls is the value -Notes: to remove the attribute pass enabled as false -## editorInfo.ace_toggleAttributeOnSelection(?) -## editorInfo.ace_getAttributeOnSelection(attribute, prevChar) -Returns a boolean if an attribute exists on a selected range. -prevChar value should be true if you want to get the previous Character attribute instead of the current selection for example -if the caret is at position 0,1 (after first character) it's probable you want the attributes on the character at 0,0 -The attribute should be the string name of the attribute applied to the selection IE subscript -Example usage: Apply the activeButton Class to a button if an attribute is on a highlighted/selected caret position or range. -Example `var isItThere = documentAttributeManager.getAttributeOnSelection("turkey::balls", true);` - -See the ep_subscript plugin for an example of this function in action. -Notes: Does not work on first or last character of a line. Suffers from a race condition if called with aceEditEvent. -## editorInfo.ace_performSelectionChange(?) -## editorInfo.ace_doIndentOutdent(?) -## editorInfo.ace_doUndoRedo(?) -## editorInfo.ace_doInsertUnorderedList(?) -## editorInfo.ace_doInsertOrderedList(?) -## editorInfo.ace_performDocumentApplyAttributesToRange() - -## editorInfo.ace_getAuthorInfos() -Returns an info object about the author. Object key = author_id and info includes author's bg color value. -Use to define your own authorship. -## editorInfo.ace_performDocumentReplaceRange(start, end, newText) -This function replaces a range (from [x1,y1] to [x2,y2]) with `newText`. -## editorInfo.ace_performDocumentReplaceCharRange(startChar, endChar, newText) -This function replaces a range (from y1 to y2) with `newText`. -## editorInfo.ace_renumberList(lineNum) -If you delete a line, calling this method will fix the line numbering. -## editorInfo.ace_doReturnKey() -Forces a return key at the current caret position. -## editorInfo.ace_isBlockElement(element) -Returns true if your passed element is registered as a block element -## editorInfo.ace_getLineListType(lineNum) -Returns the line's html list type. -## editorInfo.ace_caretLine() -Returns X position of the caret. -## editorInfo.ace_caretColumn() -Returns Y position of the caret. -## editorInfo.ace_caretDocChar() -Returns the Y offset starting from [x=0,y=0] -## editorInfo.ace_isWordChar(?) diff --git a/doc/api/embed_parameters.md b/doc/api/embed_parameters.adoc similarity index 84% rename from doc/api/embed_parameters.md rename to doc/api/embed_parameters.adoc index d6f27af0..51130771 100644 --- a/doc/api/embed_parameters.md +++ b/doc/api/embed_parameters.adoc @@ -1,72 +1,73 @@ -# Embed parameters +== Embed parameters You can easily embed your etherpad-lite into any webpage by using iframes. You can configure the embedded pad using embed parameters. Example: Cut and paste the following code into any webpage to embed a pad. The parameters below will hide the chat and the line numbers and will auto-focus on Line 4. -``` +[source, html] +---- -``` +---- -## showLineNumbers +=== showLineNumbers * Boolean Default: true -## showControls +=== showControls * Boolean Default: true -## showChat +=== showChat * Boolean Default: true -## useMonospaceFont +=== useMonospaceFont * Boolean Default: false -## userName +=== userName * String Default: "unnamed" Example: `userName=Etherpad%20User` -## userColor +=== userColor * String (css hex color value) Default: randomly chosen by pad server Example: `userColor=%23ff9900` -## noColors +=== noColors * Boolean Default: false -## alwaysShowChat +=== alwaysShowChat * Boolean Default: false -## lang +=== lang * String Default: en Example: `lang=ar` (translates the interface into Arabic) -## rtl +=== rtl * Boolean Default: true Displays pad text from right to left. -## #L +=== #L * Int Default: 0 diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.adoc old mode 100755 new mode 100644 similarity index 94% rename from doc/api/hooks_client-side.md rename to doc/api/hooks_client-side.adoc index 45ef18a0..d10a948c --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.adoc @@ -1,9 +1,9 @@ -# Client-side hooks +== Client-side hooks Most of these hooks are called during or in order to set up the formatting process. -## documentReady +=== documentReady Called from: src/templates/pad.html Things in context: @@ -12,7 +12,7 @@ nothing This hook proxies the functionality of jQuery's `$(document).ready` event. -## aceDomLinePreProcessLineAttributes +=== aceDomLinePreProcessLineAttributes Called from: src/static/js/domline.js @@ -34,7 +34,7 @@ The preHtml and postHtml values will be added to the HTML display of the element, and if processedMarker is true, the engine won't try to process it any more. -## aceDomLineProcessLineAttributes +=== aceDomLineProcessLineAttributes Called from: src/static/js/domline.js @@ -56,7 +56,7 @@ The preHtml and postHtml values will be added to the HTML display of the element, and if processedMarker is true, the engine won't try to process it any more. -## aceCreateDomLine +=== aceCreateDomLine Called from: src/static/js/domline.js @@ -76,7 +76,7 @@ The return value of this hook should have the following structure: extraOpenTags and extraCloseTags will be added before and after the element in question, and cls will be the new class of the element going forward. -## acePostWriteDomLineHTML +=== acePostWriteDomLineHTML Called from: src/static/js/domline.js @@ -87,7 +87,7 @@ Things in context: This hook is for right after a node has been fully formatted and written to the page. -## aceAttribsToClasses +=== aceAttribsToClasses Called from: src/static/js/linestylefilter.js @@ -105,7 +105,7 @@ into the DOM. The return value for this function should be a list of classes, which will then be parsed into a valid class string. -## aceAttribClasses +=== aceAttribClasses Called from: src/static/js/linestylefilter.js @@ -116,14 +116,16 @@ This hook is called when attributes are investigated on a line. It is useful if you want to add another attribute type or property type to a pad. Example: -``` + +[source,javascript] +---- exports.aceAttribClasses = function(hook_name, attr, cb){ attr.sub = 'tag:sub'; cb(attr); } -``` +---- -## aceGetFilterStack +=== aceGetFilterStack Called from: src/static/js/linestylefilter.js @@ -139,7 +141,7 @@ links. They use it to find the telltale `[[ ]]` syntax that signifies internal links, and finding that syntax, they add in the internalHref attribute to be later used by the aceCreateDomLine hook (documented above). -## aceEditorCSS +=== aceEditorCSS Called from: src/static/js/ace.js @@ -148,7 +150,7 @@ Things in context: None This hook is provided to allow custom CSS files to be loaded. The return value should be an array of resource urls or paths relative to the plugins directory. -## aceInitInnerdocbodyHead +=== aceInitInnerdocbodyHead Called from: src/static/js/ace.js @@ -161,7 +163,7 @@ have lines of HTML added to it, giving the plugin author a chance to add in meta, script, link, and other tags that go into the `` element of the editor HTML document. -## aceEditEvent +=== aceEditEvent Called from: src/static/js/ace2_inner.js @@ -178,7 +180,7 @@ changes are made. Currently you can change the editor information, some of the meanings of the edit, and so on. You can also make internal changes (internal to your plugin) that use the information provided by the edit event. -## aceRegisterNonScrollableEditEvents +=== aceRegisterNonScrollableEditEvents Called from: src/static/js/ace2_inner.js @@ -191,13 +193,15 @@ not scroll viewport. The return value of this hook should be a list of event names. Example: -``` + +[source, javascript] +---- exports.aceRegisterNonScrollableEditEvents = function(){ return [ 'repaginate', 'updatePageCount' ]; } -``` +---- -## aceRegisterBlockElements +=== aceRegisterBlockElements Called from: src/static/js/ace2_inner.js @@ -207,7 +211,7 @@ The return value of this hook will add elements into the "lineMarkerAttribute" category, making the aceDomLineProcessLineAttributes hook (documented below) call for those elements. -## aceInitialized +=== aceInitialized Called from: src/static/js/ace2_inner.js @@ -222,7 +226,7 @@ Things in context: This hook is for inserting further information into the ace engine, for later use in formatting hooks. -## postAceInit +=== postAceInit Called from: src/static/js/pad.js @@ -234,7 +238,7 @@ Things in context: `clientVars` server-side hook. 3. pad - the pad object of the current pad. -## postToolbarInit +=== postToolbarInit Called from: src/static/js/pad_editbar.js @@ -247,16 +251,16 @@ Can be used to register custom actions to the toolbar. Usage examples: -* [https://github.com/tiblu/ep_authorship_toggle]() +* https://github.com/tiblu/ep_authorship_toggle -## postTimesliderInit +=== postTimesliderInit Called from: src/static/js/timeslider.js There doesn't appear to be any example available of this particular hook being used, but it gets fired after the timeslider is all set up. -## goToRevisionEvent +=== goToRevisionEvent Called from: src/static/js/broadcast.js @@ -268,7 +272,7 @@ This hook gets fired both on timeslider load (as timeslider shows a new revision) and when the new revision is showed to a user. There doesn't appear to be any example available of this particular hook being used. -## userJoinOrUpdate +=== userJoinOrUpdate Called from: src/static/js/pad_userlist.js @@ -279,7 +283,7 @@ Things in context: This hook is called on the client side whenever a user joins or changes. This can be used to create notifications or an alternate user list. -## `chatNewMessage` +=== `chatNewMessage` Called from: `src/static/js/chat.js` @@ -315,7 +319,7 @@ Context properties: * `duration`: How long (in milliseconds) to display the gritter notification (0 to disable). -## `chatSendMessage` +=== `chatSendMessage` Called from: `src/static/js/chat.js` @@ -327,7 +331,7 @@ Context properties: * `message`: The message object that will be sent to the Etherpad server. -## collectContentPre +=== collectContentPre Called from: src/static/js/contentcollector.js @@ -351,7 +355,7 @@ If you want to specify also a value, call cc.doAttrib(state, "attributeName::value") which results in an attribute attributeName=value. -## collectContentImage +=== collectContentImage Called from: src/static/js/contentcollector.js @@ -370,14 +374,15 @@ content of the pad. Example: -``` +[source, javascript] +---- exports.collectContentImage = function(name, context){ context.state.lineAttributes.img = context.node.outerHTML; } -``` +---- -## collectContentPost +=== collectContentPost Called from: src/static/js/contentcollector.js @@ -393,7 +398,7 @@ This hook is called after the content of a node is collected by the usual methods. The cc object can be used to do a bunch of things that modify the content of the pad. See, for example, the heading1 plugin for etherpad original. -## handleClientMessage_`name` +=== handleClientMessage_`name` Called from: `src/static/js/collab_client.js` @@ -410,7 +415,7 @@ also use this to handle existing types. `collab_client.js` has a pretty extensive list of message types, if you want to take a look. -## aceStartLineAndCharForPoint-aceEndLineAndCharForPoint +=== aceStartLineAndCharForPoint-aceEndLineAndCharForPoint Called from: src/static/js/ace2_inner.js @@ -426,7 +431,7 @@ Things in context: This hook is provided to allow a plugin to turn DOM node selection into [line,char] selection. The return value should be an array of [line,char] -## aceKeyEvent +=== aceKeyEvent Called from: src/static/js/ace2_inner.js @@ -441,7 +446,7 @@ Things in context: This hook is provided to allow a plugin to handle key events. The return value should be true if you have handled the event. -## collectContentLineText +=== collectContentLineText Called from: src/static/js/contentcollector.js @@ -462,13 +467,14 @@ server side. To change the text, either: Example: -``` +[source,javascript] +---- exports.collectContentLineText = (hookName, context) => { context.text = tweakText(context.text); }; -``` +---- -## collectContentLineBreak +=== collectContentLineBreak Called from: src/static/js/contentcollector.js @@ -481,7 +487,7 @@ Things in context: This hook is provided to allow whether the br tag should induce a new magic domline or not. The return value should be either true(break the line) or false. -## disableAuthorColorsForThisLine +=== disableAuthorColorsForThisLine Called from: src/static/js/linestylefilter.js @@ -497,7 +503,7 @@ multiple authors. Multiple authors in one line cause the creation of magic span lines. This might not suit you and now you can disable it and handle your own deliniation. The return value should be either true(disable) or false. -## aceSetAuthorStyle +=== aceSetAuthorStyle Called from: src/static/js/ace2_inner.js @@ -514,7 +520,7 @@ This hook is provided to allow author highlight style to be modified. Registered hooks should return 1 if the plugin handles highlighting. If no plugin returns 1, the core will use the default background-based highlighting. -## aceSelectionChanged +=== aceSelectionChanged Called from: src/static/js/ace2_inner.js diff --git a/doc/api/hooks_overview.md b/doc/api/hooks_overview.adoc similarity index 89% rename from doc/api/hooks_overview.md rename to doc/api/hooks_overview.adoc index 35a88dbe..65200ac1 100644 --- a/doc/api/hooks_overview.md +++ b/doc/api/hooks_overview.adoc @@ -1,4 +1,4 @@ -# Hooks +== Hooks A hook function is registered with a hook via the plugin's `ep.json` file. See the Plugins section for details. A hook may have many registered functions from @@ -8,12 +8,12 @@ Some hooks call their registered functions one at a time until one of them returns a value. Others always call all of their registered functions and combine the results (if applicable). -## Registered hook functions +=== Registered hook functions Note: The documentation in this section applies to every hook unless the hook-specific documentation says otherwise. -### Arguments +==== Arguments Hook functions are called with three arguments: @@ -26,7 +26,7 @@ Hook functions are called with three arguments: section for general information that applies to most hooks). This callback always returns `undefined`. -### Expected behavior +==== Expected behavior The presence of a callback parameter suggests that every hook function can run asynchronously. While that is the eventual goal, there are some legacy hooks @@ -54,15 +54,13 @@ Note that the acceptable behaviors for asynchronous hook functions is a superset of the acceptable behaviors for synchronous hook functions. WARNING: The number of parameters is determined by examining -[Function.length](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length), -which does not count [default -parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) -or ["rest" -parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length[Function.length], +which does not count https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters[default parameters] +or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters["rest" parameters]. To avoid problems, do not use default or rest parameters when defining hook functions. -### Return values +==== Return values A hook function can provide a value to Etherpad in one of the following ways: @@ -77,7 +75,8 @@ A hook function can provide a value to Etherpad in one of the following ways: Examples: -```javascript +[source,javascript] +---- exports.exampleOne = (hookName, context, callback) => { return 'valueOne'; }; @@ -104,7 +103,7 @@ exports.exampleFive = async (hookName, context) => { // is resolved to 'valueFive'. return 'valueFive'; }; -``` +---- Etherpad collects the values provided by the hook functions into an array, filters out all `undefined` values, then flattens the array one level. diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.adoc similarity index 93% rename from doc/api/hooks_server-side.md rename to doc/api/hooks_server-side.adoc index 5998c247..0871f0c9 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.adoc @@ -1,7 +1,7 @@ -# Server-side hooks +== Server-side hooks These hooks are called on server-side. -## loadSettings +=== loadSettings Called from: src/node/server.js Things in context: @@ -10,7 +10,7 @@ Things in context: Use this hook to receive the global settings in your plugin. -## shutdown +=== shutdown Called from: src/node/server.js Things in context: None @@ -25,14 +25,15 @@ Returning `callback(value)` will return a Promise that is resolved to `value`. Example: -``` +[source, javascript] +---- // using an async function exports.shutdown = async (hookName, context) => { await flushBuffers(); }; -``` +---- -## pluginUninstall +=== pluginUninstall Called from: src/static/js/pluginfw/installer.js Things in context: @@ -41,7 +42,7 @@ Things in context: If this hook returns an error, the callback to the uninstall function gets an error as well. This mostly seems useful for handling additional features added in based on the installation of other plugins, which is pretty cool! -## pluginInstall +=== pluginInstall Called from: src/static/js/pluginfw/installer.js Things in context: @@ -50,7 +51,7 @@ Things in context: If this hook returns an error, the callback to the install function gets an error, too. This seems useful for adding in features when a particular plugin is installed. -## `init_` +=== `init_` Called from: `src/static/js/pluginfw/plugins.js` @@ -61,12 +62,12 @@ Context properties: * `logger`: An object with the following `console`-like methods: `debug`, `info`, `log`, `warn`, `error`. -## `expressPreSession` +=== `expressPreSession` Called from: `src/node/hooks/express.js` Called during server startup just before the -[`express-session`](https://www.npmjs.com/package/express-session) middleware is +https://www.npmjs.com/package/express-session[`express-session`] middleware is added to the Express Application object. Use this hook to add route handlers or middleware that executes before `express-session` state is created and authentication is performed. This is useful for creating public endpoints that @@ -79,33 +80,34 @@ handler itself authenticates the user. Context properties: -* `app`: The Express [Application](https://expressjs.com/en/4x/api.html#app) +* `app`: The Express https://expressjs.com/en/4x/api.html==app[Application] object. Example: -```javascript +[source,javascript] +---- exports.expressPreSession = async (hookName, {app}) => { app.get('/hello-world', (req, res) => res.send('hello world')); }; -``` +---- -## `expressConfigure` +=== `expressConfigure` Called from: `src/node/hooks/express.js` Called during server startup just after the -[`express-session`](https://www.npmjs.com/package/express-session) middleware is +https://www.npmjs.com/package/express-session[`express-session`] middleware is added to the Express Application object. Use this hook to add route handlers or middleware that executes after `express-session` state is created and authentication is performed. Context properties: -* `app`: The Express [Application](https://expressjs.com/en/4x/api.html#app) +* `app`: The Express https://expressjs.com/en/4x/api.html==app[Application] object. -## `expressCreateServer` +=== `expressCreateServer` Called from: `src/node/hooks/express.js` @@ -114,12 +116,12 @@ other) except this hook's context includes the HTTP Server object. Context properties: -* `app`: The Express [Application](https://expressjs.com/en/4x/api.html#app) +* `app`: The Express https://expressjs.com/en/4x/api.html==app[Application] object. -* `server`: The [http.Server](https://nodejs.org/api/http.html#class-httpserver) - or [https.Server](https://nodejs.org/api/https.html#class-httpsserver) object. +* `server`: The https://nodejs.org/api/http.html==class-httpserver[http.Server] + or https://nodejs.org/api/https.html==class-httpsserver[https.Server] object. -## expressCloseServer +=== expressCloseServer Called from: src/node/hooks/express.js @@ -132,13 +134,14 @@ not already be closed when this hook executes. Example: -``` +[source, javascript] +---- exports.expressCloseServer = async () => { await doSomeCleanup(); }; -``` +---- -## eejsBlock_`` +=== eejsBlock_`` Called from: src/node/eejs/index.js Things in context: @@ -181,7 +184,7 @@ Available blocks in `pad.html` are: * `indexWrapper` - contains the form for creating new pads * `indexCustomScripts` - contains the `index.js` `