Skip to content

Commit

Permalink
Merge pull request #155 from TheNorthMemory/fix/apply-attrs-to-the-la…
Browse files Browse the repository at this point in the history
…st-column-of-tables

fix: apply attributes to the last column of tables
  • Loading branch information
arve0 authored Aug 11, 2024
2 parents a77066c + c4c4170 commit 22c7d3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ module.exports = options => {
const content = token.content;
const attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options);
let ii = i + 1;
while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; }
do if (tokens[ii] && tokens[ii].nesting === -1) { break; } while (ii++ < tokens.length);
const openingToken = utils.getMatchingOpeningToken(tokens, ii);
utils.addAttrs(attrs, openingToken);
const trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter));
Expand Down
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,34 @@ function describeTestsWithOptions(options, postText) {
assert.equal(md.render(replaceDelimiters(src, options)), expected);
});

it(replaceDelimiters('should apply attributes to the last column of tables', options), () => {
src = '| title | title {.title-primar} |\n';
src += '| :---: | :---: |\n';
src += '| text | text {.text-primar} |\n';
src += '| text {.text-primary} | text |\n';
src += '\n';
src += '{.c}';
expected = '<table class="c">\n';
expected += '<thead>\n';
expected += '<tr>\n';
expected += '<th style="text-align:center">title</th>\n';
expected += '<th style="text-align:center" class="title-primar">title</th>\n';
expected += '</tr>\n';
expected += '</thead>\n';
expected += '<tbody>\n';
expected += '<tr>\n';
expected += '<td style="text-align:center">text</td>\n';
expected += '<td style="text-align:center" class="text-primar">text</td>\n';
expected += '</tr>\n';
expected += '<tr>\n';
expected += '<td style="text-align:center" class="text-primary">text</td>\n';
expected += '<td style="text-align:center">text</td>\n';
expected += '</tr>\n';
expected += '</tbody>\n';
expected += '</table>\n';
assert.equal(md.render(replaceDelimiters(src, options)), expected);
});

it(replaceDelimiters('should support nested lists', options), () => {
src = '- item\n';
src += ' - nested\n';
Expand Down

0 comments on commit 22c7d3a

Please sign in to comment.