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

let post_link use original post title as title attribute #4973

Merged
merged 2 commits into from
Aug 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/plugins/tag/post_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module.exports = ctx => {
if (!post) return error;

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('no slug', () => {
Expand Down