<script>
  import snarkdown from "snarkdown";

  export let content = "<b>Markdown:</b> No content? Forgot to #await?";
  export let with_p = true;
  export let using = snarkdown;

  const render = () => {
    // the documentation for snarkdown says do NOT use sanitize, read that
    // as usual there are timing issues so give some default values
    if(with_p && using === snarkdown) {
      // weird that snarkdown doesn't do this, or maybe I just don't see the option
      return content.split("\n\n").map(line => `<p>${using(line)}</p>`).join("\n");
    } else {
      return using(content);
    }

  }

  const html = render();
</script>

<div>
  {@html html}
</div>
