How to use marked in WKWebView in AppKit

Issue #429

Use https://github.com/markedjs/marked

<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>Marked in the browser</title>
</head>
<body>
  <div id="content"></div>
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  <script>
    document.getElementById('content').innerHTML =
      marked(`# Marked in the browser\n\nRendered by **marked**.`);
  </script>
</body>
</html>

Should use back tick instead of ' to deal with multiline string, and escape back tick

let markdown = markdown.replacingOccurrences(of: "`", with: "\\`")
marked(`\(markdown)`);

webView.loadHTMLString(string, baseURL: nil)

For WKWebView to load even local content, need to enable Outgoing connections, and maybe Incoming connections in Sandbox

Written by

I’m open source contributor, writer, speaker and product maker.

Start the conversation