mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-25 07:06:08 +00:00
Add start/end properties for table row/cell elements (#8494)
* Add test for existing table parsing functionality * Add expected start/end for tr elements in table wikitext test * Populate start/end properties for tr elements * Add expected start/end for th/td elements in table wikitext test * Populate start/end properties for th/td elements
This commit is contained in:
@@ -324,6 +324,100 @@ describe("WikiText parser tests", function() {
|
||||
|
||||
});
|
||||
|
||||
it("should parse tables", function() {
|
||||
let wikitext = `
|
||||
|!Cell1 |!Cell2 |
|
||||
|Cell3 |Cell4 |`.trim();
|
||||
|
||||
let expectedParseTree = [{
|
||||
type: 'element',
|
||||
tag: 'table',
|
||||
start: 0,
|
||||
end: 33,
|
||||
rule: 'table',
|
||||
children: [{
|
||||
type: 'element',
|
||||
tag: 'tbody',
|
||||
start: 0,
|
||||
end: 33,
|
||||
children: [{
|
||||
type: 'element',
|
||||
tag: 'tr',
|
||||
attributes: {
|
||||
'class': { name: 'class', type: 'string', value: 'evenRow' },
|
||||
},
|
||||
orderedAttributes: [
|
||||
{ name: 'class', type: 'string', value: 'evenRow' },
|
||||
],
|
||||
start: 0,
|
||||
end: 18,
|
||||
children: [{
|
||||
type: 'element',
|
||||
tag: 'th',
|
||||
attributes: {
|
||||
'align': { name: 'align', type: 'string', value: 'left' },
|
||||
},
|
||||
orderedAttributes: [
|
||||
{ name: 'align', type: 'string', value: 'left' },
|
||||
],
|
||||
start: 1,
|
||||
end: 8,
|
||||
children: [{type: 'text', text: 'Cell1', start: 2, end: 7}],
|
||||
}, {
|
||||
type: 'element',
|
||||
tag: 'th',
|
||||
attributes: {
|
||||
'align': { name: 'align', type: 'string', value: 'left' },
|
||||
},
|
||||
orderedAttributes: [
|
||||
{ name: 'align', type: 'string', value: 'left' },
|
||||
],
|
||||
start: 9,
|
||||
end: 16,
|
||||
children: [{type: 'text', text: 'Cell2', start: 10, end: 15}],
|
||||
}],
|
||||
}, {
|
||||
type: 'element',
|
||||
tag: 'tr',
|
||||
attributes: {
|
||||
'class': { name: 'class', type: 'string', value: 'oddRow' },
|
||||
},
|
||||
orderedAttributes: [
|
||||
{ name: 'class', type: 'string', value: 'oddRow' },
|
||||
],
|
||||
start: 18,
|
||||
end: 33,
|
||||
children: [{
|
||||
type: 'element',
|
||||
tag: 'td',
|
||||
attributes: {
|
||||
'align': { name: 'align', type: 'string', value: 'left' },
|
||||
},
|
||||
orderedAttributes: [
|
||||
{ name: 'align', type: 'string', value: 'left' },
|
||||
],
|
||||
start: 19,
|
||||
end: 25,
|
||||
children: [{type: 'text', text: 'Cell3', start: 19, end: 24}],
|
||||
}, {
|
||||
type: 'element',
|
||||
tag: 'td',
|
||||
attributes: {
|
||||
'align': { name: 'align', type: 'string', value: 'left' },
|
||||
},
|
||||
orderedAttributes: [
|
||||
{ name: 'align', type: 'string', value: 'left' },
|
||||
],
|
||||
start: 26,
|
||||
end: 32,
|
||||
children: [{type: 'text', text: 'Cell4', start: 26, end: 31}],
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
}];
|
||||
|
||||
expect(parse(wikitext)).toEqual(expectedParseTree);
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user