Skip to content

Commit

Permalink
feat: 🎸 support markup preprocessing with no tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Jul 7, 2020
1 parent 9156efc commit a1a3360
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/autoProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type AutoPreprocessOptions = {
pug?: TransformerOptions<Options.Pug>;
globalStyle?: Options.GlobalStyle | boolean;
replace?: Options.Replace;

// workaround while we don't have this
// https://github.com/microsoft/TypeScript/issues/17867
[languageName: string]:
Expand Down Expand Up @@ -212,7 +213,7 @@ export function autoPreprocess(

/** If no <template> was found, just return the original markup */
if (!templateMatch) {
return { code: content };
return markupTransformer({ content, attributes: {}, filename });
}

const [fullMatch, attributesStr, templateCode] = templateMatch;
Expand Down
17 changes: 17 additions & 0 deletions test/autoProcess/autoProcess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,21 @@ describe('options', () => {
'<script lang="tomatoScript">tomato</script>',
);
});

it('should be able to use default markup language with template tags', async () => {
const input = `potato`;

const opts = autoPreprocess({
defaults: {
markup: 'potatoScript',
},
potatoScript({ content }) {
return { code: content.replace('potato', 'french-fries') };
},
});

const preprocessed = await preprocess(input, opts);

expect(preprocessed.toString()).toContain('french-fries');
});
});

0 comments on commit a1a3360

Please sign in to comment.