Skip to content

Commit d3fdad9

Browse files
authored
feat: register heading tags as server-side block elements (#173)
ep_headings2 already registers h1-h4 + code as block elements in the editor (aceRegisterBlockElements). It did NOT register them on the server-side content collector (ccRegisterBlockElements), so any HTML import path treated those tags as inline -- and adjacent <h1>/<h2>/<code> blocks merged into a single pad line. Fix: re-export the new ccRegisterBlockElements function from ep_plugin_helpers' lineAttribute factory (added in ether/ep_plugin_helpers#14) and wire it up via ep.json. This treats h1-h4 + code as block elements on the import side too, matching their editor behavior. Bumps the ep_plugin_helpers minimum to ^0.5.2 (the version with the new export). Test added covers the regression: a pad with adjacent <h1> and <h2> (no separator) survives a setHTML/getHTML round-trip with each heading on its own line and no merged 'AlphaBeta' content. Refs ether/etherpad#7568 -- this is the missing piece for the DOCX/HTML round-trip story landing in core.
1 parent c2f470e commit d3fdad9

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

ep.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"eejsBlock_editbarMenuLeft": "ep_headings2/index",
1717
"collectContentPre": "ep_headings2/static/js/shared",
1818
"collectContentPost": "ep_headings2/static/js/shared",
19+
"ccRegisterBlockElements": "ep_headings2/static/js/shared",
1920
"getLineHTMLForExport": "ep_headings2/index",
2021
"stylesForExport" : "ep_headings2/index"
2122
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"url": "https://github.com/ether/ep_headings2/issues"
3535
},
3636
"dependencies": {
37-
"ep_plugin_helpers": "^0.3.2"
37+
"ep_plugin_helpers": "^0.5.2"
3838
},
3939
"devDependencies": {
4040
"eslint": "^8.57.1",

static/js/shared.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ const headings = lineAttribute({attr: 'heading', tags});
88

99
exports.collectContentPre = headings.collectContentPre;
1010
exports.collectContentPost = headings.collectContentPost;
11+
exports.ccRegisterBlockElements = headings.ccRegisterBlockElements;

static/tests/backend/specs/exportHTML.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,35 @@ describe('ep_headings2 - export headings to HTML', function () {
121121
}
122122
});
123123
});
124+
125+
context('when pad has adjacent <h1> and <h2> with no separator', function () {
126+
// Regression for ether/etherpad#7568 round-trip. Without server-side
127+
// ccRegisterBlockElements registered for the heading tags,
128+
// contentcollector treats <h1>/<h2> as inline and adjacent ones
129+
// merge into a single pad line.
130+
before(async function () {
131+
html = () => buildHTML('<h1>Alpha</h1><h2>Beta</h2>');
132+
});
133+
134+
it('keeps each heading on its own line', function (done) {
135+
const expected = /<h1>\s*Alpha\s*<\/h1>[\s\S]*<h2>\s*Beta\s*<\/h2>/;
136+
generateJWTToken().then((token) => {
137+
agent.get(getHTMLEndPointFor(padID))
138+
.set('Authorization', token)
139+
.end((err, res) => {
140+
if (err) return done(err);
141+
const out = res.body.data.html;
142+
if (out.search(expected) === -1) {
143+
return done(new Error(
144+
`Adjacent headings merged or missing in: ${out}`));
145+
}
146+
if (out.search(/AlphaBeta/) !== -1) {
147+
return done(new Error(
148+
`Headings merged into one line: ${out}`));
149+
}
150+
done();
151+
});
152+
}).catch(done);
153+
});
154+
});
124155
});

0 commit comments

Comments
 (0)