~dricottone/noticable

ref: ef0b3a690cfd0421bbed57a058445814a5fc348c noticable/preload.js -rw-r--r-- 750 bytes
ef0b3a69Dominic Ricottone functional markdown rendering 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const { ipcRenderer } = require('electron');
const md = require('markdown-it')();

// listen to electron
ipcRenderer.on('request-render-markdown', () => {
  console.log("[preload] caught 'request-render-markdown'!");
  console.log("[preload] sending 'request-post-markdown'...");
  window.postMessage({ type: "request-post-markdown" }, "*");
});

// listen to renderer
window.addEventListener("message", (event) => {
  if (event.source != window) return;
  if (event.data.type && (event.data.type == "post-markdown")) {
    console.log("[preload] caught 'post-markdown'!");
    console.log("[preload] sending 'request-insert-html'...");
    window.postMessage({ type: "request-insert-html", text: md.render(event.data.text) }, "*");
  };
}, false);