diff --git a/ElectronClient/app/package.json b/ElectronClient/app/package.json index 844fa5458..0880f41a3 100644 --- a/ElectronClient/app/package.json +++ b/ElectronClient/app/package.json @@ -97,6 +97,7 @@ "es6-promise-pool": "^2.5.0", "file-uri-to-path": "^1.0.0", "follow-redirects": "^1.5.0", + "font-awesome-filetypes": "^2.1.0", "form-data": "^2.3.2", "formatcoords": "^1.1.3", "fs-extra": "^5.0.0", diff --git a/ReactNativeClient/lib/renderers/MdToHtml/rules/link_open.js b/ReactNativeClient/lib/renderers/MdToHtml/rules/link_open.js index 7829f2459..d8fcc4b11 100644 --- a/ReactNativeClient/lib/renderers/MdToHtml/rules/link_open.js +++ b/ReactNativeClient/lib/renderers/MdToHtml/rules/link_open.js @@ -2,6 +2,7 @@ const Entities = require('html-entities').AllHtmlEntities; const htmlentities = new Entities().encode; const utils = require('../../utils'); const urlUtils = require('lib/urlUtils.js'); +const { getClassNameForMimeType } = require('font-awesome-filetypes'); function installRule(markdownIt, mdOptions, ruleOptions) { markdownIt.renderer.rules.link_open = function(tokens, idx) { @@ -33,7 +34,15 @@ function installRule(markdownIt, mdOptions, ruleOptions) { href = `joplin://${resourceId}`; if (resourceHrefInfo.hash) href += `#${resourceHrefInfo.hash}`; resourceIdAttr = `data-resource-id='${resourceId}'`; - icon = ''; + + let iconType = getClassNameForMimeType(mime); + if (!mime) { + iconType = 'fa-joplin'; + } + // Icons are defined in lib/renderers/noteStyle.js using inline svg + // The icons are taken from fork-awesome but use the font-awesome naming scheme in order + // to be more compatible with the getClass library + icon = ``; } } else { // If the link is a plain URL (as opposed to a resource link), set the href to the actual @@ -48,6 +57,7 @@ function installRule(markdownIt, mdOptions, ruleOptions) { } module.exports = function(context, ruleOptions) { + return function(md, mdOptions) { installRule(md, mdOptions, ruleOptions); }; diff --git a/ReactNativeClient/lib/renderers/noteStyle.js b/ReactNativeClient/lib/renderers/noteStyle.js index 5d1a05d05..6d3f2f985 100644 --- a/ReactNativeClient/lib/renderers/noteStyle.js +++ b/ReactNativeClient/lib/renderers/noteStyle.js @@ -112,10 +112,53 @@ module.exports = function(style, options) { width: 1.15em; height: 1.45em; margin-right: 0.4em; - background-color: ${style.htmlColor}; + background-color: ${style.htmlLinkColor}; + } + /* These icons are obtained from the wonderful ForkAwesome project by copying the src svgs + * into the css classes below. + * svgs are obtained from https://github.com/ForkAwesome/Fork-Awesome/tree/master/src/icons/svg + * instead of the svg width, height property you must use a viewbox here, in general 0 0 1536 1992 is a good choice + * each line begins with the pre-amble -webkit-mask: url("data:image/svg+xml;utf8, + * and of course finishes with "); + * */ + .fa-joplin { /* Awesome Font file */ -webkit-mask: url("data:image/svg+xml;utf8,"); } + .fa-file-image { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-pdf { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-word { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-powerpoint { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-excel { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-audio { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-video { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-archive { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-code { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file-alt, .fa-file-csv { + /* fork-awesome doesn't have csv so we use the text icon */ + -webkit-mask: url("data:image/svg+xml;utf8,"); + } + .fa-file { + -webkit-mask: url("data:image/svg+xml;utf8,"); + } blockquote { border-left: 4px solid ${style.htmlCodeBorderColor}; padding-left: 1.2em; diff --git a/ReactNativeClient/package.json b/ReactNativeClient/package.json index e7c5d1df2..c8db2007f 100644 --- a/ReactNativeClient/package.json +++ b/ReactNativeClient/package.json @@ -16,6 +16,7 @@ "diacritics": "^1.3.0", "diff-match-patch": "^1.0.4", "events": "^1.1.1", + "font-awesome-filetypes": "^2.1.0", "form-data": "^2.1.4", "highlight.js": "^9.15.6", "html-entities": "^1.2.1",