Skip to content

Commit

Permalink
fix: only apply embed styling when required
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Feb 10, 2024
1 parent 6297bc2 commit 36b3b7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/core/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ <h3 class="title">Markdown Styling</h3>
<discord-code>I am inline-code text!</discord-code>
</discord-message>
<discord-message>
<discord-code multiline>I am multi-\nline code text!</discord-code>
<discord-code multiline>I am multi-line code</discord-code>
</discord-message>
<discord-message>
<discord-spoiler>I am spoiler text!</discord-spoiler>
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/components/discord-code/DiscordCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,28 @@ export class DiscordCode extends LitElement implements LightTheme {
}
`;

/**
* Whether this code block is a multi-line code block
*/
@property({ type: Boolean, reflect: true })
public accessor multiline = false;

@consume({ context: messagesLightTheme, subscribe: true })
@property({ type: Boolean, reflect: true, attribute: 'light-theme' })
public accessor lightTheme = false;

/**
* Whether this code block exists within a `discord-embed` component.
*/
@property({ type: Boolean, reflect: true })
public accessor embed = false;

/**
* The language of the code snippet.
*
* Setting this property will add a class "language-<language>" to the `code` element
* which can get styled by a library such as [Prism](https://prismjs.com/).
*/
@property()
public accessor language: string | undefined = undefined;

Expand All @@ -92,7 +104,7 @@ export class DiscordCode extends LitElement implements LightTheme {

protected override render() {
if (this.multiline) {
return html`<discord-pre embed
return html`<discord-pre ?embed=${this.embed}
><code class="${ifDefined(this.language ? `language-${this.language}` : undefined)}"><slot></slot></code
></discord-pre>`;
}
Expand Down

0 comments on commit 36b3b7a

Please sign in to comment.