Skip to content

Commit

Permalink
Omit first child elements (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
h-shams authored Aug 29, 2024
1 parent 6a7b5e5 commit 4dd22bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = function markdownItBidi(md) {
if (token.type === 'th_open' && prevToken.type === 'tr_open') {
return defaultRenderer(tokens, idx, opts, env, self);
}
// omit this token if this is the first child of an element
if (prevToken && rules.includes(prevToken.type) && token.level > prevToken.level) {
return defaultRenderer(tokens, idx, opts, env, self);
}
token.attrSet('dir', 'auto');
return defaultRenderer(tokens, idx, opts, env, self);
};
Expand Down
6 changes: 6 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ test('Add Bidi support to nested elements', () => {
md.render('1. item 1\n 1. item 2')
).toEqual('<ol dir="auto">\n<li>item 1\n<ol dir="auto">\n<li>item 2</li>\n</ol>\n</li>\n</ol>\n');
});

test('Omit dir=auto for first children of elements', () => {
expect(
md.render('> # Heading\n> Some text')
).toEqual('<blockquote dir="auto">\n<h1>Heading</h1>\n<p dir="auto">Some text</p>\n</blockquote>\n');
});

0 comments on commit 4dd22bc

Please sign in to comment.