Skip to content

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

@swyxio

Description

@swyxio

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions