#MDX Code Blocks not syntax higlighted

72 messages · Page 1 of 1 (latest)

crude plaza
#

Hello 👋
We are running Storybook 6.5.15 for WebComponents and I am unable to get code syntax blocks to highlight code.

You can see from the screenshot its just some un-highlighted code block.
I have also put the file of the MDX in the screenshot here.

Any pointers or advice, would be fantastic.

Thanks
Warren

NOTE: Code sample below is using ''' and not backticks ` as Discord getting confused as what to render as code snippet.

import { Meta } from '@storybook/addon-docs';

<Meta title="Guides/Store" parameters={{ previewTabs: { canvas: { hidden: true } } }} />

# Store


A store is the link between a Resource and a data implementation. A store is mainly taken form as a Context, In other words we will have to Consume the Context(Store) to get the Store.
Generally a Store will be holding one or more RxJS Subjects, each Subject is made available for Subscription via a RxJS Observable.

### A Simple Store:

'''typescript
class MyProductStore {

    #products = new ArrayState(<Array<MyProductType>>[], (product) => product.key);

    public readonly products = this.#products.asObservable();

    protected host: UmbControllerHostInterface;
    constructor(host: UmbControllerHostInterface) {
        this.host = host;

        // The Store provides it self as a Context-API.
        new UmbContextProviderController(_host, 'MyStoreContextAlias', this);
    }

}
'''
wanton crown
#

Have you tried upgrading to 7.0 to see if it has been fixed there? npx sb@next upgrade —prerelease if you’d like to try.

crude plaza
#

@wanton crown I will give that a go and see what happens

crude plaza
#

OK running sb@next upgrade —prerelease is being weird @wanton crown
I get the interactive prompt talking about V7 migrations but my package.json is only updating to 6.15.6

wanton crown
#

Two dashes? —prerelease

#

It’s combining them on discord

#

Ugh

crude plaza
#

Then when running npm run storybook
I get this issue

#

Ahhh OK will try with two dashes

#

OK getting different prompts so looks a bit more promising

wanton crown
#

🤞

crude plaza
#

OK well looks to have upgraded but now to investigate why its not running/booting

#

Well its descriptive - so off to go hunt & solve this tomorrow 😄

wanton crown
crude plaza
#

OK well boots now after fixing duplicate IDs - clearly a side effect of some of us in the team doing some copy/pasting coding that we all love to do.

Now onto porting the MDX to get them to work

crude plaza
#

Current issue I have is that I can't get Markdown links to other MDX files to work

#

[Link Text](link-url)

Any ideas @wanton crown ?

wanton crown
#

Is there any jsx on the same line as the link?

#

That apparently breaks in mdx2. I'm honestly not an MDX user so I'm not really sure. That might be more in @icy hull's expertise.

crude plaza
#

- **Resource** A API enabling communication with a server. [Go to Resource Guide](/?path=/story/guides-resource--page)

wanton crown
#

Does it work if it's on its own line, out of curiosity?

#

Probably not

#

Are you getting an error, or it just doesn't make a link?

icy hull
crude plaza
#

Blank page in Storybook but some console errors in DevTools

#

So no visible error in the UI until you look at the console

icy hull
#

Interesting. That looks like it can't find the theme, which is provided via React context.

That markdown link isn't somehow inside a story is it?

crude plaza
#
import { Meta } from '@storybook/blocks';

<Meta title="Guides/Getting Started" />

# Getting started
This section contains a set of guide which will ease the learning of the Umbraco CMS (Backoffice).
In this document you will get a overview of the articles — Enabling you to get started with the parts that makes sense for you.

# Terminology
There is a few words that covers certain concepts, which is good to learn to easilier decode the purpose of code.

[Go to Resource Guide](/?path=/story/guides-resource--page)
#

Thats the whole file for now. If I remove the last line for the markdown type link it then renders the two headers and paragraphs fine

icy hull
#

I just copy/pasted that last line into an MDX file in the project I'm working on now (react-vite, beta.47) and it worked as expected.

I'm not sure what's happening in your project. 😕

wanton crown
#

I wonder if it's related to web-components? Or the version of react being used? @icy hull do you have react 18 installed?

#

@crude plaza it sounds like the most useful thing would be to create a minimal reproduction, if you're able.

wanton crown
crude plaza
#

Hmm can't repro in that StackBlitz :S

#

Seems like something in our setup then - now the joy of finding it 🙈

#

Worst case for now I can turn them back to regular <a> but would be good to figure out why it imploded on me?! 🤔

wanton crown
#

what does your .storybook/main.js look like?

crude plaza
#
const tsconfigPaths = require('vite-tsconfig-paths').default;
const {
  mergeConfig
} = require('vite');
module.exports = {
  stories: ['../@(src|libs|apps)/**/*.@(mdx|stories.@(js|jsx|ts|tsx))'],
  addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-a11y'],
  framework: {
    name: '@storybook/web-components-vite',
    options: {}
  },
  features: {
    previewMdx2: true,
    storyStoreV7: true
  },
  staticDirs: ['../public-assets'],
  async viteFinal(config, {
    configType
  }) {
    return mergeConfig(config, {
      // customize the Vite config here
      plugins: [tsconfigPaths()]
    });
  },
  docs: {
    autodocs: true
  }
};
wanton crown
#

Are you using tsconfigPaths in your vite.config.js file?

#

Storybook 7 reads your vite config automatically, so you may no longer need to merge the config.

#

Also, you can write your main.js in ESM or TypeScript now, BTW

crude plaza
#

Yeh this was after the auto migration stuff - not touched this file

#

Just noticed also the StackBlitz is on beta 47 where I am on beta 53

wanton crown
#

oh strange, I'll look into that, thanks

#

Thanks, I think you just spotted a pretty big problem in our CI process. 😅

crude plaza
#

hehe well glad I have been helpful in that way

#

Curious if it is an issue with .53 the markdown thing

#

Gonna look at converting the main.js over into TS

wanton crown
#

You should be able to change the package.json in the stackblitz and then refresh the page which will trigger a re-installation

crude plaza
#

OK works with .53 in StackBlitz this is gonna bug me...

wanton crown
#

I find the easiest thing to do is to simplify my project more and more until it matches the reproduction that works.

#

One smallish step at a time

crude plaza
#

Yep think thats gonna be tomorows job - getting glares from the wife to get off the laptop this evening

wanton crown
#

:-D. Have a good evening!

crude plaza
#

Thanks you too

#

OK gonna post this here before I forget tomorrow....
Also same/similar problem the MDX does not render when trying to render a code block with backticks.

'''typescript
this.consumeContext('requestThisContextAlias', (context) => {
    // Notice this is a subscription, as context might change or a new one appears.
    console.log("I've got the context", context);
});
'''
icy hull
#

Those are apostrophes ('), not backticks (`).

wanton crown
#

He had to do that for discord

wanton crown
icy hull
#

Oh, duh. 🤦‍♂️ I wish Discord supported the "use four backticks to code fence and you can put three backticks in the code block" trick.

icy hull
wanton crown
#

cool! I didn't know that. thanks

crude plaza
#

OK most of these console errors point to theme things not being set.
However I don't think we have any custom themes set AFAIK.

Where would I look to see if we did override any of this @wanton crown or @icy hull ?

crude plaza
icy hull
#

The theme that is not being set is likely the theme used by the docs components. Somehow the React context connection used to provide that theme to the various components is broken in your project.

I took a look at your project (the storybook-v7-upgrade branch) and see a few improvements that could be made:

  • Rename *.stories.mdx files to *.mdx. While the latter is generally still supported, it can cause strange problems. When you do this, you should also update the stories array in .storybook/main.js to ['../@(src|libs|apps)/**/*.mdx', '../@(src|libs|apps)/**/*.stories.@(js|jsx|ts|tsx)']
  • storyStoreV7 is now the default, so no need for that feature flag
  • Did you know you can reference CSF stories in MDX? It's more straightforward in 7.0 and we just published updated docs: https://storybook.js.org/docs/7.0/web-components/writing-docs/mdx
crude plaza
#

Thanks for this advice @icy hull my colleague found the issue was to do something with package.lock.json so he deleted it and it all started working working.

#

I will try adding your improvements be it me or my colleagues.

crude plaza
#

@icy hull or @wanton crown can I ask either of you for any tooling/extensions in VSCode that can be installed to make writing MDX files easier with completions of the blocks offered by Storybook?