Skip to content
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

Markdoc shiki code does not render inside an if tag #11656

Open
1 task done
taktran opened this issue Aug 8, 2024 · 1 comment
Open
1 task done

Markdoc shiki code does not render inside an if tag #11656

taktran opened this issue Aug 8, 2024 · 1 comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) pkg: markdoc Related to the `@astrojs/markdoc` package (scope)

Comments

@taktran
Copy link
Contributor

taktran commented Aug 8, 2024

Astro Info

Astro                    v4.13.2
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/markdoc

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Using shiki code highlighting inside a markdoc if tag results in nothing being rendered (including other content inside the if tag).

What's the expected result?

In this .mdoc file:

{% if equals("true", "true") %}
Inside truthy

```js
const hello = "yes";
```

{% /if %}

I expect to see Inside truthy and the code block rendered using shiki highlighting, however all the contents inside the if are not shown at all: https://stackblitz.com/edit/github-jw5bfh?file=src%2Fcontent%2Fdocs%2Fintro.mdoc

I've replicated this with shiki commented out: https://stackblitz.com/edit/github-jw5bfh-xsgvdw?file=src%2Fcontent%2Fdocs%2Fintro.mdoc,markdoc.config.mjs - here the text and code are shown.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-jw5bfh?file=src%2Fcontent%2Fdocs%2Fintro.mdoc

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 8, 2024
@bluwy bluwy added the pkg: markdoc Related to the `@astrojs/markdoc` package (scope) label Aug 8, 2024
@taktran
Copy link
Contributor Author

taktran commented Aug 8, 2024

I copied over the Astro Shiki extension and console logged the results when parsing a .mdoc file, and it seems like the extension is returning the correct output, so I'm thinking it's the Astro/Markdoc wrapping around it.

.mdoc

{% if isFramework("react") %}
react code
```js
const js = "hello";
```
{% /if %}

Inside the shiki extension

console.log({
    lang,
    content: attributes.content,
    html,
    unescaped: unescapeHTML(html),
});

Console

{
  lang: 'js',
  content: 'const js = "hello";\n',
  html: '<pre class="astro-code astro-code-themes github-light github-dark" style="background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;" tabindex="0" data-language="js"><code><span class="line"><span style="color:#D73A49;--shiki-dark:#F97583">const</span><span style="color:#005CC5;--shiki-dark:#79B8FF"> js</span><span style="color:#D73A49;--shiki-dark:#F97583"> =</span><span style="color:#032F62;--shiki-dark:#9ECBFF"> "hello"</span><span style="color:#24292E;--shiki-dark:#E1E4E8">;</span></span>\n' +
    '<span class="line"></span></code></pre>',
  unescaped: [String (HTMLString): '<pre class="astro-code astro-code-themes github-light github-dark" style="background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;" tabindex="0" data-language="js"><code><span class="line"><span style="color:#D73A49;--shiki-dark:#F97583">const</span><span style="color:#005CC5;--shiki-dark:#79B8FF"> js</span><span style="color:#D73A49;--shiki-dark:#F97583"> =</span><span style="color:#032F62;--shiki-dark:#9ECBFF"> "hello"</span><span style="color:#24292E;--shiki-dark:#E1E4E8">;</span></span>\n' +
    '<span class="line"></span></code></pre>']
}

@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) pkg: markdoc Related to the `@astrojs/markdoc` package (scope)
Projects
None yet
Development

No branches or pull requests

3 participants