Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ const createLineAttribute = (config) => {

const aceRegisterBlockElements = () => tags;

// Server-side counterpart of aceRegisterBlockElements. Etherpad core's
// import-side content collector keeps its own `_blockElems` set
// separate from the editor's, so plugins that want their custom block
// tags treated as block elements on import (so adjacent ones don't
// merge into a single pad line) need to register them on the server
// side too. A plugin that uses `lineAttribute({tags: [...]})` should
// re-export this hook from its `ep.json` under
// `"ccRegisterBlockElements"`.
const ccRegisterBlockElements = () => tags;

const collectContentPre = (hookName, context, cb) => {
const tname = context.tname;
const lineAttributes = context.state.lineAttributes;
Expand Down Expand Up @@ -60,6 +70,7 @@ const createLineAttribute = (config) => {
aceDomLineProcessLineAttributes,
aceRegisterBlockElements,
aceRegisterLineAttributes,
ccRegisterBlockElements,
collectContentPre,
collectContentPost,
};
Expand Down Expand Up @@ -122,6 +133,16 @@ const createTagAttribute = (config) => {

const aceRegisterBlockElements = () => tags;

// Server-side counterpart of aceRegisterBlockElements. Etherpad core's
// import-side content collector keeps its own `_blockElems` set
// separate from the editor's, so plugins that want their custom block
// tags treated as block elements on import (so adjacent ones don't
// merge into a single pad line) need to register them on the server
// side too. A plugin that uses `lineAttribute({tags: [...]})` should
// re-export this hook from its `ep.json` under
// `"ccRegisterBlockElements"`.
const ccRegisterBlockElements = () => tags;

const collectContentPre = (hookName, context, cb) => {
const tname = context.tname;
if (tags.includes(tname)) {
Expand All @@ -138,6 +159,7 @@ const createTagAttribute = (config) => {
aceAttribClasses,
aceAttribsToClasses,
aceRegisterBlockElements,
ccRegisterBlockElements,
collectContentPre,
collectContentPost,
};
Expand Down
17 changes: 17 additions & 0 deletions test/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ describe('lineAttribute', () => {
});
});

describe('ccRegisterBlockElements', () => {
it('returns the tags array (server-side counterpart)', () => {
assert.deepStrictEqual(headings.ccRegisterBlockElements(), tags);
});

it('is exposed alongside aceRegisterBlockElements', () => {
assert.strictEqual(typeof headings.ccRegisterBlockElements, 'function');
assert.strictEqual(typeof headings.aceRegisterBlockElements, 'function');
});
});

describe('collectContentPre', () => {
it('sets line attribute for matching tag', () => {
const state = {lineAttributes: {}};
Expand Down Expand Up @@ -198,6 +209,12 @@ describe('tagAttribute', () => {
});
});

describe('ccRegisterBlockElements', () => {
it('returns the tags array (server-side)', () => {
assert.deepStrictEqual(subSup.ccRegisterBlockElements(), ['sub', 'sup']);
});
});

describe('collectContentPre', () => {
it('calls doAttrib for matching tag', () => {
let called = null;
Expand Down