question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSCode plugin: Syntax highlighting not correctly applied to embedded svelte component in markdown

See original GitHub issue

Describe the bug Syntax highlighting not correctly applied to embedded svelte component in markdown when using “Svelte for VSCode”

To Reproduce Steps to reproduce the behavior:

Put the following inside a markdown document:

```svelte
<script>
  import { onMount } from "svelte";

  export let data = undefined;
  let dom_node;

  onMount(() => {
    Plotly.newPlot(dom_node, data, {barmode: 'stack'});
  });
</script>

<div id="plotDiv" bind:this={dom_node}></div>
```

For example a code snippet that is treated in a way you don’t expect.

Expected behavior

Expected similar syntax highlighting to what I see when viewing a svelte file with that content.

Actual behaviour

Get somewhat incorrect / inconsistent formatting (see screenshots)

Screenshots If applicable, add screenshots to help explain your problem.

View for a svelte component (correct):

image

View for a svelte component embedded in markdown (incorrect):

image

System (please complete the following information):

  • OS: Mac and Windows 10
  • IDE: VSCode
  • Plugin/Package: “Svelte for VSCode”

Additional context Add any other context about the problem here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Jul 16, 2021

Thank you for digging into this!

1reaction
wlachcommented, Jul 16, 2021

Apologies for my flailing around. Dug into things more and realized that @jasonlyu123 was correct all along: the injection rules are not being applied in an embedded context. The weird behaviour I’m describing above is only due to the fact that the injection rules are not there, and it’s falling back to whatever else is defined in the file.

I’m now pretty sure this is an issue upstream so filed an issue there: https://github.com/microsoft/vscode-textmate/issues/152 – that has some more details as well as confirmation of the problem described.

It’s likely possible to make the grammar not depend on injections (e.g. I got it working for bare script tags without them), though I think it would be less elegant.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with vscode syntax highlighting for svelte files
I currently have 3 svelte extensions installed. I've tried disabling, uninstalling, etc and none seem to fix it. I've tried updating vscode, no...
Read more >
Svelte code highlight in markdown code block in VSCode
Hello. I try save some svelte code examples in md files, but highlight and formatting not woking. Try to show them as `html`...
Read more >
Will Lachance (@wrlach) / Twitter
Describe the bug Syntax highlighting not correctly applied to embedded svelte component in markdown when using "Svelte for VSCode" To Reproduce Steps to ......
Read more >
Prettier 2.1: new --embedded-language-formatting option and ...
It applies to all languages where Prettier recognizes embedded code, not just JavaScript. // Input html` <p> I am expecting this to come...
Read more >
Web Development Simplified with Svelte
Svelte : 9.7. Some web frameworks, including React and Vue, use a virtual DOM to optimize rendering changes. When components re-render, the framework...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found