Skip to content

Commit

Permalink
feat(tag/post_link): use original post title as title attribute (#4973)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Aug 27, 2022
1 parent a2fc8c0 commit e44b48c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/plugins/tag/post_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ module.exports = ctx => {
}

let title = args.length ? args.join(' ') : post.title;
const attrTitle = escapeHTML(title);
if (escape === 'true') title = attrTitle;
// Let attribute be the true post title so it appears in tooltip.
const attrTitle = escapeHTML(post.title);
if (escape === 'true') title = escapeHTML(title);

const link = encodeURL(resolve(ctx.config.root, post.path));

Expand Down
6 changes: 3 additions & 3 deletions test/scripts/tags/post_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('post_link', () => {
});

it('title', () => {
postLink(['foo', 'test']).should.eql('<a href="/foo/" title="test">test</a>');
postLink(['foo', 'test']).should.eql('<a href="/foo/" title="Hello world">test</a>');
});

it('should escape tag in title by default', () => {
Expand All @@ -45,7 +45,7 @@ describe('post_link', () => {
});

it('should escape tag in custom title', () => {
postLink(['title-with-tag', '<test>', 'title', 'true']).should.eql('<a href="/title-with-tag/" title="&lt;test&gt; title">&lt;test&gt; title</a>');
postLink(['title-with-tag', '<test>', 'title', 'true']).should.eql('<a href="/title-with-tag/" title="&quot;Hello&quot; &lt;new world&gt;!">&lt;test&gt; title</a>');
});

it('should not escape tag in title', () => {
Expand All @@ -54,7 +54,7 @@ describe('post_link', () => {

it('should not escape tag in custom title', () => {
postLink(['title-with-tag', 'This is a <b>Bold</b> "statement"', 'false'])
.should.eql('<a href="/title-with-tag/" title="This is a &lt;b&gt;Bold&lt;&#x2F;b&gt; &quot;statement&quot;">This is a <b>Bold</b> "statement"</a>');
.should.eql('<a href="/title-with-tag/" title="&quot;Hello&quot; &lt;new world&gt;!">This is a <b>Bold</b> "statement"</a>');
});

it('should throw if no slug', () => {
Expand Down

0 comments on commit e44b48c

Please sign in to comment.