|
1 | 1 | import { consume } from '@lit/context';
|
2 |
| -import { css, html, LitElement } from 'lit'; |
| 2 | +import { css, html, LitElement, type TemplateResult } from 'lit'; |
3 | 3 | import { customElement, property } from 'lit/decorators.js';
|
4 | 4 | import { classMap } from 'lit/directives/class-map.js';
|
5 | 5 | import { ifDefined } from 'lit/directives/if-defined.js';
|
@@ -122,6 +122,11 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light
|
122 | 122 | width: 24px;
|
123 | 123 | }
|
124 | 124 |
|
| 125 | + :host .discord-embed-author-block, |
| 126 | + :host .discord-embed-author-block > span { |
| 127 | + max-width: 95%; |
| 128 | + } |
| 129 | +
|
125 | 130 | :host .discord-embed-provider {
|
126 | 131 | font-size: 0.75rem;
|
127 | 132 | line-height: 1rem;
|
@@ -328,10 +333,15 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light
|
328 | 333 | ${when(
|
329 | 334 | this.authorUrl,
|
330 | 335 | () =>
|
331 |
| - html`<a href=${ifDefined(this.authorUrl)} target="_blank" rel="noopener noreferrer"> |
332 |
| - ${emojiParsedAuthorName} |
| 336 | + html`<a |
| 337 | + href=${ifDefined(this.authorUrl)} |
| 338 | + target="_blank" |
| 339 | + rel="noopener noreferrer" |
| 340 | + class="discord-embed-author-block" |
| 341 | + > |
| 342 | + <span class="discord-embed-author-block">${emojiParsedAuthorName}</span> |
333 | 343 | </a>`,
|
334 |
| - () => html`${emojiParsedAuthorName}` |
| 344 | + () => html`<span class="discord-embed-author-block">${emojiParsedAuthorName}</span>` |
335 | 345 | )}
|
336 | 346 | </div>`
|
337 | 347 | )}
|
@@ -388,18 +398,35 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light
|
388 | 398 | private parseTitle(title?: string) {
|
389 | 399 | if (!title) return null;
|
390 | 400 |
|
391 |
| - const words = title.split(' '); |
| 401 | + const el: (TemplateResult<1> | string)[] = []; |
| 402 | + let complete = ''; |
| 403 | + |
| 404 | + for (const words of title.split('\n')) { |
| 405 | + for (const word of words.split(' ')) { |
| 406 | + const emoji = getGlobalEmojiUrl(word) ?? this.embedEmojisMap[word] ?? ({} as Emoji); |
| 407 | + |
| 408 | + if (emoji.name) { |
| 409 | + el.push(html`<discord-custom-emoji name=${emoji.name} url=${ifDefined(emoji.url)} embed-emoji></discord-custom-emoji>`); |
| 410 | + } else { |
| 411 | + complete += `${word} `; |
| 412 | + } |
| 413 | + |
| 414 | + if (complete === ' ') { |
| 415 | + el.push(html`<br />`); |
| 416 | + } |
| 417 | + } |
| 418 | + |
| 419 | + el.push(complete); |
| 420 | + |
| 421 | + complete = ''; |
| 422 | + } |
392 | 423 |
|
393 |
| - return words.map((word: string, idx: number) => { |
394 |
| - const emoji = getGlobalEmojiUrl(word) ?? this.embedEmojisMap[word] ?? ({} as Emoji); |
395 |
| - let el; |
396 |
| - if (emoji.name) { |
397 |
| - el = html`<discord-custom-emoji name=${emoji.name} url=${ifDefined(emoji.url)} embed-emoji></discord-custom-emoji>`; |
398 |
| - } else { |
399 |
| - el = idx < words.length - 1 ? `${word} ` : word; |
| 424 | + return el.map((wordOrHtmlTemplate) => { |
| 425 | + if (typeof wordOrHtmlTemplate === 'string') { |
| 426 | + return html`<span>${wordOrHtmlTemplate}</span>`; |
400 | 427 | }
|
401 | 428 |
|
402 |
| - return el; |
| 429 | + return wordOrHtmlTemplate; |
403 | 430 | });
|
404 | 431 | }
|
405 | 432 | }
|
|
0 commit comments