summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-03-18 13:06:10 -0600
committerGitHub <noreply@github.com>2019-03-18 13:06:10 -0600
commit597028804f395d6251540400dd074e403fa73664 (patch)
treef0f4a30efd0d99e030709d98be45b031ca258339
parentad2b37966b2cfc67096a4e5739baf1b266aca1f7 (diff)
resolves #3036 load additional languages for highlight.js as defined in the highlightjs-languages attribute (PR #3159)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/syntax_highlighter/highlightjs.rb2
-rw-r--r--test/syntax_highlighter_test.rb15
3 files changed, 17 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 2f151923..25f31bc3 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -74,6 +74,7 @@ Enhancements / Compliance::
* rename header_footer option to standalone (while still honoring header_footer for backwards compatibility) (#1444)
* replace anchors and xrefs before footnotes (replace footnotes last in macros substitution group)
* apply substitution for custom inline macro before all other macros
+ * load additional languages for highlight.js as defined in the comma-separated highlightjs-languages attribute (#3036)
Improvements::
diff --git a/lib/asciidoctor/syntax_highlighter/highlightjs.rb b/lib/asciidoctor/syntax_highlighter/highlightjs.rb
index 866a8063..616a0dfa 100644
--- a/lib/asciidoctor/syntax_highlighter/highlightjs.rb
+++ b/lib/asciidoctor/syntax_highlighter/highlightjs.rb
@@ -20,7 +20,7 @@ class SyntaxHighlighter::HighlightJsAdapter < SyntaxHighlighter::Base
base_url = doc.attr 'highlightjsdir', %(#{opts[:cdn_base_url]}/highlight.js/#{HIGHLIGHT_JS_VERSION})
%(<link rel="stylesheet" href="#{base_url}/styles/#{doc.attr 'highlightjs-theme', 'github'}.min.css"#{opts[:self_closing_tag_slash]}>
<script src="#{base_url}/highlight.min.js"></script>
-<script>hljs.initHighlighting()</script>)
+#{(doc.attr? 'highlightjs-languages') ? ((doc.attr 'highlightjs-languages').split ',').map {|lang| %[<script src="#{base_url}/languages/#{lang.lstrip}.min.js"></script>\n] }.join : ''}<script>hljs.initHighlighting()</script>)
end
end
end
diff --git a/test/syntax_highlighter_test.rb b/test/syntax_highlighter_test.rb
index 3fca42ff..857e417e 100644
--- a/test/syntax_highlighter_test.rb
+++ b/test/syntax_highlighter_test.rb
@@ -561,6 +561,21 @@ context 'Syntax Highlighter' do
output = convert_string input, safe: :safe
assert_css 'code.language-none', output, 1
end
+
+ test 'should load additional languages specified by highlightjs-languages' do
+ input = <<~'EOS'
+ :source-highlighter: highlight.js
+ :highlightjs-languages: yaml, scilab
+
+ [source,yaml]
+ ----
+ key: value
+ ----
+ EOS
+ output = convert_string input, safe: Asciidoctor::SafeMode::SAFE
+ assert_css '#footer ~ script[src*="languages/yaml.min.js"]', output, 1
+ assert_css '#footer ~ script[src*="languages/scilab.min.js"]', output, 1
+ end
end
context 'Prettify' do