1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Chore: Apply eslint rules

This commit is contained in:
Laurent Cozic
2019-09-19 22:51:18 +01:00
parent ab29d7e872
commit e648392330
185 changed files with 1196 additions and 1196 deletions

View File

@@ -18,7 +18,7 @@ class MarkupToHtml {
} else if (markupLanguage === Note.MARKUP_LANGUAGE_HTML) {
RendererClass = HtmlToHtml;
} else {
throw new Error('Invalid markup language: ' + markupLanguage);
throw new Error(`Invalid markup language: ${markupLanguage}`);
}
this.renderers_[markupLanguage] = new RendererClass(this.options_);

View File

@@ -81,7 +81,7 @@ class MdToHtml {
try {
let hlCode = '';
const cacheKey = md5(str + '_' + lang);
const cacheKey = md5(`${str}_${lang}`);
if (options.codeHighlightCacheKey && this.cachedHighlightedCode_[cacheKey]) {
hlCode = this.cachedHighlightedCode_[cacheKey];
@@ -97,12 +97,12 @@ class MdToHtml {
if (shim.isReactNative()) {
context.css['hljs'] = shim.loadCssFromJs(options.codeTheme);
} else {
context.cssFiles['hljs'] = 'highlight/styles/' + options.codeTheme;
context.cssFiles['hljs'] = `highlight/styles/${options.codeTheme}`;
}
return '<pre class="hljs"><code>' + hlCode + '</code></pre>';
return `<pre class="hljs"><code>${hlCode}</code></pre>`;
} catch (error) {
return '<pre class="hljs"><code>' + markdownIt.utils.escapeHtml(str) + '</code></pre>';
return `<pre class="hljs"><code>${markdownIt.utils.escapeHtml(str)}</code></pre>`;
}
},
});
@@ -148,7 +148,7 @@ class MdToHtml {
});
for (let key in plugins) {
if (Setting.value('markdown.plugin.' + key)) markdownIt.use(plugins[key].module, plugins[key].options);
if (Setting.value(`markdown.plugin.${key}`)) markdownIt.use(plugins[key].module, plugins[key].options);
}
setupLinkify(markdownIt);
@@ -165,15 +165,15 @@ class MdToHtml {
for (let k in context.assetLoaders) {
if (!context.assetLoaders.hasOwnProperty(k)) continue;
context.assetLoaders[k]().catch(error => {
console.warn('MdToHtml: Error loading assets for ' + k + ': ', error.message);
console.warn(`MdToHtml: Error loading assets for ${k}: `, error.message);
});
}
if (options.userCss) cssStrings.push(options.userCss);
const styleHtml = '<style>' + cssStrings.join('\n') + '</style>';
const styleHtml = `<style>${cssStrings.join('\n')}</style>`;
const html = styleHtml + '<div id="rendered-md">' + renderedBody + '</div>';
const html = `${styleHtml}<div id="rendered-md">${renderedBody}</div>`;
const output = {
html: html,

View File

@@ -28,7 +28,7 @@ function createPrefixTokens(Token, id, checked, label, postMessageSyntax, source
const lineIndex = sourceToken.map && sourceToken.map.length ? sourceToken.map[0] : 99999999;
const checkedString = checked ? 'checked' : 'unchecked';
const labelId = 'cb-label-' + id;
const labelId = `cb-label-${id}`;
const js = `
${postMessageSyntax}('checkboxclick:${checkedString}:${lineIndex}');
@@ -44,7 +44,7 @@ function createPrefixTokens(Token, id, checked, label, postMessageSyntax, source
tokens.push(token);
token = new Token('label_open', 'label', 1);
token.attrs = [['id', labelId], ['for', id], ['class', 'checkbox-label-' + checkedString]];
token.attrs = [['id', labelId], ['for', id], ['class', `checkbox-label-${checkedString}`]];
tokens.push(token);
if (label) {
@@ -94,7 +94,7 @@ function installRule(markdownIt, mdOptions, ruleOptions, context) {
checkboxIndex_++;
const checked = matches[1] !== ' ';
const id = 'md-checkbox-' + checkboxIndex_;
const id = `md-checkbox-${checkboxIndex_}`;
const label = matches.length >= 3 ? matches[2] : '';
// Prepend the text content with the checkbox markup and the opening <label> tag

View File

@@ -5,8 +5,8 @@ const utils = require('../../utils');
function renderImageHtml(before, src, after, ruleOptions) {
const r = utils.imageReplacement(src, ruleOptions.resources, ruleOptions.resourceBaseUrl);
if (typeof r === 'string') return r;
if (r) return '<img ' + before + ' ' + htmlUtils.attributesHtml(r) + ' ' + after + '/>';
return '[Image: ' + src + ']';
if (r) return `<img ${before} ${htmlUtils.attributesHtml(r)} ${after}/>`;
return `[Image: ${src}]`;
}
function installRule(markdownIt, mdOptions, ruleOptions) {

View File

@@ -14,7 +14,7 @@ function installRule(markdownIt, mdOptions, ruleOptions) {
const r = utils.imageReplacement(src, ruleOptions.resources, ruleOptions.resourceBaseUrl);
if (typeof r === 'string') return r;
if (r) return '<img data-from-md ' + htmlUtils.attributesHtml(Object.assign({}, r, { title: title })) + '/>';
if (r) return `<img data-from-md ${htmlUtils.attributesHtml(Object.assign({}, r, { title: title }))}/>`;
return defaultRender(tokens, idx, options, env, self);
};

View File

@@ -185,7 +185,7 @@ function math_block(state, start, end, silent) {
token = state.push('math_block', 'math', 0);
token.block = true;
token.content = (firstLine && firstLine.trim() ? firstLine + '\n' : '') + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : '');
token.content = (firstLine && firstLine.trim() ? `${firstLine}\n` : '') + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : '');
token.map = [start, state.line];
token.markup = '$$';
return true;
@@ -213,11 +213,11 @@ module.exports = function(context) {
if (shim.isReactNative()) {
// Fonts must go under the resourceDir directory because this is the baseUrl of NoteBodyViewer
const baseDir = Setting.value('resourceDir');
await shim.fsDriver().mkdir(baseDir + '/fonts');
await shim.fsDriver().mkdir(`${baseDir}/fonts`);
await shim.fetchBlob('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta1/fonts/KaTeX_Main-Regular.woff2', { overwrite: false, path: baseDir + '/fonts/KaTeX_Main-Regular.woff2' });
await shim.fetchBlob('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta1/fonts/KaTeX_Math-Italic.woff2', { overwrite: false, path: baseDir + '/fonts/KaTeX_Math-Italic.woff2' });
await shim.fetchBlob('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta1/fonts/KaTeX_Size1-Regular.woff2', { overwrite: false, path: baseDir + '/fonts/KaTeX_Size1-Regular.woff2' });
await shim.fetchBlob('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta1/fonts/KaTeX_Main-Regular.woff2', { overwrite: false, path: `${baseDir}/fonts/KaTeX_Main-Regular.woff2` });
await shim.fetchBlob('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta1/fonts/KaTeX_Math-Italic.woff2', { overwrite: false, path: `${baseDir}/fonts/KaTeX_Math-Italic.woff2` });
await shim.fetchBlob('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta1/fonts/KaTeX_Size1-Regular.woff2', { overwrite: false, path: `${baseDir}/fonts/KaTeX_Size1-Regular.woff2` });
}
// eslint-disable-next-line require-atomic-updates
@@ -268,7 +268,7 @@ module.exports = function(context) {
var katexBlock = function(latex) {
options.displayMode = true;
try {
return '<p>' + renderToStringWithCache(latex, options) + '</p>';
return `<p>${renderToStringWithCache(latex, options)}</p>`;
} catch (error) {
if (options.throwOnError) {
console.log(error);
@@ -279,7 +279,7 @@ module.exports = function(context) {
var blockRenderer = function(tokens, idx) {
addContextAssets();
return katexBlock(tokens[idx].content) + '\n';
return `${katexBlock(tokens[idx].content)}\n`;
};
md.inline.ruler.after('escape', 'math_inline', math_inline);

View File

@@ -22,11 +22,11 @@ function installRule(markdownIt, mdOptions, ruleOptions) {
if (result && resourceStatus !== 'ready') {
const icon = utils.resourceStatusFile(resourceStatus);
return '<a class="not-loaded-resource resource-status-' + resourceStatus + '" data-resource-id="' + resourceId + '">' + '<img src="data:image/svg+xml;utf8,' + htmlentities(icon) + '"/>';
return `<a class="not-loaded-resource resource-status-${resourceStatus}" data-resource-id="${resourceId}">` + `<img src="data:image/svg+xml;utf8,${htmlentities(icon)}"/>`;
} else {
href = 'joplin://' + resourceId;
if (resourceHrefInfo.hash) href += '#' + resourceHrefInfo.hash;
resourceIdAttr = 'data-resource-id=\'' + resourceId + '\'';
href = `joplin://${resourceId}`;
if (resourceHrefInfo.hash) href += `#${resourceHrefInfo.hash}`;
resourceIdAttr = `data-resource-id='${resourceId}'`;
icon = '<span class="resource-icon"></span>';
}
} else {
@@ -35,9 +35,9 @@ function installRule(markdownIt, mdOptions, ruleOptions) {
hrefAttr = href;
}
let js = ruleOptions.postMessageSyntax + '(' + JSON.stringify(href) + '); return false;';
let js = `${ruleOptions.postMessageSyntax}(${JSON.stringify(href)}); return false;`;
if (hrefAttr.indexOf('#') === 0 && href.indexOf('#') === 0) js = ''; // If it's an internal anchor, don't add any JS since the webview is going to handle navigating to the right place
return '<a data-from-md ' + resourceIdAttr + ' title=\'' + htmlentities(title) + '\' href=\'' + hrefAttr + '\' onclick=\'' + js + '\'>' + icon;
return `<a data-from-md ${resourceIdAttr} title='${htmlentities(title)}' href='${hrefAttr}' onclick='${js}'>${icon}`;
};
}

View File

@@ -12,29 +12,29 @@ module.exports = function(style, options) {
const css =
`
body {
font-size: ` +
style.htmlFontSize +
`;
color: ` +
style.htmlColor +
`;
line-height: ` +
style.htmlLineHeight +
`;
background-color: ` +
style.htmlBackgroundColor +
`;
font-family: ` +
fontFamily +
`;
padding-bottom: ` +
options.paddingBottom +
`;
font-size: ${
style.htmlFontSize
};
color: ${
style.htmlColor
};
line-height: ${
style.htmlLineHeight
};
background-color: ${
style.htmlBackgroundColor
};
font-family: ${
fontFamily
};
padding-bottom: ${
options.paddingBottom
};
}
strong {
color: ` +
style.colorBright +
`
color: ${
style.colorBright
}
}
::-webkit-scrollbar {
width: 7px;
@@ -82,9 +82,9 @@ module.exports = function(style, options) {
h1 {
font-size: 1.5em;
font-weight: bold;
border-bottom: 1px solid ` +
style.htmlDividerColor +
`;
border-bottom: 1px solid ${
style.htmlDividerColor
};
padding-bottom: .3em;
}
h2 {
@@ -100,9 +100,9 @@ module.exports = function(style, options) {
font-weight: bold;
}
a {
color: ` +
style.htmlLinkColor +
`;
color: ${
style.htmlLinkColor
};
}
ul, ol {
padding-left: 0;
@@ -123,16 +123,16 @@ module.exports = function(style, options) {
width: 1.15em;
height: 1.45em;
margin-right: 0.4em;
background-color: ` +
style.htmlColor +
`;
background-color: ${
style.htmlColor
};
/* Awesome Font file */
-webkit-mask: url("data:image/svg+xml;utf8,<svg viewBox='0 0 1536 1892' xmlns='http://www.w3.org/2000/svg'><path d='M288 128C129 128 0 257 0 416v960c0 159 129 288 288 288h960c159 0 288-129 288-288V416c0-159-129-288-288-288H288zm449.168 236.572l263.434.565 263.431.562.584 73.412.584 73.412-42.732 1.504c-23.708.835-47.002 2.774-52.322 4.36-14.497 4.318-23.722 12.902-29.563 27.51l-5.12 12.802-1.403 291.717c-1.425 295.661-1.626 302.586-9.936 343.043-15.2 74-69.604 150.014-142.197 198.685-58.287 39.08-121.487 60.47-208.155 70.45-22.999 2.648-122.228 2.636-141.976-.024l-.002.006c-69.785-9.377-108.469-20.202-154.848-43.332-85.682-42.73-151.778-116.991-177.537-199.469-10.247-32.81-11.407-40.853-11.375-78.754.026-31.257.76-39.15 5.024-54.043 8.94-31.228 20.912-51.733 43.56-74.62 27.312-27.6 55.812-40.022 95.524-41.633 37.997-1.542 63.274 5.024 87.23 22.66 15.263 11.235 30.828 33.238 39.537 55.884 5.52 14.355 5.949 18.31 7.549 69.569 1.675 53.648 3.05 63.99 11.674 87.785 11.777 32.499 31.771 55.017 61.46 69.22 26.835 12.838 47.272 16.785 80.56 15.56 21.646-.798 30.212-2.135 43.208-6.741 38.682-13.708 70.96-44.553 86.471-82.635 16.027-39.348 15.995-38.647 15.947-361.595-.042-283.26-.09-286.272-4.568-296.153-10.958-24.171-22.488-28.492-81.074-30.377l-42.969-1.38v-147.95z'/></svg>");
}
blockquote {
border-left: 4px solid ` +
style.htmlCodeBorderColor +
`;
border-left: 4px solid ${
style.htmlCodeBorderColor
};
padding-left: 1.2em;
margin-left: 0;
opacity: .7;
@@ -140,77 +140,77 @@ module.exports = function(style, options) {
table {
text-align: left-align;
border-collapse: collapse;
border: 1px solid ` +
style.htmlCodeBorderColor +
`;
background-color: ` +
style.htmlBackgroundColor +
`;
border: 1px solid ${
style.htmlCodeBorderColor
};
background-color: ${
style.htmlBackgroundColor
};
}
td, th {
padding: .5em 1em .5em 1em;
font-size: ` +
style.htmlFontSize +
`;
color: ` +
style.htmlColor +
`;
font-family: ` +
fontFamily +
`;
font-size: ${
style.htmlFontSize
};
color: ${
style.htmlColor
};
font-family: ${
fontFamily
};
}
td {
border: 1px solid ` +
style.htmlCodeBorderColor +
`;
border: 1px solid ${
style.htmlCodeBorderColor
};
}
th {
border: 1px solid ` +
style.htmlCodeBorderColor +
`;
border-bottom: 2px solid ` +
style.htmlCodeBorderColor +
`;
background-color: ` +
style.htmlTableBackgroundColor +
`;
border: 1px solid ${
style.htmlCodeBorderColor
};
border-bottom: 2px solid ${
style.htmlCodeBorderColor
};
background-color: ${
style.htmlTableBackgroundColor
};
}
tr:nth-child(even) {
background-color: ` +
style.htmlTableBackgroundColor +
`;
background-color: ${
style.htmlTableBackgroundColor
};
}
tr:hover {
background-color: ` +
style.raisedBackgroundColor +
`;
background-color: ${
style.raisedBackgroundColor
};
}
hr {
border: none;
border-bottom: 2px solid ` +
style.htmlDividerColor +
`;
border-bottom: 2px solid ${
style.htmlDividerColor
};
}
img {
max-width: 100%;
height: auto;
}
.inline-code {
border: 1px solid ` +
style.htmlCodeBorderColor +
`;
background-color: ` +
style.htmlCodeBackgroundColor +
`;
border: 1px solid ${
style.htmlCodeBorderColor
};
background-color: ${
style.htmlCodeBackgroundColor
};
padding-right: .2em;
padding-left: .2em;
border-radius: .25em;
color: ` +
style.htmlCodeColor +
`;
font-size: ` +
style.htmlCodeFontSize +
`;
color: ${
style.htmlCodeColor
};
font-size: ${
style.htmlCodeFontSize
};
}
.highlighted-keyword {

View File

@@ -67,7 +67,7 @@ utils.resourceStatusFile = function(state) {
if (state === 'encrypted') return utils.loaderImage();
if (state === 'error') return utils.errorImage();
throw new Error('Unknown state: ' + state);
throw new Error(`Unknown state: ${state}`);
};
utils.resourceStatus = function(resourceInfo) {
@@ -103,12 +103,12 @@ utils.imageReplacement = function(src, resources, resourceBaseUrl) {
if (resourceStatus !== 'ready') {
const icon = utils.resourceStatusImage(resourceStatus);
return '<div class="not-loaded-resource resource-status-' + resourceStatus + '" data-resource-id="' + resourceId + '">' + '<img src="data:image/svg+xml;utf8,' + htmlentities(icon) + '"/>' + '</div>';
return `<div class="not-loaded-resource resource-status-${resourceStatus}" data-resource-id="${resourceId}">` + `<img src="data:image/svg+xml;utf8,${htmlentities(icon)}"/>` + '</div>';
}
const mime = resource.mime ? resource.mime.toLowerCase() : '';
if (Resource.isSupportedImageMimeType(mime)) {
let newSrc = './' + Resource.filename(resource);
let newSrc = `./${Resource.filename(resource)}`;
if (resourceBaseUrl) newSrc = resourceBaseUrl + newSrc;
return {
'data-resource-id': resource.id,

View File

@@ -4,7 +4,7 @@ let manualDownloadResourceElements = [];
webviewLib.onUnloadedResourceClick = function(event) {
const resourceId = event.currentTarget.getAttribute('data-resource-id');
webviewLib.options_.postMessage('markForDownload:' + resourceId);
webviewLib.options_.postMessage(`markForDownload:${resourceId}`);
};
webviewLib.setupResourceManualDownload = function() {
@@ -76,7 +76,7 @@ webviewLib.logEnabledEventHandler = function(fn) {
try {
return fn(event);
} catch (error) {
webviewLib.options_.postMessage('error:' + JSON.stringify(webviewLib.cloneError(error)));
webviewLib.options_.postMessage(`error:${JSON.stringify(webviewLib.cloneError(error))}`);
throw error;
}
};