Skip to content

Commit

Permalink
Add additional class to td with a tag inside
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed Jul 6, 2021
1 parent c6732bc commit 19e3876
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm test
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For detailed information check [Blogophon's releases on Github](https://github.c
* 🎁 Add Spotify embedding
* 🎁 JSON-LD added
* 🎁 Changed code highlighting for Bash prompt
* 🎁 Add additional `class` to `td` with a tag inside

2.1.7
-----
Expand Down
1 change: 1 addition & 0 deletions lib/helpers/marky-mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ const markyMark = function(string, rules) {
})
.replace(/(<tr>\s*<)td([^>]+?text-align:\s?left.+?<\/)td(>)/g, '$1th scope="row"$2th$3')
//.replace(/(<tr>[\s\S]+?)(<\/tbody>)/g, '$2<tfoot>$1</tfoot>')
.replace(/(<td[^>]*)(>\s*<)([^>]+)(>[^<]+<\/\3>\s*<\/td>)/g, '$1 class="tag-$3"$2$3$4')
.replace(/(<(th|td))(.+?)\s+([²³⁴⁵⁶⁷⁸⁹])(<\/\2>)/g, (all, before, tag, content, index, after) => {
let colspan = index.charCodeAt(0);
colspan -= (colspan > 8000) ? 8304 : 176;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"gulp-sass": "^5.0.0",
"gulp-stylelint": "^13.0.0",
"gulp-uglify": "^3.0.2",
"husky": "^6.0.0",
"husky": "^7.0.0",
"mocha": "^9.0.1",
"stylelint": "^13.11.0",
"stylelint-config-recommended-scss": "^4.2.0",
Expand Down
16 changes: 13 additions & 3 deletions test/marky-mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,24 @@ describe('MarkyMark', function() {
<td style="text-align:right"></td>
<td style="text-align:left">Das bist du und so ⁴</td>
</tr>
<tr>
<td style="text-align:left"><strong>Das bist du und so</strong></td>
<td style="text-align:left"><em>Das bist du und so</em></td>
<td style="text-align:right"><strong>Test</strong></td>
<td style="text-align:left"><a>Das bist du und so</a></td>
</tr>
</tbody>
</table>`;

let m = markyMark(x);
assert.ok(m, 'Got output');
assert.equal(m.match(/colspan="\d"/g).length, 1, 'Colspan added');
assert.equal(m.match(/<col class="table-cell--right"/g).length, 1);
assert.equal(m.match(/<col class="table-cell--left"/g).length, 1);
assert.strictEqual(m.match(/colspan="\d"/g).length, 1, 'Colspan added');
assert.strictEqual(m.match(/<col class="table-cell--right"/g).length, 1);
assert.strictEqual(m.match(/<col class="table-cell--left"/g).length, 1);
assert.strictEqual(m.match(/class="tag-strong"/g).length, 1);
assert.strictEqual(m.match(/class="tag-em"/g).length, 1);
assert.strictEqual(m.match(/class="tag-a"/g).length, 1);
assert.strictEqual(m.match(/<th/g).length, 5);
});
});

Expand Down

0 comments on commit 19e3876

Please sign in to comment.