1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Clean up rules

This commit is contained in:
Laurent Cozic 2020-10-19 16:40:11 +01:00
parent d927a238bb
commit 47c7b864cb
7 changed files with 20 additions and 12 deletions

View File

@ -112,6 +112,7 @@ describe('MdToHtml', function() {
const mdToHtml = newTestMdToHtml({ pluginOptions: pluginOptions });
const assets = await mdToHtml.allAssets(themeStyle(1));
console.info('ASSETS', assets);
expect(assets.length).toBe(2);
expect(assets[1].mime).toBe('text/css');

View File

@ -696,7 +696,9 @@ export default class BaseApplication {
initArgs = Object.assign(initArgs, extraFlags);
this.logger_.addTarget(TargetType.File, { path: `${profileDir}/log.txt` });
if (Setting.value('env') === 'dev' && !shim.isTestingEnv()) {
// this.logger_.addTarget(TargetType.Console, { level: Logger.LEVEL_DEBUG });
}
this.logger_.setLevel(initArgs.logLevel);
reg.setLogger(this.logger_);

View File

@ -5,8 +5,13 @@ import { fileExtension } from './pathUtils';
const MarkdownIt = require('markdown-it');
const md5 = require('md5');
interface RendererRule {
install(context:any, ruleOptions:any):any,
assets?(theme:any):any,
}
interface RendererRules {
[pluginName:string]: any,
[pluginName:string]: RendererRule,
}
interface RendererPlugin {
@ -94,7 +99,7 @@ interface PluginContext {
css: any
pluginAssets: any,
cache: any,
};
}
interface RenderResultPluginAsset {
name: string,
@ -183,7 +188,7 @@ export default class MdToHtml {
// `module` is a file that has already been `required()`
public loadExtraRendererRule(id:string, module:any) {
if (this.extraRendererRules_[id]) throw new Error('A renderer rule with this ID has already been loaded: ' + id);
if (this.extraRendererRules_[id]) throw new Error(`A renderer rule with this ID has already been loaded: ${id}`);
this.extraRendererRules_[id] = module;
}
@ -236,8 +241,8 @@ export default class MdToHtml {
if (!this.pluginEnabled(key)) continue;
const rule = rules[key];
if (rule.style) {
assets[key] = rule.style(theme);
if (rule.assets) {
assets[key] = rule.assets(theme);
}
}
@ -386,7 +391,7 @@ export default class MdToHtml {
for (const key in allRules) {
if (!this.pluginEnabled(key)) continue;
const rule = allRules[key];
const ruleInstall = rule.install ? rule.install : rule;
const ruleInstall:Function = rule.install ? rule.install : (rule as any);
markdownIt.use(ruleInstall(context, { ...ruleOptions }));
}

View File

@ -229,5 +229,5 @@ export default {
installRule(md, mdOptions, ruleOptions, context);
};
},
style: pluginAssets[2],
assets: pluginAssets[2],
};

View File

@ -143,5 +143,5 @@ module.exports = {
installRule(md, mdOptions, ruleOptions, context);
};
},
style: fountainCss,
assets: fountainCss,
};

View File

@ -287,5 +287,5 @@ module.exports = {
md.renderer.rules.math_block = blockRenderer;
};
},
style: katexStyle,
assets: katexStyle,
};

View File

@ -45,5 +45,5 @@ export default {
installRule(md, mdOptions, ruleOptions, context);
};
},
style: style,
assets: style,
};