Skip to content

Commit e5eeefc

Browse files
committed
fix(json-crdt-peritext-ui): 🐛 allow string type tag names
1 parent 45a76b9 commit e5eeefc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/json-crdt-extensions/peritext/events/__tests__/marker.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,29 @@ const testSuite = (getKit: () => Kit) => {
203203
'<p>abcdefgh</p><blockquote data-attr=\'{"author":"Pierre Gringoire","source":"Journal of Hunchbacks"}\'>ijklmnopqrstuvwxyz</blockquote>',
204204
);
205205
});
206+
207+
test('can update the correct tag data', () => {
208+
const kit = setup();
209+
kit.et.cursor({at: [8]});
210+
kit.et.marker({action: 'ins', type: [['ul', 0, {type: 'tasks'}], ['li', 0 , {done: false}]]});
211+
expect(kit.toHtml()).toBe('<p>abcdefgh</p><ul data-attr=\'{"type":"tasks"}\'><li data-attr=\'{"done":false}\'>ijklmnopqrstuvwxyz</li></ul>');
212+
kit.et.marker({
213+
action: 'upd',
214+
target: ['data', 0],
215+
ops: [
216+
['add', '/type', 'ordered'],
217+
],
218+
});
219+
expect(kit.toHtml()).toBe('<p>abcdefgh</p><ul data-attr=\'{"type":"ordered"}\'><li data-attr=\'{"done":false}\'>ijklmnopqrstuvwxyz</li></ul>');
220+
kit.et.marker({
221+
action: 'upd',
222+
target: ['data', 1],
223+
ops: [
224+
['replace', '/done', true],
225+
],
226+
});
227+
expect(kit.toHtml()).toBe('<p>abcdefgh</p><ul data-attr=\'{"type":"ordered"}\'><li data-attr=\'{"done":true}\'>ijklmnopqrstuvwxyz</li></ul>');
228+
});
206229
});
207230
});
208231

src/json-crdt-extensions/peritext/transfer/export-html.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import type {ViewStyle, ViewRange} from '../editor/types';
1010
export const toJsonMl = (json: PeritextMlNode): JsonMlNode => {
1111
if (typeof json === 'string') return json;
1212
const [tag, attr, ...children] = json;
13-
const namedTag = tag === '' ? tag : SliceTypeName[tag as any];
13+
let namedTag = tag === '' ? tag : SliceTypeName[tag as any];
14+
if (typeof namedTag !== 'string') namedTag = tag + '';
1415
const htmlTag = namedTag ?? (attr?.inline ? 'span' : 'div');
1516
const htmlAttr = attr && attr.data !== void 0 ? {'data-attr': JSON.stringify(attr.data)} : null;
1617
const htmlNode: JsonMlNode = [htmlTag, htmlAttr];

0 commit comments

Comments
 (0)