Skip to content

Commit

Permalink
fix: use hr instead of a tag
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 8d9712e commit 0a70e2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/transform/plugins/block-anchor/block-anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export function replaceTokens(state: StateCore) {
export function renderTokens(tokens: Token[], idx: number) {
const token = tokens[idx];
const id = token.content;
return `<a id=${id}></a>`;
return `<hr id=${id} class="visually-hidden"/>`;
}
10 changes: 6 additions & 4 deletions test/block-anchor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ let transformYfm = (text: string) => {

describe('block-anchor', function () {
describe('simple rendering', () => {
it('should render an a tag', () => {
expect(transformYfm('{%anchor my-anchor%}')).toBe('<a id="my-anchor"></a>');
it('should render an hr tag', () => {
expect(transformYfm('{%anchor my-anchor%}')).toBe(
'<hr id="my-anchor" class="visually-hidden" />',
);
});
it('does not consume things it should not', () => {
expect(transformYfm('# Heading \n {%anchor my-anchor%} \n # Other heading')).toEqual(
'<h1 id="heading"><a href="#heading" class="yfm-anchor" aria-hidden="true">' +
'<span class="visually-hidden">Heading</span></a>Heading</h1>\n' +
'<a id="my-anchor"></a><h1 id="other-heading">' +
'<hr id="my-anchor" class="visually-hidden" /><h1 id="other-heading">' +
'<a href="#other-heading" class="yfm-anchor" aria-hidden="true">' +
'<span class="visually-hidden">Other heading</span></a>Other heading</h1>\n',
);
Expand All @@ -44,7 +46,7 @@ describe('block-anchor', function () {
'<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>',
'<hr id="my-anchor" class="visually-hidden" />',
);
});
});
Expand Down

0 comments on commit 0a70e2e

Please sign in to comment.