mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 09:26:14 -04:00
contentcollector: Fix collectContentLineText hook
Before, the hook always ignored the return values provided by the hook functions. Now the hook functions can change the text by either returning a string or setting `context.text` to the desired value. Also drop the `styl` and `cls` context properties. They were never documented and they were always null.
This commit is contained in:
parent
4e220538a1
commit
e3a47e48f9
2 changed files with 21 additions and 18 deletions
|
@ -338,24 +338,14 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
|
|||
_reachBlockPoint(node, 0, state);
|
||||
|
||||
if (dom.isTextNode(node)) {
|
||||
let txt = dom.nodeValue(node);
|
||||
const tname = dom.getAttribute(node.parentNode, 'name');
|
||||
|
||||
const txtFromHook = hooks.callAll('collectContentLineText', {
|
||||
cc: this,
|
||||
state,
|
||||
tname,
|
||||
node,
|
||||
text: txt,
|
||||
styl: null,
|
||||
cls: null,
|
||||
});
|
||||
|
||||
if (typeof (txtFromHook) === 'object') {
|
||||
txt = dom.nodeValue(node);
|
||||
} else if (txtFromHook) {
|
||||
txt = txtFromHook;
|
||||
}
|
||||
const context = {cc: this, state, tname, node, text: dom.nodeValue(node)};
|
||||
// Hook functions may either return a string (deprecated) or modify context.text. If any hook
|
||||
// function modifies context.text then all returned strings are ignored. If no hook functions
|
||||
// modify context.text, the first hook function to return a string wins.
|
||||
const [hookTxt] =
|
||||
hooks.callAll('collectContentLineText', context).filter((s) => typeof s === 'string');
|
||||
let txt = context.text === dom.nodeValue(node) && hookTxt != null ? hookTxt : context.text;
|
||||
|
||||
let rest = '';
|
||||
let x = 0; // offset into original text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue