Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply attributes to the last column of tables #155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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