How to use marked in WKWebView in AppKit

Issue #429

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!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

1
2
3
4
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

Comments