Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 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,11 @@ 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 { 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 @@ -111,6 +110,11 @@ export class CommentEditor extends LitElement {
heading: false,
link: {
openOnClick: false,
defaultProtocol: 'https',
HTMLAttributes: {
target: '_blank',
rel: 'noopener noreferrer nofollow ugc',
},
},
codeBlock: false,
}),
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
Loading