mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
Pad: Convert line endings in text from padDefaultContent
hook
This commit is contained in:
parent
cd43625be8
commit
b733ed9ab0
2 changed files with 14 additions and 7 deletions
|
@ -387,15 +387,10 @@ Pad.prototype.init = async function (text, authorId = '') {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
const context = {
|
const context = {pad: this, authorId, type: 'text', content: settings.defaultPadText};
|
||||||
pad: this,
|
|
||||||
authorId,
|
|
||||||
type: 'text',
|
|
||||||
content: exports.cleanText(settings.defaultPadText),
|
|
||||||
};
|
|
||||||
await hooks.aCallAll('padDefaultContent', context);
|
await hooks.aCallAll('padDefaultContent', context);
|
||||||
if (context.type !== 'text') throw new Error(`unsupported content type: ${context.type}`);
|
if (context.type !== 'text') throw new Error(`unsupported content type: ${context.type}`);
|
||||||
text = context.content;
|
text = exports.cleanText(context.content);
|
||||||
}
|
}
|
||||||
const firstChangeset = Changeset.makeSplice('\n', 0, 0, text);
|
const firstChangeset = Changeset.makeSplice('\n', 0, 0, text);
|
||||||
await this.appendRevision(firstChangeset, authorId);
|
await this.appendRevision(firstChangeset, authorId);
|
||||||
|
|
|
@ -118,5 +118,17 @@ describe(__filename, function () {
|
||||||
pad = await padManager.getPad(padId);
|
pad = await padManager.getPad(padId);
|
||||||
assert.equal(pad.text(), `${want}\n`);
|
assert.equal(pad.text(), `${want}\n`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('cleans provided content', async function () {
|
||||||
|
const input = 'foo\r\nbar\r\tbaz';
|
||||||
|
const want = 'foo\nbar\n baz';
|
||||||
|
assert.notEqual(want, settings.defaultPadText);
|
||||||
|
plugins.hooks.padDefaultContent.push({hook_fn: async (hookName, ctx) => {
|
||||||
|
ctx.type = 'text';
|
||||||
|
ctx.content = input;
|
||||||
|
}});
|
||||||
|
pad = await padManager.getPad(padId);
|
||||||
|
assert.equal(pad.text(), `${want}\n`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue