import { Link } from '../MdToHtml'; import { toForwardSlashes } from '../pathUtils'; const Entities = require('html-entities').AllHtmlEntities; const htmlentities = new Entities().encode; export interface Options { audioPlayerEnabled: boolean; videoPlayerEnabled: boolean; 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(resourceUrl(link.resourceFullPath)); const escapedMime = htmlentities(resource.mime); if (options.videoPlayerEnabled && resource.mime.indexOf('video/') === 0) { return ` `; } if (options.audioPlayerEnabled && resource.mime.indexOf('audio/') === 0) { return ` `; } if (options.pdfViewerEnabled && resource.mime === 'application/pdf') { return ``; } return ''; }