docs: Improve `getLineHTMLForExport` server-side hook docs

pull/5288/head
Richard Hansen 2021-11-18 20:52:23 -05:00
parent 93abc31936
commit cdad5c3325
1 changed files with 23 additions and 26 deletions

View File

@ -646,39 +646,36 @@ exports.clientVars = (hookName, context, callback) => {
}; };
``` ```
## getLineHTMLForExport ## `getLineHTMLForExport`
Called from: src/node/utils/ExportHtml.js
Things in context: Called from: `src/node/utils/ExportHtml.js`
1. apool - pool object This hook will allow a plug-in developer to re-write each line when exporting to
2. attribLine - line attributes HTML.
3. text - line text
This hook will allow a plug-in developer to re-write each line when exporting to HTML. Context properties:
* `apool`: Pool object.
* `attribLine`: Line attributes.
* `line`:
* `lineContent`:
* `text`: Line text.
* `padId`: Writable (not read-only) pad identifier.
Example: Example:
```
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
exports.getLineHTMLForExport = function (hook, context) { ```javascript
var header = _analyzeLine(context.attribLine, context.apool); const Changeset = require('ep_etherpad-lite/static/js/Changeset');
if (header) {
return "<" + header + ">" + context.lineContent + "</" + header + ">";
}
}
function _analyzeLine(alineAttrs, apool) { exports.getLineHTMLForExport = async (hookName, context) => {
var header = null; if (!context.attribLine) return;
if (alineAttrs) { const opIter = Changeset.opIterator(context.attribLine);
var opIter = Changeset.opIterator(alineAttrs); if (!opIter.hasNext()) return;
if (opIter.hasNext()) { const op = opIter.next();
var op = opIter.next(); const heading = Changeset.opAttributeValue(op, 'heading', apool);
header = Changeset.opAttributeValue(op, 'heading', apool); if (!heading) return;
} context.lineContent = `<${heading}>${context.lineContent}</${heading}>`;
} };
return header;
}
``` ```
## exportHTMLAdditionalContent ## exportHTMLAdditionalContent