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

Parser for prettier #123

Open
eps1lon opened this issue Aug 17, 2020 · 3 comments
Open

Parser for prettier #123

eps1lon opened this issue Aug 17, 2020 · 3 comments

Comments

@eps1lon
Copy link

eps1lon commented Aug 17, 2020

To format .svx files I'm using prettier with their built-in parser for markdown which isn't ideal since it doesn't touch code such as

<script context="module">
  export async function preload() {
    const {repositories, totalStars, updatedAt} = await this.fetch('contributions.json').then(response => response.json());

    repositories.sort((a, b) => {
      return b.stars - a.stars
    });

    return {repositories, totalStars, updatedAt};
  }
</script>

-- .svx in prettier playground

when the actual javascript should be formatted as

export async function preload() {
  const { repositories, totalStars, updatedAt } = await this.fetch(
    "contributions.json"
  ).then((response) => response.json());

  repositories.sort((a, b) => {
    return b.stars - a.stars;
  });

  return { repositories, totalStars, updatedAt };
}

-- javascript in prettier playground

Using the mdx parser does not work since it causes multiple syntax errors.

I guess we should be able to pass a custom parser to prettier. prettier/prettier#4975 could be used as inspiration.

@pngwn
Copy link
Owner

pngwn commented Aug 17, 2020

This is very much on my todo list when i've resolved a few core issues that I'm currently working on.

@jcayzac
Copy link

jcayzac commented Jul 31, 2021

Prettier uses themdx parser when it sees a .mdx, with the result you highlight above. The markdown parser gives me better results. Try adding this to your .prettierrc.yaml:

overrides:
  - files:
      - '*.mdx'
      - '*.svx'
    options:
      parser: markdown

@pngwn pngwn added this to mdsvex Oct 16, 2021
@pngwn pngwn moved this to Refine in mdsvex Oct 16, 2021
@basaran
Copy link

basaran commented Oct 29, 2021

it would have been great to have something that combines mdx and markdown parsers. Mdx formats everything nicely, but destroys the mdsvex file :) and markdown skips formatting of all svelte markup.

In the meantime, on sublime, I setup two formatters. The formatter I use for selections does mdx formatting that I use on markup, and the formatter for the entire buffer uses markdown parser.

@pngwn pngwn added this to mdsvex Feb 24, 2024
@github-project-automation github-project-automation bot moved this to Triage + Refine in mdsvex Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Triage + Refine
Status: Refine
Development

No branches or pull requests

4 participants