Skip to content

Commit

Permalink
✨ Allow #embed file replacement and preserve eol-tokens (#5600)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Oct 21, 2023
1 parent c4616b3 commit c6d3fa6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions static/compiler-service.ts
Expand Up @@ -318,20 +318,20 @@ export class CompilerService {
}

public async expandToFiles(source: string): Promise<SourceAndFiles> {
const includes = new IncludeDownloads();
const includesOrEmbeds = new IncludeDownloads();

const includeFind = /^\s*#\s*include\s*["<](https?:\/\/[^">]+)[">]/;
const includeOrEmbedFind = /^\s*#\s*(include|embed)\s*["<](https?:\/\/[^">]+)[">]/;
const lines = source.split('\n');
for (const idx in lines) {
const line = lines[idx];
const match = line.match(includeFind);
const match = line.match(includeOrEmbedFind);
if (match) {
const download = includes.include(match[1]);
lines[idx] = `#include "${download.filename}"`;
const download = includesOrEmbeds.include(match[2]);
lines[idx] = line.replace(includeOrEmbedFind, `#${match[1]} "${download.filename}"`);
}
}

const files: FiledataPair[] = await includes.allDownloadsAsFileDataPairs();
const files: FiledataPair[] = await includesOrEmbeds.allDownloadsAsFileDataPairs();

return {
source: lines.join('\n'),
Expand Down

0 comments on commit c6d3fa6

Please sign in to comment.