From 945d83608a0beaa714f7d9826581bde716238d70 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 2 Mar 2019 23:22:41 +0000 Subject: [PATCH] All: Include injected Mermaid JS only when necessary --- ReactNativeClient/lib/MdToHtml_Mermaid.js | 4 ++-- ReactNativeClient/lib/shim-init-react.js | 9 +++++++++ ReactNativeClient/lib/shim.js | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ReactNativeClient/lib/MdToHtml_Mermaid.js b/ReactNativeClient/lib/MdToHtml_Mermaid.js index e5842eefc..20efea36a 100644 --- a/ReactNativeClient/lib/MdToHtml_Mermaid.js +++ b/ReactNativeClient/lib/MdToHtml_Mermaid.js @@ -1,5 +1,4 @@ const { shim } = require('lib/shim'); -const injectedJs = require('lib/rnInjectedJs/mermaid'); class MdToHtml_Mermaid { @@ -20,7 +19,8 @@ class MdToHtml_Mermaid { } injectedJavaScript() { - return injectedJs + '\n' + 'mermaid.init();'; + const js = shim.injectedJs('mermaid'); + return js ? js + '\n' + 'mermaid.init();' : ''; } async loadAssets() {} diff --git a/ReactNativeClient/lib/shim-init-react.js b/ReactNativeClient/lib/shim-init-react.js index f8c9b1098..468d62f95 100644 --- a/ReactNativeClient/lib/shim-init-react.js +++ b/ReactNativeClient/lib/shim-init-react.js @@ -12,6 +12,10 @@ const { basename, fileExtension } = require('lib/path-utils.js'); const { uuid } = require('lib/uuid.js'); const Resource = require('lib/models/Resource'); +const injectedJs = { + mermaid: require('lib/rnInjectedJs/mermaid'), +}; + function shimInit() { shim.Geolocation = GeolocationReact; shim.setInterval = PoorManIntervals.setInterval; @@ -164,6 +168,11 @@ function shimInit() { return resource; } + shim.injectedJs = function(name) { + if (name in injectedJs) return injectedJs[name]; + return ''; + } + } module.exports = { shimInit }; \ No newline at end of file diff --git a/ReactNativeClient/lib/shim.js b/ReactNativeClient/lib/shim.js index d5416ec92..f3eb0205a 100644 --- a/ReactNativeClient/lib/shim.js +++ b/ReactNativeClient/lib/shim.js @@ -149,5 +149,6 @@ shim.imageFromDataUrl = async function(imageDataUrl, filePath, options = null) { shim.Buffer = null; shim.openUrl = () => { throw new Error('Not implemented'); } shim.waitForFrame = () => { throw new Error('Not implemented'); } +shim.injectedJs = name => ''; module.exports = { shim };