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

[idea] add markup preprocessor helper util that only works on markup #5005

Closed
swyxio opened this issue Jun 11, 2020 · 3 comments
Closed

[idea] add markup preprocessor helper util that only works on markup #5005

swyxio opened this issue Jun 11, 2020 · 3 comments

Comments

@swyxio
Copy link
Contributor

swyxio commented Jun 11, 2020

Is your feature request related to a problem? Please describe.

while writing the preprocessor recipe (https://github.com/svelte-society/recipes-mvp/blob/master/build-setup.md#how-to-make-a-pre-processor-that-makes-it-possible-to-use-pugjade) and livecoding for a talk, i realized it is too hard to split out the script/style tags and then too easy to forget to stitch them back together again. this is a pretty common task for markup preprocessing and i think it would be very low cost to add it to svelte since it only involves optional code?

Describe the solution you'd like

offer a utility for preprocessing that kinda works like this:

import {utils} from "svelte/compiler"
(async function () {
  const result = await svelte.preprocess(file, {
    markup: ({ content }) => {
      code = utils.modifyTemplate(template => {
			// no need to mess with stripping and restitching style and script tags
			return pug.render(template)
	  })
      return { code };
    },
  });
})();

we offer this for script and style tags, it feels weird that we don't offer it for markup right?

Describe alternatives you've considered

do nothing, or

could also just consider an alternative template api:

import {utils} from "svelte/compiler"
(async function () {
  const result = await svelte.preprocess(file, {
    template: ({ content }) => {
      return { code: pug.render(template) };
    },
  });
})();

How important is this feature to you?

nice to have

@swyxio swyxio changed the title add markup preprocessor helper util that only works on markdown [idea] add markup preprocessor helper util that only works on markdown Jun 11, 2020
@swyxio swyxio changed the title [idea] add markup preprocessor helper util that only works on markdown [idea] add markup preprocessor helper util that only works on markup Jun 11, 2020
@pngwn
Copy link
Member

pngwn commented Jun 11, 2020

The reason for this is that script and style tags are markup. That said, they are also handled specially by Svelte. If you were writing pug, wouldn’t you write your script and styles tags in pug syntax too?

@swyxio
Copy link
Contributor Author

swyxio commented Jun 11, 2020

mm i see! pug doesnt officially mention either way what their script and style tag support is. probably pug isn't the best example here anyway... what are other ways that the markup preprocessor gets used?

honestly dont really know any others but the level of interest in my talk seemed to indicate that people had ideas.

this isnt something im dying to have i just thought it might be nice to have since we offer that to the <style> and <script> tags. but now that you explained it this way im not gonna insist on it

@dummdidumm
Copy link
Member

Closing in favor of the RFC that's about a preprocessor API rework sveltejs/rfcs#56 , making a note there about this feature request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants