pngwn / MDsveX

A markdown preprocessor for Svelte.
https://mdsvex.pngwn.io
MIT License
2.36k stars 102 forks source link

why not <style> instead of ```style? #23

Closed swyxio closed 4 years ago

swyxio commented 5 years ago

i've read https://github.com/pngwn/MDsveX/issues/10, so i understand that this may be hard given the current setup of mdsvex, but the way i really do want to code is to use mdsvex as a single file component file authoring mechanism.

while this thing is still in early life, i think its worth considering if this is what we want (i'm also throwing in github flavored markdown mixing of markdown and html tags):

<script>
import Layout from './layout'
</script>

<style>
  .noooes {
    color: white;
  }
</style>

<Layout>
    <h1 class='noooes'>Test</h1>

    - markdown li 1
    - markdown li 2
    - markdown li 3

</Layout>

this may mean forking rollup-plugin-svelte or integrating with it in some other way in order to be a superset.

pngwn commented 5 years ago

Partly because of scope, partly because of the parser being annoying.

The component is converted into a Svelte component before being wrapped with the Layout (if built-in layouts are used) which means the style tag is no longer a top-level element so it becomes a normal style tag rather than scoped css. This is solvable but annoying without reparsing the document since you just get a new string back from markdown-it. The other reason was due to how markdown-it parses style elements since everything is configurable via the parser option everything essentially has to work with standard markdown parsing rules (ish).

This is something I want to support and will look at fixing both issues when I implement #20 which will happen over the next few weeks, maybe sooner. Having an AST will make these kinds of modifications much simpler and won't require me to reparse the document which removes any significant performance penalty.

swyxio commented 5 years ago

brilliant. i look foward to it

swyxio commented 4 years ago

closing in favor of https://github.com/pngwn/MDsveX/issues/27