diff --git a/ElectronClient/app/bridge.js b/ElectronClient/app/bridge.js index 35777f277..a65b24e6e 100644 --- a/ElectronClient/app/bridge.js +++ b/ElectronClient/app/bridge.js @@ -62,6 +62,10 @@ class Bridge { return require('electron').shell.openExternal(url) } + openItem(fullPath) { + return require('electron').shell.openItem(fullPath) + } + } let bridge_ = null; diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index c623431dc..a3a66dc0b 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -58,7 +58,7 @@ class NoteTextComponent extends React.Component { mdToHtml() { if (this.mdToHtml_) return this.mdToHtml_; - this.mdToHtml_ = new MdToHtml(); + this.mdToHtml_ = new MdToHtml({ supportsResourceLinks: true }); return this.mdToHtml_; } @@ -175,6 +175,12 @@ class NoteTextComponent extends React.Component { } else if (msg === 'percentScroll') { this.ignoreNextEditorScroll_ = true; this.setEditorPercentScroll(arg0); + } else if (msg.indexOf('joplin://') === 0) { + const resourceId = msg.substr('joplin://'.length); + Resource.load(resourceId).then((resource) => { + const filePath = Resource.fullPath(resource); + bridge().openItem(filePath); + }); } else { bridge().showMessageBox({ type: 'error', diff --git a/ReactNativeClient/lib/MdToHtml.js b/ReactNativeClient/lib/MdToHtml.js index 6baf69037..4f3ccdb65 100644 --- a/ReactNativeClient/lib/MdToHtml.js +++ b/ReactNativeClient/lib/MdToHtml.js @@ -7,7 +7,10 @@ const md5 = require('md5'); class MdToHtml { - constructor() { + constructor(options = null) { + if (!options) options = {}; + + this.supportsResourceLinks_ = !!options.supportsResourceLinks; this.loadedResources_ = {}; this.cachedContent_ = null; this.cachedContentKey_ = null; @@ -118,15 +121,21 @@ class MdToHtml { } renderOpenLink_(attrs, options) { - const href = this.getAttr_(attrs, 'href'); + let href = this.getAttr_(attrs, 'href'); const title = this.getAttr_(attrs, 'title'); const text = this.getAttr_(attrs, 'text'); + const isResourceUrl = Resource.isResourceUrl(href); - if (Resource.isResourceUrl(href)) { + if (isResourceUrl && !this.supportsResourceLinks_) { // In mobile, links to local resources, such as PDF, etc. currently aren't supported. // Ideally they should be opened in the user's browser. - return '[Resource not yet supported: ' + htmlentities(text) + ']'; + return '[Resource not yet supported: '; //+ htmlentities(text) + ']'; } else { + if (isResourceUrl) { + const resourceId = Resource.pathToId(href); + href = 'joplin://' + resourceId; + } + const js = options.postMessageSyntax + "(" + JSON.stringify(href) + "); return false;"; let output = ""; return output; @@ -135,9 +144,10 @@ class MdToHtml { renderCloseLink_(attrs, options) { const href = this.getAttr_(attrs, 'href'); + const isResourceUrl = Resource.isResourceUrl(href); - if (Resource.isResourceUrl(href)) { - return ''; + if (isResourceUrl && !this.supportsResourceLinks_) { + return ']'; } else { return ''; } diff --git a/ReactNativeClient/lib/components/note-body-viewer.js b/ReactNativeClient/lib/components/note-body-viewer.js index 4bb61b00f..656cf0408 100644 --- a/ReactNativeClient/lib/components/note-body-viewer.js +++ b/ReactNativeClient/lib/components/note-body-viewer.js @@ -18,7 +18,7 @@ class NoteBodyViewer extends Component { } componentWillMount() { - this.mdToHtml_ = new MdToHtml(); + this.mdToHtml_ = new MdToHtml({ supportsResourceLinks: false }); this.isMounted_ = true; }