Markdown TransformStream

by Hemanth HM

HTML

<script src="https://unpkg.com/[email protected]/lib/marked.js"></script>

Babel + JSX

// Check the browser's console.

const markedTransform = new TransformStream({
    start(controller) {
      c = controller;
    },
    transform(chunk, controller) {
      c.enqueue(marked(new TextDecoder().decode(chunk)));
    }
  })

async function fetchMD() {

  const resp = await fetch('https://gist.githubusercontent.com/PurpleBooth/109311bb0361f32d87a2/raw/824da51d0763e6855c338cc8107b2ff890e7dd43/README-Template.md')
 
  await resp.body
  //.pipeThrough(new TextDecoder())
  .pipeThrough(markedTransform).
  pipeTo(new WritableStream({ write: console.log })) 
}

fetchMD();