-
-
Notifications
You must be signed in to change notification settings - Fork 49
fix: added the possibility of skipping lines for discord-embed titles #426
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
Changes from all commits
12dd7d4
59fe264
a40eefe
d3e8ea4
07c0d6d
fd46751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { consume } from '@lit/context'; | ||
import { css, html, LitElement } from 'lit'; | ||
import { css, html, LitElement, type TemplateResult } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
import { classMap } from 'lit/directives/class-map.js'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
|
@@ -122,6 +122,11 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light | |
width: 24px; | ||
} | ||
|
||
:host .discord-embed-author-block, | ||
:host .discord-embed-author-block > span { | ||
max-width: 95%; | ||
} | ||
|
||
:host .discord-embed-provider { | ||
font-size: 0.75rem; | ||
line-height: 1rem; | ||
|
@@ -328,10 +333,15 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light | |
${when( | ||
this.authorUrl, | ||
() => | ||
html`<a href=${ifDefined(this.authorUrl)} target="_blank" rel="noopener noreferrer"> | ||
${emojiParsedAuthorName} | ||
html`<a | ||
href=${ifDefined(this.authorUrl)} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
class="discord-embed-author-block" | ||
> | ||
<span class="discord-embed-author-block">${emojiParsedAuthorName}</span> | ||
</a>`, | ||
() => html`${emojiParsedAuthorName}` | ||
() => html`<span class="discord-embed-author-block">${emojiParsedAuthorName}</span>` | ||
)} | ||
</div>` | ||
)} | ||
|
@@ -388,18 +398,35 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light | |
private parseTitle(title?: string) { | ||
if (!title) return null; | ||
|
||
const words = title.split(' '); | ||
const el: (TemplateResult<1> | string)[] = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't strongly typed, hiding a bug at the end of the function (see below) |
||
let complete = ''; | ||
|
||
for (const words of title.split('\n')) { | ||
for (const word of words.split(' ')) { | ||
const emoji = getGlobalEmojiUrl(word) ?? this.embedEmojisMap[word] ?? ({} as Emoji); | ||
|
||
if (emoji.name) { | ||
el.push(html`<discord-custom-emoji name=${emoji.name} url=${ifDefined(emoji.url)} embed-emoji></discord-custom-emoji>`); | ||
} else { | ||
complete += `${word} `; | ||
} | ||
|
||
if (complete === ' ') { | ||
el.push(html`<br />`); | ||
} | ||
} | ||
|
||
el.push(complete); | ||
|
||
complete = ''; | ||
} | ||
|
||
return words.map((word: string, idx: number) => { | ||
const emoji = getGlobalEmojiUrl(word) ?? this.embedEmojisMap[word] ?? ({} as Emoji); | ||
let el; | ||
if (emoji.name) { | ||
el = html`<discord-custom-emoji name=${emoji.name} url=${ifDefined(emoji.url)} embed-emoji></discord-custom-emoji>`; | ||
} else { | ||
el = idx < words.length - 1 ? `${word} ` : word; | ||
return el.map((wordOrHtmlTemplate) => { | ||
if (typeof wordOrHtmlTemplate === 'string') { | ||
return html`<span>${wordOrHtmlTemplate}</span>`; | ||
} | ||
|
||
return el; | ||
return wordOrHtmlTemplate; | ||
}); | ||
Comment on lines
+424
to
430
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your code you typed |
||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added inline styles here. That makes it harder for end-user customizability and we try to avoid them unless strictly necessary. I moved the styles to a class.