Skip to content

Commit

Permalink
test: check detached anchor for conflicts with anchors plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
main-kun authored and moki committed Nov 30, 2023
1 parent de87eca commit 7712685
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/detached-anchor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import transform from '../src/transform';
import plugin from '../src/transform/plugins/detached-anchor';
import anchorsPlugin from '../src/transform/plugins/anchors';

const transformYfm = (text: string) => {
let transformYfm = (text: string) => {
const {
result: {html},
} = transform(text, {
Expand All @@ -16,10 +17,19 @@ describe('detached-anchor', function () {
expect(transformYfm('{#my-anchor}')).toBe('<a id="my-anchor"></a>');
});
});
describe('with heading', () => {
describe('with heading anchors', () => {
transformYfm = (text) => {
const {
result: {html},
} = transform(text, {plugins: [plugin, anchorsPlugin]});
return html;
};
it('does not conflict with heading anchors', () => {
expect(transformYfm('# Heading {#heading-anchor} \n {#my-anchor}')).toBe(
'<h1 id="heading-anchor">Heading</h1>\n<a id="my-anchor"></a>',
'<h1 id="heading-anchor">' +
'<a href="#heading-anchor" class="yfm-anchor" aria-hidden="true">' +
'<span class="visually-hidden">Heading</span></a>Heading</h1>\n' +
'<a id="my-anchor"></a>',
);
});
});
Expand Down

0 comments on commit 7712685

Please sign in to comment.