summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-highlight/src/getLanguage.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-plugin-highlight/src/getLanguage.js')
-rw-r--r--packages/gitbook-plugin-highlight/src/getLanguage.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-highlight/src/getLanguage.js b/packages/gitbook-plugin-highlight/src/getLanguage.js
new file mode 100644
index 0000000..47b68cf
--- /dev/null
+++ b/packages/gitbook-plugin-highlight/src/getLanguage.js
@@ -0,0 +1,30 @@
+const GitBook = require('gitbook-core');
+const { List } = GitBook.Immutable;
+
+/**
+ * Return language for a code blocks from a list of class names
+ *
+ * @param {Array<String>}
+ * @return {String}
+ */
+function getLanguage(classNames) {
+ return List(classNames)
+ .map(function(cl) {
+ // Markdown
+ if (cl.search('lang-') === 0) {
+ return cl.slice('lang-'.length);
+ }
+
+ // Asciidoc
+ if (cl.search('language-') === 0) {
+ return cl.slice('language-'.length);
+ }
+
+ return null;
+ })
+ .find(function(cl) {
+ return Boolean(cl);
+ });
+}
+
+module.exports = getLanguage;