Can I apply a language to inline <code> blocks? #630

Open
opened 2026-01-29 14:41:32 +00:00 by claunia · 2 comments
Owner

Originally created by @seangwright on GitHub (Oct 2, 2023).

Prism.js can highlight inline code blocks like `<div></div>` but a language needs to specified (the way we do for multiline fenced code blocks.

If a language is provided on the <code> element then it will be highlighted.

<code class="language-markup">
<!-- ... -->
</code>

Is there a way to specify an inline code fence language? Something like `[html]<div></div>`

If not, I supposed I just need to supply some default styles for <code> elements.

Originally created by @seangwright on GitHub (Oct 2, 2023). [Prism.js](https://prismjs.com/) can highlight inline code blocks like `` `<div></div>` `` but a language needs to specified (the way we do for multiline fenced code blocks. If a language is provided on the `<code>` element then it will be highlighted. ```html <code class="language-markup"> <!-- ... --> </code> ``` Is there a way to specify an inline code fence language? Something like `` `[html]<div></div>` `` If not, I supposed I just need to supply some default styles for `<code>` elements.
claunia added the question label 2026-01-29 14:41:32 +00:00
Author
Owner

@gfoidl commented on GitHub (Oct 3, 2023):

Does

    foo bar

    ```c#
    int answer = 42;
    ```

    baz

work for you? dotnet fiddle displays the correct html-tags.

@gfoidl commented on GitHub (Oct 3, 2023): Does ``` foo bar ```c# int answer = 42; ``` baz ``` work for you? [dotnet fiddle](https://dotnetfiddle.net/SC89Df) displays the correct html-tags.
Author
Owner

@seangwright commented on GitHub (Oct 3, 2023):

That produces this:

<p>foo bar</p>

<pre class="language-csharp"><code>int answer = 42;
</code></pre>

<p>baz</p>

I want the code to be inline with the content:

<p>foo bar <code class="language-csharp">int answer = 42;</code> baz </p>
@seangwright commented on GitHub (Oct 3, 2023): That produces this: ``` <p>foo bar</p> <pre class="language-csharp"><code>int answer = 42; </code></pre> <p>baz</p> ``` I want the code to be inline with the content: ``` <p>foo bar <code class="language-csharp">int answer = 42;</code> baz </p> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#630