Skip to content

Commit

Permalink
Do not crash on inlining exception
Browse files Browse the repository at this point in the history
  • Loading branch information
offbynull committed Jul 6, 2019
1 parent f5174f5 commit 8dda384
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/index.ts
Expand Up @@ -77,37 +77,45 @@ inputWatcher.on('change', () => {
FileSystemExtra.copySync(inputPath, tempRenderPath);

// Render input.md to output.html
const inputFileSize = FileSystem.statSync(tempRenderPath + '/input.md').size;
const inputBuffer = FileSystem.readFileSync(tempRenderPath + '/input.md', null);
const input = inputBuffer.toString('utf8');
let markdownGenerationError = false;
const output = (() => {
const mdInput = FileSystem.readFileSync(tempRenderPath + '/input.md', { encoding: 'utf8'});
const mdOutput = (() => {
try {
return new Markdown('', tempRenderPath).render(input);
return new Markdown('', tempRenderPath).render(mdInput);
} catch (err) {
markdownGenerationError = true;
return injectHtmlErrorOverlay(lastSuccessfulOutput, err.toString());
FileSystem.writeFileSync(
outputPath + '/output.html',
injectHtmlErrorOverlay(lastSuccessfulOutput, err.toString()),
{ encoding: 'utf8' }
);
bs.reload('output.html');
return undefined;
}
})();
if (mdOutput === undefined) {
return;
}

// Inline rendered file
inlineHtml(output, tempRenderPath,
(result) => {
if (markdownGenerationError === false) {
lastSuccessfulOutput = result;
try {
inlineHtml(mdOutput, tempRenderPath,
(inlineOutput) => {
FileSystem.writeFileSync(
outputPath + '/output.html',
inlineOutput,
{ encoding: 'utf8' }
);
bs.reload('output.html'); // ask the browser to reload
}

const outputBuffer = Buffer.from(result, 'utf8');
FileSystem.writeFileSync(outputPath + '/output.html', outputBuffer.toString('utf8'));
const outputFileSize = FileSystem.statSync(outputPath + '/output.html').size;

console.log('input_filesize:' + inputFileSize
+ ' input_readsize:' + inputBuffer.byteLength
+ ' output_writesize: ' + outputBuffer.byteLength
+ ' output_filesize: ' + outputFileSize);
bs.reload('output.html'); // ask the browser to reload
}
);
);
} catch (err) {
FileSystem.writeFileSync(
outputPath + '/output.html',
injectHtmlErrorOverlay(lastSuccessfulOutput, err.toString()),
{ encoding: 'utf8' }
);
bs.reload('output.html');
return;
}
});

bs.init({
Expand Down

0 comments on commit 8dda384

Please sign in to comment.