name
The goal of this documentation is to comprehensively explain Etherpad-Lite, both from a reference as well as a conceptual point of view.
Where appropriate, property types, method arguments, and the arguments provided to event handlers are detailed in a list underneath the topic heading.
Every .html
file is generated based on the corresponding
.md
file in the doc/
folder in the source tree. The
documentation is generated using tools/doc/generate.js
.
The HTML template is located at doc/template.html
.
You can easily embed your etherpad-lite into any webpage by using iframes. You can configure the embedded pad using embed paramters.
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.
<iframe src='http://pad.test.de/p/PAD_NAME?showChat=false&showLineNumbers=false' width=600 height=400></iframe>
Default: true
Default: true
Default: true
Default: false
Default: "unnamed"
Example: userName=Etherpad%20User
Default: false
Default: false
The API gives another web application control of the pads. The basic functions are
The API is designed in a way, so you can reuse your existing user system with their permissions, and map it to etherpad lite. Means: Your web application still has to do authentication, but you can tell etherpad lite via the api, which visitors should get which permissions. This allows etherpad lite to fit into any web application and extend it with real-time functionality. You can embed the pads via an iframe into your website.
Take a look at HTTP API client libraries to see if a library in your favorite language.
A portal (such as WordPress) wants to give a user access to a new pad. Let's assume the user have the internal id 7 and his name is michael.
Portal maps the internal userid to an etherpad author.
Request:
http://pad.domain/api/1/createAuthorIfNotExistsFor?apikey=secret&name=Michael&authorMapper=7
Response:
{code: 0, message:"ok", data: {authorID: "a.s8oes9dhwrvt0zif"}}
Portal maps the internal userid to an etherpad group:
Request:
http://pad.domain/api/1/createGroupIfNotExistsFor?apikey=secret&groupMapper=7
Response:
{code: 0, message:"ok", data: {groupID: "g.s8oes9dhwrvt0zif"}}
Portal creates a pad in the userGroup
Request:
http://pad.domain/api/1/createGroupPad?apikey=secret&groupID=g.s8oes9dhwrvt0zif&padName=samplePad&text=This is the first sentence in the pad
Response:
{code: 0, message:"ok", data: null}
Portal starts the session for the user on the group:
Request:
http://pad.domain/api/1/createSession?apikey=secret&groupID=g.s8oes9dhwrvt0zif&authorID=a.s8oes9dhwrvt0zif&validUntil=1312201246
Response:
{"data":{"sessionID": "s.s8oes9dhwrvt0zif"}}
Portal places the cookie "sessionID" with the given value on the client and creates an iframe including the pad.
A portal (such as WordPress) wants to transform the contents of a pad that multiple admins edited into a blog post.
Portal retrieves the contents of the pad for entry into the db as a blog post:
Request:
http://pad.domain/api/1/getText?apikey=secret&padID=g.s8oes9dhwrvt0zif$123
Response:
{code: 0, message:"ok", data: {text:"Welcome Text"}}
Portal submits content into new blog post
Portal.AddNewBlog(content)
The API is accessible via HTTP. HTTP Requests are in the format /api/$APIVERSION/$FUNCTIONNAME. Parameters are transmitted via HTTP GET. $APIVERSION is 1
Responses are valid JSON in the following format:
{
"code": number,
"message": string,
"data": obj
}
Authentication works via a token that is sent with each request as a post parameter. There is a single token per Etherpad-Lite deployment. This token will be random string, generated by Etherpad-Lite at the first start. It will be saved in APIKEY.txt in the root folder of Etherpad Lite. Only Etherpad Lite and the requesting application knows this key. Token management will not be exposed through this API.
All functions will also be available through a node module accessable from other node.js applications.
The API provides JSONP support to allow requests from a server in a different domain.
Simply add &jsonp=?
to the API call.
Example usage: http://api.jquery.com/jQuery.getJSON/
Pads can belong to a group. The padID of grouppads is starting with a groupID like g.asdfasdfasdfasdf$test
{code: 0, message:"ok", data: {groupID: g.s8oes9dhwrvt0zif}}
{code: 0, message:"ok", data: {groupID: g.s8oes9dhwrvt0zif}}
{code: 0, message:"ok", data: null}
{code: 1, message:"groupID does not exist", data: null}
{code: 0, message:"ok", data: {padIDs : ["g.s8oes9dhwrvt0zif$test", "g.s8oes9dhwrvt0zif$test2"]}
{code: 1, message:"groupID does not exist", data: null}
{code: 0, message:"ok", data: null}
{code: 1, message:"pad does already exist", data: null}
{code: 1, message:"groupID does not exist", data: null}
{code: 0, message:"ok", data: {groupIDs: ["g.mKjkmnAbSMtCt8eL", "g.3ADWx6sbGuAiUmCy"]}}
{code: 0, message:"ok", data: {groupIDs: []}}
These authors are bound to the attributes the users choose (color and name).
{code: 0, message:"ok", data: {authorID: "a.s8oes9dhwrvt0zif"}}
{code: 0, message:"ok", data: {authorID: "a.s8oes9dhwrvt0zif"}}
{code: 0, message:"ok", data: {padIDs: ["g.s8oes9dhwrvt0zif$test", "g.s8oejklhwrvt0zif$foo"]}}
{code: 1, message:"authorID does not exist", data: null}
getAuthorName(authorID) Returns the Author Name of the author
Example returns:
{code: 0, message:"ok", data: {authorName: "John McLear"}}
can't be deleted cause this would involve scanning all the pads where this author was
Sessions can be created between a group and an author. This allows an author to access more than one group. The sessionID will be set as a cookie to the client and is valid until a certain date. The session cookie can also contain multiple comma-seperated sessionIDs, allowing a user to edit pads in different groups at the same time. Only users with a valid session for this group, can access group pads. You can create a session after you authenticated the user at your web application, to give them access to the pads. You should save the sessionID of this session and delete it after the user logged out.
{code: 0, message:"ok", data: {sessionID: "s.s8oes9dhwrvt0zif"}}
{code: 1, message:"groupID doesn't exist", data: null}
{code: 1, message:"authorID doesn't exist", data: null}
{code: 1, message:"validUntil is in the past", data: null}
{code: 1, message:"ok", data: null}
{code: 1, message:"sessionID does not exist", data: null}
{code: 0, message:"ok", data: {authorID: "a.s8oes9dhwrvt0zif", groupID: g.s8oes9dhwrvt0zif, validUntil: 1312201246}}
{code: 1, message:"sessionID does not exist", data: null}
{"code":0,"message":"ok","data":{"s.oxf2ras6lvhv2132":{"groupID":"g.s8oes9dhwrvt0zif","authorID":"a.akf8finncvomlqva","validUntil":2312905480}}}
{code: 1, message:"groupID does not exist", data: null}
{"code":0,"message":"ok","data":{"s.oxf2ras6lvhv2132":{"groupID":"g.s8oes9dhwrvt0zif","authorID":"a.akf8finncvomlqva","validUntil":2312905480}}}
{code: 1, message:"authorID does not exist", data: null}
Pad content can be updated and retrieved through the API
{code: 0, message:"ok", data: {text:"Welcome Text"}}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: null}
{code: 1, message:"padID does not exist", data: null}
{code: 1, message:"text too long", data: null}
{code: 0, message:"ok", data: {html:"Welcome Text<br>More Text"}}
{code: 1, message:"padID does not exist", data: null}
Group pads are normal pads, but with the name schema GROUPID$PADNAME. A security manager controls access of them and its forbidden for normal pads to include a $ in the name.
{code: 0, message:"ok", data: null}
{code: 1, message:"pad does already exist", data: null}
{code: 0, message:"ok", data: {revisions: 56}}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: {padUsersCount: 5}}
{code: 0, message:"ok", data: {padUsers: [{colorId:"#c1a9d9","name":"username1","timestamp":1345228793126},{"colorId":"#d9a9cd","name":"Hmmm","timestamp":1345228796042}]}}
{code: 0, message:"ok", data: {padUsers: []}}
{code: 0, message:"ok", data: null}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: {readOnlyID: "r.s8oes9dhwrvt0zif"}}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: null}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: {publicStatus: true}}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: null}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: {passwordProtection: true}}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: {authorIDs : ["a.s8oes9dhwrvt0zif", "a.akf8finncvomlqva"]}
{code: 1, message:"padID does not exist", data: null}
{code: 0, message:"ok", data: {lastEdited: 1340815946602}}
{code: 1, message:"padID does not exist", data: null}
msg
to the pad {code: 0, message:"ok", data: {}}
{code: 1, message:"padID does not exist", data: null}
All hooks are called with two arguments:
A hook should always return a list or undefined. Returning undefined is equivalent to returning an empty list.
All the returned lists are appended to each other, so if the return values where [1, 2]
, undefined
, [3, 4,]
, undefined
and [5]
, the value returned by callHook would be [1, 2, 3, 4, 5]
.
This is, because it should never matter if you have one plugin or several plugins doing some work - a single plugin should be able to make callHook return the same value a set of plugins are able to return collectively. So, any plugin can return a list of values, of any length, not just one value.
Most of these hooks are called during or in order to set up the formatting process.
Called from: src/templates/pad.html
Things in context:
nothing
This hook proxies the functionality of jQuery's $(document).ready
event.
Called from: src/static/js/domline.js
Things in context:
This hook is called for elements in the DOM that have the "lineMarkerAttribute" set. You can add elements into this category with the aceRegisterBlockElements hook above.
The return value of this hook should have the following structure:
{ preHtml: String, postHtml: String, processedMarker: Boolean }
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.
Called from: src/static/js/domline.js
Things in context:
This hook is called for any line being processed by the formatting engine, unless the aceDomLineProcessLineAttributes hook from above returned true, in which case this hook is skipped.
The return value of this hook should have the following structure:
{ extraOpenTags: String, extraCloseTags: String, cls: String }
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.
Called from: src/static/js/domline.js
Things in context:
This hook is for right after a node has been fully formatted and written to the page.
Called from: src/static/js/linestylefilter.js
Things in context:
This hook is called during the attribute processing procedure, and should be used to translate key, value pairs into valid HTML classes that can be inserted 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.
Called from: src/static/js/linestylefilter.js
Things in context:
This hook is called to apply custom regular expression filters to a set of styles. The one example available is the ep_linkify plugin, which adds internal 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).
Called from: src/static/js/ace.js
Things in context: None
This hook is provided to allow custom CSS files to be loaded. The return value should be an array of paths relative to the plugins directory.
Called from: src/static/js/ace.js
Things in context:
This hook is called during the creation of the editor HTML. The array should 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 <head>
element of the editor HTML document.
Called from: src/static/js/ace2_inner.js
Things in context:
This hook is made available to edit the edit events that might occur when 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.
Called from: src/static/js/ace2_inner.js
Things in context: None
The return value of this hook will add elements into the "lineMarkerAttribute" category, making the aceDomLineProcessLineAttributes hook (documented below) call for those elements.
Called from: src/static/js/ace2_inner.js
Things in context:
This hook is for inserting further information into the ace engine, for later use in formatting hooks.
Called from: src/static/js/pad.js
Things in context:
There doesn't appear to be any example available of this particular hook being used, but it gets fired after the editor is all set up.
Called from: src/static/js/pad_userlist.js
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.
Called from: src/static/js/contentcollector.js
Things in context:
This hook is called before 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.
Called from: src/static/js/contentcollector.js
Things in context:
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.
name
#Called from: src/static/js/collab_client.js
Things in context:
This hook gets called every time the client receives a message of type name
. This can most notably be used with the new HTTP API call, "sendClientsMessage", which sends a custom message type to all clients connected to a pad. You can 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.
Called from: src/static/js/ace2_inner.js
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]
Called from: src/static/js/ace2_inner.js
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.
Called from: src/static/js/contentcollector.js
Things in context:
This hook allows you to validate/manipulate the text before it's sent to the server side. The return value should be the validated/manipulated text.
Called from: src/static/js/contentcollector.js
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.
Called from: src/static/js/linestylefilter.js
Things in context:
This hook is provided to allow whether a given line should be deliniated with 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.
These hooks are called on server-side.
Called from: src/node/server.js
Things in context:
Use this hook to receive the global settings in your plugin.
Called from: src/static/js/pluginfw/installer.js
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!
Called from: src/static/js/pluginfw/installer.js
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.
<plugin name>
#Called from: src/static/js/pluginfw/plugins.js
Things in context: None
This function is called after a specific plugin is initialized. This would probably be more useful than the previous two functions if you only wanted to add in features to one specific plugin.
Called from: src/node/server.js
Things in context:
This is a helpful hook for changing the behavior and configuration of the application. It's called right after the application gets configured.
Called from: src/node/server.js
Things in context:
This hook gets called after the application object has been created, but before it starts listening. This is similar to the expressConfigure hook, but it's not guaranteed that the application object will have all relevant configuration variables.
<name>
#Called from: src/node/eejs/index.js
Things in context:
This hook gets called upon the rendering of an ejs template block. For any specific kind of block, you can change how that block gets rendered by modifying the content object passed in.
Have a look at src/templates/pad.html
and src/templates/timeslider.html
to see which blocks are available.
Called from: src/node/hooks/express/socketio.js
Things in context:
I have no idea what this is useful for, someone else will have to add this description.
Called from: src/node/hooks/express/webaccess.js
Things in context:
This is useful for modifying the way authentication is done, especially for specific paths.
Called from: src/node/hooks/express/webaccess.js
Things in context:
This is useful for modifying the way authentication is done.
Called from: src/node/hooks/express/webaccess.js
Things in context:
This is useful for modifying the way authentication is done.
Called from: src/node/handler/PadMessageHandler.js
Things in context:
This hook will be called once a message arrive. If a plugin calls callback(null)
the message will be dropped. However it is not possible to modify the message.
Plugins may also decide to implement custom behavior once a message arrives.
WARNING: handleMessage will be called, even if the client is not authorized to send this message. It's up to the plugin to check permissions.
Example:
function handleMessage ( hook, context, callback ) {
if ( context.message.type == 'USERINFO_UPDATE' ) {
// If the message type is USERINFO_UPDATE, drop the message
callback(null);
}else{
callback();
}
};
Called from: src/node/utils/ExportHtml.js
Things in context:
This hook will allow a plug-in developer to re-write each line when exporting to HTML.
This function replaces a range (from start
to end
) with text
.
Returns the rep
object.
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.
This function replaces a range (from [x1,y1] to [x2,y2]) with newText
.
This function replaces a range (from y1 to y2) with newText
.
If you delete a line, calling this method will fix the line numbering.
Forces a return key at the current carret position.
Returns true if your passed elment is registered as a block element
Returns the line's html list type.
Returns X position of the caret.
Returns Y position of the caret.
Returns the Y offset starting from [x=0,y=0]
"Z:z>1|2=m=b*0|1+1$\n"
This is a Changeset. Its just a string and its very difficult to read in this form. But the Changeset Library gives us some tools to read it.
A changeset describes the diff between two revisions of the document. The Browser sends changesets to the server and the server sends them to the clients to update them. This Changesets gets also saved into the history of a pad. Which allows us to go back to every revision from the past.
changeset
StringThis functions returns an object representaion of the changeset, similar to this:
{ oldLen: 35, newLen: 36, ops: '|2=m=b*0|1+1', charBank: '\n' }
oldLen
{Number} the original length of the document.newLen
{Number} the length of the document after the changeset is applied.ops
{String} the actual changes, introduced by this changeset.charBank
{String} All characters that are added by this changeset.ops
String The operators, returned by Changeset.unpack()
Returns an operator iterator. This iterator allows us to iterate over all operators that are in the changeset.
You can iterate with an opIterator using its next()
and hasNext()
methods. Next returns the next()
operator object and hasNext()
indicates, whether there are any operators left.
There are 3 types of operators: +
,-
and =
. These operators describe different changes to the document, beginning with the first character of the document. A =
operator doesn't change the text, but it may add or remove text attributes. A -
operator removes text. And a +
Operator adds text and optionally adds some attributes to it.
opcode
{String} the operator typechars
{Number} the length of the text changed by this operator.lines
{Number} the number of lines changed by this operator.attribs
{attribs} attributes set on this text.{ opcode: '+',
chars: 1,
lines: 1,
attribs: '*0' }
> var AttributePoolFactory = require("./utils/AttributePoolFactory");
> var apool = AttributePoolFactory.createAttributePool();
> console.log(apool)
{ numToAttrib: {},
attribToNum: {},
nextNum: 0,
putAttrib: [Function],
getAttrib: [Function],
getAttribKey: [Function],
getAttribValue: [Function],
eachAttrib: [Function],
toJsonable: [Function],
fromJsonable: [Function] }
This creates an empty apool. A apool saves which attributes were used during the history of a pad. There is one apool for each pad. It only saves the attributes that were really used, it doesn't save unused attributes. Lets fill this apool with some values
> apool.fromJsonable({"numToAttrib":{"0":["author","a.kVnWeomPADAT2pn9"],"1":["bold","true"],"2":["italic","true"]},"nextNum":3});
> console.log(apool)
{ numToAttrib:
{ '0': [ 'author', 'a.kVnWeomPADAT2pn9' ],
'1': [ 'bold', 'true' ],
'2': [ 'italic', 'true' ] },
attribToNum:
{ 'author,a.kVnWeomPADAT2pn9': 0,
'bold,true': 1,
'italic,true': 2 },
nextNum: 3,
putAttrib: [Function],
getAttrib: [Function],
getAttribKey: [Function],
getAttribValue: [Function],
eachAttrib: [Function],
toJsonable: [Function],
fromJsonable: [Function] }
We used the fromJsonable function to fill the empty apool with values. the fromJsonable and toJsonable functions are used to serialize and deserialize an apool. You can see that it stores the relation between numbers and attributes. So for example the attribute 1 is the attribute bold and vise versa. A attribute is always a key value pair. For stuff like bold and italic its just 'italic':'true'. For authors its author:$AUTHORID. So a character can be bold and italic. But it can't belong to multiple authors
> apool.getAttrib(1)
[ 'bold', 'true' ]
Simple example of how to get the key value pair for the attribute 1
> var atext = {"text":"bold text\nitalic text\nnormal text\n\n","attribs":"*0*1+9*0|1+1*0*1*2+b|1+1*0+b|2+2"};
> console.log(atext)
{ text: 'bold text\nitalic text\nnormal text\n\n',
attribs: '*0*1+9*0|1+1*0*1*2+b|1+1*0+b|2+2' }
This is an atext. An atext has two parts: text and attribs. The text is just the text of the pad as a string. We will look closer at the attribs at the next steps
> var opiterator = Changeset.opIterator(atext.attribs)
> console.log(opiterator)
{ next: [Function: next],
hasNext: [Function: hasNext],
lastIndex: [Function: lastIndex] }
> opiterator.next()
{ opcode: '+',
chars: 9,
lines: 0,
attribs: '*0*1' }
> opiterator.next()
{ opcode: '+',
chars: 1,
lines: 1,
attribs: '*0' }
> opiterator.next()
{ opcode: '+',
chars: 11,
lines: 0,
attribs: '*0*1*2' }
> opiterator.next()
{ opcode: '+',
chars: 1,
lines: 1,
attribs: '' }
> opiterator.next()
{ opcode: '+',
chars: 11,
lines: 0,
attribs: '*0' }
> opiterator.next()
{ opcode: '+',
chars: 2,
lines: 2,
attribs: '' }
The attribs are again a bunch of operators like .ops in the changeset was. But these operators are only + operators. They describe which part of the text has which attributes
For more information see /doc/easysync/easysync-notes.txt in the source.
A list of all existing groups (a JSON object with groupIDs as keys and 1
as values).
Saves all informations about pads
Saves a revision $REVNUM of pad $PADID
Saves a chatentry with num $CHATNUM of pad $PADID
Translates a padID to a readonlyID
Translates a readonlyID to a padID
Translates a token to an authorID
Information about an author
Maps an external application identifier to an internal group
Maps an external application identifier to an internal author
a group of pads
saves the sessions of an author