Skip to content

Commit

Permalink
Use colSpan and rowSpan (#399)
Browse files Browse the repository at this point in the history
* Use colSpan and rowSpan

Closes #302

* add marktest test too
  • Loading branch information
mfix-stripe committed Jun 2, 2023
1 parent 32c581c commit 43dc11c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions spec/marktest/tests.yaml
Expand Up @@ -717,7 +717,7 @@
* Test 1 - 3
---
* Test 2 - 1
* Test 2 - 2
* Test 2 - 2 {% colspan=2 %}
* Test 2 - 3
---
* Test 3 - 1
Expand Down Expand Up @@ -746,7 +746,9 @@
- tag: td
children: [Test 2 - 1]
- tag: td
children: [Test 2 - 2]
children: ['Test 2 - 2 ']
attributes:
colSpan: 2
- tag: td
children: [Test 2 - 3]
- tag: tr
Expand Down
7 changes: 7 additions & 0 deletions src/renderers/html.test.ts
Expand Up @@ -54,6 +54,13 @@ describe('HTML renderer', function () {
expect(html).toEqual('<p>1</p>');
});

it('lowercase attributes', function () {
const content = tag('td', { colSpan: 2, rowSpan: 3 }, ['Data']);

const html = render(content);
expect(html).toEqual('<td colspan="2" rowspan="3">Data</td>');
});

describe('attributes', function () {
it('with basic value', function () {
const example = tag('foo', { bar: 'baz' });
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/html.ts
Expand Up @@ -36,7 +36,7 @@ export default function render(node: RenderableTreeNodes): string {

let output = `<${name}`;
for (const [k, v] of Object.entries(attributes ?? {}))
output += ` ${k}="${escapeHtml(String(v))}"`;
output += ` ${k.toLowerCase()}="${escapeHtml(String(v))}"`;
output += '>';

if (voidElements.has(name)) return output;
Expand Down
4 changes: 2 additions & 2 deletions src/schema.ts
Expand Up @@ -136,8 +136,8 @@ export const td: Schema = {
'hr',
],
attributes: {
colspan: { type: Number },
rowspan: { type: Number },
colspan: { type: Number, render: 'colSpan' },
rowspan: { type: Number, render: 'rowSpan' },
align: { type: String },
},
};
Expand Down

0 comments on commit 43dc11c

Please sign in to comment.