postmanlabs / newman-reporter-html

Apache License 2.0
82 stars 86 forks source link

New Feature Request: Support markdown in --reporters html output #186

Open testmonger opened 6 years ago

testmonger commented 6 years ago
  1. Newman Version (can be found via newman -v): 3.8.3
  2. OS details (type, version, and architecture): Win 10 Home
  3. Are you using Newman as a library, or via the CLI? CLI
  4. Did you encounter this recently, or has this bug always been there: always
  5. Expected behaviour: markdown syntax formatted appropriately in newman html report.
  6. 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
  7. Sample collection, and auxilliary files (minus the sensitive details):
  8. Screenshots (if applicable): N/A

Steps to reproduce the problem:

  1. Edit collection description to include markdown. Example: Functional Test Plan

Overview

  1. Export the collection to the newman working directory
  2. 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

shamasis commented 6 years ago

care must be taken to sanitise the output.

filipeamaral commented 6 years ago

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/jquery@3.3.1,npm/bootstrap@3.3.7/dist/js/bootstrap.min.js,npm/remarkable@1.7.1/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"
    }
}
aquibbaig commented 4 years ago

@kunagpal @shamasis @testmonger Can I work on this?