Skip to content

Commit

Permalink
remove python warning from markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
dmca-glasgow committed May 16, 2022
1 parent 1759354 commit fc79b84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions compiler/src/knitr/__test__/knitr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,20 @@ describe('knitr', () => {

expect(ignoreWhitespace(html)).toBe(result);
}, 120000);

it('should remove python warnings from the top of knitr output', async () => {
const { md } = await testProcessor(`
WARNING - All triples will be processed in the same batch (batches_count=1).
When processing large graphs it is recommended to batch the input knowledge
graph instead.
## Introduction
In the first two week of this course we have focused on the use of networks
to analyse social systems, using a mixture of global statistics, node
statistics, and ERGM modelling.
`);

expect(md.trim().startsWith('WARNING')).toBe(false);
});
});
5 changes: 5 additions & 0 deletions compiler/src/knitr/knitr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function reportErrors(response: string, file: VFile) {
async function formatResponse(response: string) {
let md = response;
md = removeCustomPythonBinNotice(md);
md = removePythonWarningMessage(md);
md = addCodeBlockClasses(md);
md = addErrorCodeBlock(md);
md = removeHashSigns(md);
Expand All @@ -165,6 +166,10 @@ function removeCustomPythonBinNotice(md: string) {
return md.replace(/^\$python\s\[1\]\s"\S+"/, '');
}

function removePythonWarningMessage(md: string) {
return md.replace(/^WARNING - .+?[\r\n]+/m, '');
}

function addCodeBlockClasses(md: string) {
return md
.split('\n')
Expand Down

0 comments on commit fc79b84

Please sign in to comment.