parent
2272f36e59
commit
f36cae36dc
4 changed files with 33 additions and 9 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -5,15 +5,17 @@
|
|||
|
||||
import { getSettings } from './settings';
|
||||
|
||||
declare var vscode: any;
|
||||
|
||||
/**
|
||||
* Post a message to the markdown extension
|
||||
*/
|
||||
export function postMessage(type: string, body: object) {
|
||||
window.parent.postMessage({
|
||||
vscode.postMessage({
|
||||
type,
|
||||
source: getSettings().source,
|
||||
body
|
||||
}, '*');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
|
||||
|
||||
const registerVscodeResourceScheme = (function() {
|
||||
const registerVscodeResourceScheme = (function () {
|
||||
let hasRegistered = false;
|
||||
return () => {
|
||||
if (hasRegistered) {
|
||||
|
@ -174,6 +174,28 @@
|
|||
newDocument.head.appendChild(baseElement);
|
||||
}
|
||||
|
||||
// apply default script
|
||||
if (enableWrappedPostMessage) {
|
||||
const defaultScript = newDocument.createElement('script');
|
||||
defaultScript.textContent = `
|
||||
const vscode = Object.freeze((function() {
|
||||
const originalPostMessage = window.parent.postMessage.bind(window.parent);
|
||||
return {
|
||||
postMessage: function(msg) {
|
||||
return originalPostMessage(msg, '*');
|
||||
}
|
||||
};
|
||||
})());
|
||||
delete window.parent;
|
||||
`;
|
||||
|
||||
if (newDocument.head.hasChildNodes()) {
|
||||
newDocument.head.insertBefore(defaultScript, newDocument.head.firstChild);
|
||||
} else {
|
||||
newDocument.head.appendChild(defaultScript);
|
||||
}
|
||||
}
|
||||
|
||||
// apply default styles
|
||||
const defaultStyles = newDocument.createElement('style');
|
||||
defaultStyles.id = '_defaultStyles';
|
||||
|
|
Loading…
Reference in a new issue