Skip to content

Commit

Permalink
fix(attributes): handle attribute of elements in tableCell
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Mar 8, 2024
1 parent c7fa71b commit 65def9b
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/from-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ export default (opts: RemarkMDCOptions = {}) => {
stackTop = stackTop.children[stackTop.children.length - 1]
}

if (stackTop.type === 'tableCell') {
stackTop = stackTop.children[stackTop.children.length - 1]
}

(stackTop as any).attributes = cleaned
}

Expand Down
229 changes: 229 additions & 0 deletions test/__snapshots__/attributes.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,235 @@ exports[`Attributes > link 1`] = `
}
`;

exports[`Attributes > nested-in-table 1`] = `
{
"children": [
{
"align": [
null,
null,
],
"children": [
{
"children": [
{
"children": [
{
"position": {
"end": {
"column": 7,
"line": 1,
"offset": 6,
},
"start": {
"column": 3,
"line": 1,
"offset": 2,
},
},
"type": "text",
"value": "Col1",
},
],
"position": {
"end": {
"column": 8,
"line": 1,
"offset": 7,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "tableCell",
},
{
"children": [
{
"position": {
"end": {
"column": 19,
"line": 1,
"offset": 18,
},
"start": {
"column": 15,
"line": 1,
"offset": 14,
},
},
"type": "text",
"value": "Col2",
},
],
"position": {
"end": {
"column": 26,
"line": 1,
"offset": 25,
},
"start": {
"column": 8,
"line": 1,
"offset": 7,
},
},
"type": "tableCell",
},
],
"position": {
"end": {
"column": 26,
"line": 1,
"offset": 25,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "tableRow",
},
{
"children": [
{
"children": [
{
"position": {
"end": {
"column": 6,
"line": 3,
"offset": 57,
},
"start": {
"column": 4,
"line": 3,
"offset": 55,
},
},
"type": "text",
"value": "aa",
},
],
"position": {
"end": {
"column": 8,
"line": 3,
"offset": 59,
},
"start": {
"column": 1,
"line": 3,
"offset": 52,
},
},
"type": "tableCell",
},
{
"children": [
{
"attributes": {
"a": "a",
},
"children": [
{
"position": {
"end": {
"column": 12,
"line": 3,
"offset": 63,
},
"start": {
"column": 11,
"line": 3,
"offset": 62,
},
},
"type": "text",
"value": "a",
},
],
"position": {
"end": {
"column": 17,
"line": 3,
"offset": 68,
},
"start": {
"column": 10,
"line": 3,
"offset": 61,
},
},
"title": null,
"type": "link",
"url": "/a",
},
],
"position": {
"end": {
"column": 26,
"line": 3,
"offset": 77,
},
"start": {
"column": 8,
"line": 3,
"offset": 59,
},
},
"type": "tableCell",
},
],
"position": {
"end": {
"column": 26,
"line": 3,
"offset": 77,
},
"start": {
"column": 1,
"line": 3,
"offset": 52,
},
},
"type": "tableRow",
},
],
"position": {
"end": {
"column": 26,
"line": 3,
"offset": 77,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "table",
},
],
"position": {
"end": {
"column": 26,
"line": 3,
"offset": 77,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
}
`;

exports[`Attributes > strong 1`] = `
{
"children": [
Expand Down
12 changes: 12 additions & 0 deletions test/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ describe('Attributes', () => {
},
emphasis: {
markdown: '_emphasis_{#id .class}'
},
'nested-in-table': {
markdown: [
'| Col1 | Col2 |',
'| -- | ----- |',
'| aa | [a](/a){a="a"} |'
].join('\n'),
expected: [
'| Col1 | Col2 |',
'| ---- | -------------- |',
'| aa | [a](/a){a="a"} |'
].join('\n')
}
})
})

0 comments on commit 65def9b

Please sign in to comment.