1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00
joplin/ReactNativeClient/lib/resourceUtils.js
Devon Zuegel 172d925f0f Desktop: Fix import interop service (#1887)
* Revert "Revert "Desktop: Add ENEX to HTML export (#1795)""

This reverts commit 50b66cceca.

* Revert "Revert "Desktop, Cli: Fixed interop service so that it still allow auto-detecting importer based on format (required for Cli and for test units)""

This reverts commit c7c57ab2a5.

* Fix the .md importer

* Add comment re future refactor

* Rm importerClass for .md importer

* Fix EnexToMd module name
2019-09-23 22:18:30 +01:00

85 lines
1.9 KiB
JavaScript

const imageMimeTypes = [
'image/cgm',
'image/fits',
'image/g3fax',
'image/gif',
'image/ief',
'image/jp2',
'image/jpeg',
'image/jpm',
'image/jpx',
'image/naplps',
'image/png',
'image/prs.btif',
'image/prs.pti',
'image/t38',
'image/tiff',
'image/tiff-fx',
'image/vnd.adobe.photoshop',
'image/vnd.cns.inf2',
'image/vnd.djvu',
'image/vnd.dwg',
'image/vnd.dxf',
'image/vnd.fastbidsheet',
'image/vnd.fpx',
'image/vnd.fst',
'image/vnd.fujixerox.edmics-mmr',
'image/vnd.fujixerox.edmics-rlc',
'image/vnd.globalgraphics.pgb',
'image/vnd.microsoft.icon',
'image/vnd.mix',
'image/vnd.ms-modi',
'image/vnd.net-fpx',
'image/vnd.sealed.png',
'image/vnd.sealedmedia.softseal.gif',
'image/vnd.sealedmedia.softseal.jpg',
'image/vnd.svf',
'image/vnd.wap.wbmp',
'image/vnd.xiff',
];
const escapeQuotes = (str) => str.replace(/"/g, '"');
const attributesToStr = (attributes) =>
Object.entries(attributes)
.map(([key, value]) => ` ${key}="${escapeQuotes(value)}"`)
.join('');
const ipcProxySendToHost = (id) =>
`onclick="ipcProxySendToHost('joplin://${id}'); return false;"`;
const attachmentElement = ({src, attributes, id}) =>
[
`<a href='#' ${attributesToStr(attributes)} ${ipcProxySendToHost(id)}>`,
` ${attributes.alt || src}`,
'</a>',
].join('');
const imgElement = ({src, attributes}) =>
`<img src="${src}" ${attributesToStr(attributes)} />`;
const audioElement = ({src, alt, id}) =>
[
'<audio controls preload="none" style="width:480px;">',
` <source src="${src}" type="audio/mp4" />`,
' <p>',
' Your browser does not support HTML5 audio.',
' </p>',
'</audio>',
'<p>',
` <a href="${src}" ${ipcProxySendToHost(id)}>`,
` ${alt || src || id || 'Download audio'}`,
' </a>',
'</p>',
].join('');
const resourceUtils = {
imgElement,
audioElement,
attachmentElement,
attributesToStr,
isImageMimeType: (m) => imageMimeTypes.indexOf(m) >= 0,
};
module.exports = resourceUtils;