fix(client): stop injecting extra comments into preview (#44723)

This commit is contained in:
Oliver Eyton-Williams
2022-01-13 22:25:55 +01:00
committed by GitHub
parent e97920ae9c
commit a00788417a
2 changed files with 8 additions and 18 deletions

View File

@ -14,36 +14,28 @@ import {
transformContents
} from '../../../../../utils/polyvinyl';
const htmlCatch = '\n<!--fcc-->\n';
const jsCatch = '\n;/*fcc*/\n';
const cssCatch = '\n/*fcc*/\n';
const defaultTemplate = ({ source }) => {
return `
<body id='display-body'>
<!-- fcc-start-source -->
${source}
<!-- fcc-end-source -->
${source}
</body>`;
};
const wrapInScript = partial(
transformContents,
content => `${htmlCatch}<script>${content}${jsCatch}</script>`
content => `<script>${content}</script>`
);
const wrapInStyle = partial(
transformContents,
content => `${htmlCatch}<style>${content}${cssCatch}</style>`
content => `<style>${content}</style>`
);
const setExtToHTML = partial(setExt, 'html');
const padContentWithJsCatch = partial(compileHeadTail, jsCatch);
const padContentWithCssCatch = partial(compileHeadTail, cssCatch);
// const padContentWithHTMLCatch = partial(compileHeadTail, htmlCatch);
const concatHeadTail = partial(compileHeadTail, '');
export const jsToHtml = cond([
[
matchesProperty('ext', 'js'),
flow(padContentWithJsCatch, wrapInScript, setExtToHTML)
flow(concatHeadTail, wrapInScript, setExtToHTML)
],
[stubTrue, identity]
]);
@ -51,7 +43,7 @@ export const jsToHtml = cond([
export const cssToHtml = cond([
[
matchesProperty('ext', 'css'),
flow(padContentWithCssCatch, wrapInStyle, setExtToHTML)
flow(concatHeadTail, wrapInStyle, setExtToHTML)
],
[stubTrue, identity]
]);
@ -96,12 +88,12 @@ A required file can not have both a src and a link: src = ${src}, link = ${link}
const indexHtml = findIndexHtml(challengeFiles);
const source = challengeFiles.reduce((source, challengeFile) => {
if (!indexHtml) return source.concat(challengeFile.contents, htmlCatch);
if (!indexHtml) return source.concat(challengeFile.contents);
if (
indexHtml.importedFiles.includes(challengeFile.history[0]) ||
wasHtmlFile(challengeFile)
) {
return source.concat(challengeFile.contents, htmlCatch);
return source.concat(challengeFile.contents);
} else {
return source;
}

View File

@ -105,8 +105,6 @@ async function loadPresetReact() {
const babelTransformCode = options => code =>
Babel.transform(code, options).code;
// const sourceReg =
// /(<!-- fcc-start-source -->)([\s\S]*?)(?=<!-- fcc-end-source -->)/g;
const NBSPReg = new RegExp(String.fromCharCode(160), 'g');
const testJS = matchesProperty('ext', 'js');