Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/comment-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@lit/context": "^1.1.6",
"@lit/localize": "^0.12.2",
"@tiptap/core": "^3.10.4",
"@tiptap/extension-link": "^3.10.4",
Comment thread
HowieHz marked this conversation as resolved.
Outdated
"@tiptap/extensions": "^3.10.4",
"@tiptap/pm": "^3.10.4",
"@tiptap/starter-kit": "^3.10.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/comment-widget/src/base-comment-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BaseCommentItem extends LitElement {
class="item-author font-medium text-sm text-text-1 hover:underline"
target="_blank"
href=${ifDefined(this.userWebsite)}
rel="noopener noreferrer"
rel="noopener noreferrer nofollow ugc"
>
${this.userDisplayName}
</a>
Expand Down
17 changes: 17 additions & 0 deletions packages/comment-widget/src/comment-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export class CommentContent extends LitElement {
@property({ type: String })
content: string = '';

private applyLinkAttributes() {
const anchors =
this.shadowRoot?.querySelectorAll<HTMLAnchorElement>('.content a');

anchors?.forEach((anchor) => {
anchor.target = '_blank';
anchor.rel = 'noopener noreferrer nofollow ugc';
});
}

protected override firstUpdated(_changedProperties: PropertyValues) {
super.firstUpdated(_changedProperties);
const codeElements = this.shadowRoot?.querySelectorAll('pre>code');
Expand Down Expand Up @@ -38,6 +48,13 @@ export class CommentContent extends LitElement {
);
}

protected override updated(_changedProperties: PropertyValues) {
super.updated(_changedProperties);
if (_changedProperties.has('content')) {
this.applyLinkAttributes();
}
}

private extractLanguageFromCodeElement(codeElement: Element): string | null {
const supportedPrefixes = ['language-', 'lang-'];

Expand Down
13 changes: 11 additions & 2 deletions packages/comment-widget/src/comment-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ export class CommentEditor extends LitElement {

async createEditor() {
const { Editor } = await import('@tiptap/core');
const { Placeholder } = await import('@tiptap/extensions');
const { CharacterCount, Placeholder } = await import('@tiptap/extensions');
const { Link } = await import('@tiptap/extension-link');
const { StarterKit } = await import('@tiptap/starter-kit');
const { CodeBlockShiki } = await import(
'tiptap-extension-code-block-shiki'
);
const { CharacterCount } = await import('@tiptap/extensions');

this.loading = false;

Expand All @@ -119,6 +119,15 @@ export class CommentEditor extends LitElement {
placeholder: this.placeholder || msg('Write a comment'),
}),

Link.configure({
openOnClick: false,
defaultProtocol: 'https',
HTMLAttributes: {
target: '_blank',
rel: 'noopener noreferrer nofollow ugc',
},
}),

Comment thread
HowieHz marked this conversation as resolved.
Outdated
CodeBlockShiki.configure({
defaultTheme: 'github-dark',
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/comment-widget/src/user-avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class UserAvatar extends LitElement {

override render() {
if (this.href) {
return html`<a class="avatar" href="${this.href}" target="_blank" rel="noopener noreferrer">
return html`<a class="avatar" href="${this.href}" target="_blank" rel="noopener noreferrer nofollow ugc">
${this.renderAvatarContent()}
</a>`;
}
Expand Down
36 changes: 35 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.