summaryrefslogtreecommitdiffstats
path: root/lib/output/getModifiers.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output/getModifiers.js')
-rw-r--r--lib/output/getModifiers.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/output/getModifiers.js b/lib/output/getModifiers.js
new file mode 100644
index 0000000..e649df6
--- /dev/null
+++ b/lib/output/getModifiers.js
@@ -0,0 +1,68 @@
+var Modifiers = require('./modifiers');
+var resolveFileToURL = require('./helper/resolveFileToURL');
+var Api = require('../api');
+var Plugins = require('../plugins');
+var Promise = require('../utils/promise');
+var defaultBlocks = require('../constants/defaultBlocks');
+
+var CODEBLOCK = 'code';
+
+/**
+ Return default modifier to prepare a page for
+ rendering.
+
+ @return {Array<Modifier>}
+*/
+function getModifiers(output, page) {
+ var book = output.getBook();
+ var plugins = output.getPlugins();
+ var glossary = book.getGlossary();
+ var entries = glossary.getEntries();
+ var file = page.getFile();
+
+ // Current file path
+ var currentFilePath = file.getPath();
+
+ // Get TemplateBlock for highlighting
+ var blocks = Plugins.listBlocks(plugins);
+ var code = blocks.get(CODEBLOCK) || defaultBlocks.get(CODEBLOCK);
+
+ // Current context
+ var context = Api.encodeGlobal(output);
+
+ return [
+ // Normalize IDs on headings
+ Modifiers.addHeadingId,
+
+ // Resolve links (.md -> .html)
+ Modifiers.resolveLinks.bind(null,
+ currentFilePath,
+ resolveFileToURL.bind(null, output)
+ ),
+
+ // Resolve images
+ Modifiers.resolveImages.bind(null, currentFilePath),
+
+ // Annotate text with glossary entries
+ Modifiers.annotateText.bind(null, entries),
+
+ // Highlight code blocks using "code" block
+ Modifiers.highlightCode.bind(null, function(lang, source) {
+ return Promise(code.applyBlock({
+ body: source,
+ kwargs: {
+ language: lang
+ }
+ }, context))
+ .then(function(result) {
+ if (result.html === false) {
+ return { text: result.body };
+ } else {
+ return { html: result.body };
+ }
+ });
+ })
+ ];
+}
+
+module.exports = getModifiers;