Adds a markup parameter to Preprocessors.

This parameter will hold the entire processed source file up until the
current preprocessor.

Fixes #4912
pull/4913/head
Maarten van Sambeek 5 years ago
parent f46b38a308
commit 17a3e28855

@ -17,6 +17,7 @@ export type Preprocessor = (options: {
content: string;
attributes: Record<string, string | boolean>;
filename?: string;
markup: string;
}) => Processed | Promise<Processed>;
function parse_attributes(str: string) {
@ -103,7 +104,8 @@ export default async function preprocess(
const processed = await fn({
content,
attributes: parse_attributes(attributes),
filename
filename,
markup: source
});
if (processed && processed.dependencies) dependencies.push(...processed.dependencies);
return processed ? `<script${attributes}>${processed.code}</script>` : match;
@ -122,7 +124,8 @@ export default async function preprocess(
const processed: Processed = await fn({
content,
attributes: parse_attributes(attributes),
filename
filename,
markup: source
});
if (processed && processed.dependencies) dependencies.push(...processed.dependencies);
return processed ? `<style${attributes}>${processed.code}</style>` : match;

@ -0,0 +1,12 @@
export default {
preprocess: {
script: ({ content, markup }) => {
return {
code: content.replace(
"__HASDIVTAG__",
markup && /<div\/>/g.test(markup) ? "'yes'" : "'no'"
),
};
},
},
};

@ -0,0 +1,5 @@
<script>
console.log(__HASDIVTAG__);
</script>
<div/>

@ -0,0 +1,5 @@
<script>
console.log('yes');
</script>
<div/>
Loading…
Cancel
Save