newman-reporter-html
newman-reporter-html copied to clipboard
New Feature Request: Support markdown in --reporters html output
- Newman Version (can be found via
newman -v
): 3.8.3 - OS details (type, version, and architecture): Win 10 Home
- Are you using Newman as a library, or via the CLI? CLI
- Did you encounter this recently, or has this bug always been there: always
- Expected behaviour: markdown syntax formatted appropriately in newman html report.
- Command / script used to run Newman: newman run %collection% --environment %p_envir% --ssl-client-cert %p_cert% --ssl-client-key %p_key% --ssl-client-passphrase %pp% --reporters html
- Sample collection, and auxilliary files (minus the sensitive details):
- Screenshots (if applicable): N/A
Steps to reproduce the problem:
- Edit collection description to include markdown. Example: Functional Test Plan =================================
Overview
- Export the collection to the newman working directory
- Run the newman script, as indicated in step 5.
Expected: html report displays markdown as html styles (like heading 1). Actual: report shows markdown syntax instead of rendering as html tag format. example: Description: Functional Test Plan ================================= Overview -------- executes a series of API level tests to verify the functional accuracy
care must be taken to sanitise the output.
I was able to successfully apply markdown -> html transformations, in collection and requests descriptions, by implementing a workaround with the help of Remarkable. Just take the default template used by newman and apply the following changes:
Add to <head>
(provide different lib versions if necessary)
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/[email protected]/dist/js/bootstrap.min.js,npm/[email protected]/dist/remarkable.min.js"></script>
Add to end of <body>
<script type="text/javascript">
const remarkable = new Remarkable();
const collectionDescription = document.querySelector("#collectionDescription");
if(collectionDescription) {
collectionDescription.innerHTML = renderHtmlFromMarkdown(collectionDescription.textContent);
}
const requestDescriptions = document.querySelectorAll("#requestDescription");
requestDescriptions.forEach(requestDescription => {
requestDescription.innerHTML = renderHtmlFromMarkdown(requestDescription.textContent);
});
function renderHtmlFromMarkdown(markdown) {
return remarkable.render(trim(markdown));
}
function trim(string) {
return string ? string.replace(/^ +| +$/gm, "") : string;
}
</script>
Don't forget to provide the new template through newman options, e.g.:
"reporter": {
"html": {
"export": "report.html",
"template": "new-template.hbs"
}
}
@kunagpal @shamasis @testmonger Can I work on this?