|
@@ -1,34 +1,65 @@
|
|
var Prism = require('prismjs');
|
|
var Prism = require('prismjs');
|
|
-var languages = require('prism-languages');
|
|
|
|
|
|
+var languages = require('prismjs').languages;
|
|
var path = require('path');
|
|
var path = require('path');
|
|
|
|
|
|
-var prismCSS = require.resolve('prismjs/themes/prism.css');
|
|
|
|
-
|
|
|
|
var DEFAULT_LANGUAGE = 'markup';
|
|
var DEFAULT_LANGUAGE = 'markup';
|
|
var MAP_LANGUAGES = {
|
|
var MAP_LANGUAGES = {
|
|
'py': 'python',
|
|
'py': 'python',
|
|
'js': 'javascript',
|
|
'js': 'javascript',
|
|
- 'json': 'javascript',
|
|
|
|
'rb': 'ruby',
|
|
'rb': 'ruby',
|
|
'csharp': 'cs',
|
|
'csharp': 'cs',
|
|
'html': 'markup'
|
|
'html': 'markup'
|
|
};
|
|
};
|
|
|
|
|
|
-var assets = {
|
|
|
|
- assets: path.dirname(prismCSS),
|
|
|
|
- css: [path.basename(prismCSS)]
|
|
|
|
-};
|
|
|
|
|
|
+function getAssets() {
|
|
|
|
+
|
|
|
|
+ var book = this;
|
|
|
|
+
|
|
|
|
+ var cssFiles = this.config.get('pluginsConfig.prism.css', []);
|
|
|
|
+ var cssFolder = null;
|
|
|
|
+ var cssNames = [];
|
|
|
|
+
|
|
|
|
+ if(cssFiles.length === 0) {
|
|
|
|
+ cssFiles.push('prismjs/themes/prism.css');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cssFiles.forEach(function(cssFile) {
|
|
|
|
+ var cssPath = require.resolve(cssFile);
|
|
|
|
+ cssFolder = path.dirname(cssPath);
|
|
|
|
+ cssName = path.basename(cssPath);
|
|
|
|
+ cssNames.push(cssName);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ var assets = {
|
|
|
|
+ assets: cssFolder,
|
|
|
|
+ css: cssNames
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return assets;
|
|
|
|
+}
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
- book: assets,
|
|
|
|
- ebook: assets,
|
|
|
|
|
|
+ book: getAssets,
|
|
|
|
+ ebook: getAssets,
|
|
blocks: {
|
|
blocks: {
|
|
code: function(block) {
|
|
code: function(block) {
|
|
|
|
+
|
|
var highlighted = '';
|
|
var highlighted = '';
|
|
|
|
|
|
// Normalize language id
|
|
// Normalize language id
|
|
var lang = block.kwargs.language || DEFAULT_LANGUAGE;
|
|
var lang = block.kwargs.language || DEFAULT_LANGUAGE;
|
|
lang = MAP_LANGUAGES[lang] || lang;
|
|
lang = MAP_LANGUAGES[lang] || lang;
|
|
|
|
+
|
|
|
|
+ // Try and find the language definition in components folder
|
|
|
|
+ if (!languages[lang]) {
|
|
|
|
+ try {
|
|
|
|
+ require('prismjs/components/prism-' + lang + '.js');
|
|
|
|
+ }catch(e) {
|
|
|
|
+ console.warn('Failed to load prism syntax: '+ lang);
|
|
|
|
+ console.warn(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!languages[lang]) lang = DEFAULT_LANGUAGE;
|
|
if (!languages[lang]) lang = DEFAULT_LANGUAGE;
|
|
|
|
|
|
// Check against html, prism "markup" works for this
|
|
// Check against html, prism "markup" works for this
|
|
@@ -48,4 +79,4 @@ module.exports = {
|
|
return highlighted;
|
|
return highlighted;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-};
|
|
|
|
|
|
+};
|