1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Electron: Supports non-image files in notes

This commit is contained in:
Laurent Cozic 2017-11-12 16:33:34 +00:00
parent 6e9e3fc9bd
commit e48d2ed64b
4 changed files with 28 additions and 8 deletions

View File

@ -62,6 +62,10 @@ class Bridge {
return require('electron').shell.openExternal(url)
}
openItem(fullPath) {
return require('electron').shell.openItem(fullPath)
}
}
let bridge_ = null;

View File

@ -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',

View File

@ -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 = "<a title='" + htmlentities(title) + "' href='#' onclick='" + js + "'>";
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 '</a>';
}

View File

@ -18,7 +18,7 @@ class NoteBodyViewer extends Component {
}
componentWillMount() {
this.mdToHtml_ = new MdToHtml();
this.mdToHtml_ = new MdToHtml({ supportsResourceLinks: false });
this.isMounted_ = true;
}