mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-18 20:16:34 +02:00
Server: Add support for sharing notes via a link
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import utils from '../utils';
|
||||
import utils, { ItemIdToUrlHandler } from '../utils';
|
||||
const Entities = require('html-entities').AllHtmlEntities;
|
||||
const htmlentities = new Entities().encode;
|
||||
const urlUtils = require('../urlUtils.js');
|
||||
@@ -12,6 +12,7 @@ export interface Options {
|
||||
plainResourceRendering?: boolean;
|
||||
postMessageSyntax?: string;
|
||||
enableLongPress?: boolean;
|
||||
itemIdToUrl?: ItemIdToUrlHandler;
|
||||
}
|
||||
|
||||
export interface LinkReplacementResult {
|
||||
@@ -65,6 +66,8 @@ export default function(href: string, options: Options = null): LinkReplacementR
|
||||
resourceFullPath: null,
|
||||
};
|
||||
} else {
|
||||
// If we are rendering a note link, we'll get here too, so in that
|
||||
// case "resourceId" would actually be the note ID.
|
||||
href = `joplin://${resourceId}`;
|
||||
if (resourceHrefInfo.hash) href += `#${resourceHrefInfo.hash}`;
|
||||
resourceIdAttr = `data-resource-id='${resourceId}'`;
|
||||
@@ -109,7 +112,13 @@ export default function(href: string, options: Options = null): LinkReplacementR
|
||||
if (title) attrHtml.push(`title='${htmlentities(title)}'`);
|
||||
if (mime) attrHtml.push(`type='${htmlentities(mime)}'`);
|
||||
|
||||
if (options.plainResourceRendering || options.linkRenderingType === 2) {
|
||||
let resourceFullPath = resource && options?.ResourceModel?.fullPath ? options.ResourceModel.fullPath(resource) : null;
|
||||
|
||||
if (resourceId && options.itemIdToUrl) {
|
||||
const url = options.itemIdToUrl(resourceId);
|
||||
attrHtml.push(`href='${htmlentities(url)}'`);
|
||||
resourceFullPath = url;
|
||||
} else if (options.plainResourceRendering || options.linkRenderingType === 2) {
|
||||
icon = '';
|
||||
attrHtml.push(`href='${htmlentities(href)}'`);
|
||||
} else {
|
||||
@@ -121,6 +130,6 @@ export default function(href: string, options: Options = null): LinkReplacementR
|
||||
html: `<a ${attrHtml.join(' ')}>${icon}`,
|
||||
resourceReady: true,
|
||||
resource,
|
||||
resourceFullPath: resource && options?.ResourceModel?.fullPath ? options.ResourceModel.fullPath(resource) : null,
|
||||
resourceFullPath: resourceFullPath,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,12 +9,17 @@ export interface Options {
|
||||
pdfViewerEnabled: boolean;
|
||||
}
|
||||
|
||||
function resourceUrl(resourceFullPath: string): string {
|
||||
if (resourceFullPath.indexOf('http://') === 0 || resourceFullPath.indexOf('https://')) return resourceFullPath;
|
||||
return `file://${toForwardSlashes(resourceFullPath)}`;
|
||||
}
|
||||
|
||||
export default function(link: Link, options: Options) {
|
||||
const resource = link.resource;
|
||||
|
||||
if (!link.resourceReady || !resource || !resource.mime) return '';
|
||||
|
||||
const escapedResourcePath = htmlentities(`file://${toForwardSlashes(link.resourceFullPath)}`);
|
||||
const escapedResourcePath = htmlentities(resourceUrl(link.resourceFullPath));
|
||||
const escapedMime = htmlentities(resource.mime);
|
||||
|
||||
if (options.videoPlayerEnabled && resource.mime.indexOf('video/') === 0) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import htmlUtils from '../../htmlUtils';
|
||||
import utils from '../../utils';
|
||||
|
||||
function renderImageHtml(before: string, src: string, after: string, ruleOptions: RuleOptions) {
|
||||
const r = utils.imageReplacement(ruleOptions.ResourceModel, src, ruleOptions.resources, ruleOptions.resourceBaseUrl);
|
||||
const r = utils.imageReplacement(ruleOptions.ResourceModel, src, ruleOptions.resources, ruleOptions.resourceBaseUrl, ruleOptions.itemIdToUrl);
|
||||
if (typeof r === 'string') return r;
|
||||
if (r) return `<img ${before} ${htmlUtils.attributesHtml(r)} ${after}/>`;
|
||||
return `[Image: ${src}]`;
|
||||
|
||||
@@ -14,7 +14,7 @@ function plugin(markdownIt: any, ruleOptions: RuleOptions) {
|
||||
|
||||
if (!Resource.isResourceUrl(src) || ruleOptions.plainResourceRendering) return defaultRender(tokens, idx, options, env, self);
|
||||
|
||||
const r = utils.imageReplacement(ruleOptions.ResourceModel, src, ruleOptions.resources, ruleOptions.resourceBaseUrl);
|
||||
const r = utils.imageReplacement(ruleOptions.ResourceModel, src, ruleOptions.resources, ruleOptions.resourceBaseUrl, ruleOptions.itemIdToUrl);
|
||||
if (typeof r === 'string') return r;
|
||||
if (r) {
|
||||
let js = '';
|
||||
|
||||
@@ -20,6 +20,7 @@ function plugin(markdownIt: any, ruleOptions: RuleOptions) {
|
||||
plainResourceRendering: ruleOptions.plainResourceRendering,
|
||||
postMessageSyntax: ruleOptions.postMessageSyntax,
|
||||
enableLongPress: ruleOptions.enableLongPress,
|
||||
itemIdToUrl: ruleOptions.itemIdToUrl,
|
||||
});
|
||||
|
||||
ruleOptions.context.currentLinks.push({
|
||||
|
||||
Reference in New Issue
Block a user