summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarat Radchenko <marat@slonopotamus.org>2024-01-07 18:28:56 +0300
committerGitHub <noreply@github.com>2024-01-07 18:28:56 +0300
commitba986531f5b51c5c2b72f5e2e89f47dfbacca431 (patch)
tree5b38149a36bfcf96c0f993cfb64fc71ea512141c
parent3e7fb05a39fa73c77da1f98a0d5aa3199cd62aa6 (diff)
remove compatibility code for pre-2.0 Asciidoctor (#456)
-rw-r--r--lib/asciidoctor-epub3/converter.rb9
-rw-r--r--lib/asciidoctor-epub3/ext.rb1
-rw-r--r--lib/asciidoctor-epub3/ext/asciidoctor.rb4
-rw-r--r--lib/asciidoctor-epub3/ext/asciidoctor/document.rb23
-rw-r--r--lib/asciidoctor-epub3/ext/asciidoctor/logging_shim.rb33
-rw-r--r--spec/highlight_spec.rb23
6 files changed, 7 insertions, 86 deletions
diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb
index 93b3bae..42d5e96 100644
--- a/lib/asciidoctor-epub3/converter.rb
+++ b/lib/asciidoctor-epub3/converter.rb
@@ -620,6 +620,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
%(<#{tag_name}#{id_attribute} class="#{['discrete', node.role].compact * ' '}">#{node.title}</#{tag_name}>)
end
+ # @param node [Asciidoctor::Block]
def convert_listing(node)
id_attribute = node.id ? %( id="#{node.id}") : ''
nowrap = (node.option? 'nowrap') || !(node.document.attr? 'prewrap')
@@ -1945,14 +1946,6 @@ body > svg {
document.set_attribute 'pygments-style', 'bw' unless document.attr? 'pygments-style'
document.set_attribute 'rouge-style', 'bw' unless document.attr? 'rouge-style'
- # Old asciidoctor versions do not have public API for writing highlighter CSS file
- # So just use inline CSS there.
- unless Document.supports_syntax_highlighter?
- document.set_attribute 'coderay-css', 'style'
- document.set_attribute 'pygments-css', 'style'
- document.set_attribute 'rouge-css', 'style'
- end
-
case (ebook_format = document.attributes['ebook-format'])
when 'epub3', 'kf8'
# all good
diff --git a/lib/asciidoctor-epub3/ext.rb b/lib/asciidoctor-epub3/ext.rb
index 047824e..79baf85 100644
--- a/lib/asciidoctor-epub3/ext.rb
+++ b/lib/asciidoctor-epub3/ext.rb
@@ -1,4 +1,3 @@
# frozen_string_literal: true
-require_relative 'ext/asciidoctor'
require_relative 'ext/core'
diff --git a/lib/asciidoctor-epub3/ext/asciidoctor.rb b/lib/asciidoctor-epub3/ext/asciidoctor.rb
deleted file mode 100644
index f926633..0000000
--- a/lib/asciidoctor-epub3/ext/asciidoctor.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# frozen_string_literal: true
-
-require_relative 'asciidoctor/document'
-require_relative 'asciidoctor/logging_shim' unless defined? Asciidoctor::Logging
diff --git a/lib/asciidoctor-epub3/ext/asciidoctor/document.rb b/lib/asciidoctor-epub3/ext/asciidoctor/document.rb
deleted file mode 100644
index 8b80041..0000000
--- a/lib/asciidoctor-epub3/ext/asciidoctor/document.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-module Asciidoctor
- class Document
- class << self
- def supports_syntax_highlighter?
- if @supports_syntax_highlighter.nil?
- # Asciidoctor only got pluggable syntax highlighters since 2.0:
- # https://github.com/asciidoctor/asciidoctor/commit/23ddbaed6818025cbe74365fec7e8101f34eadca
- @supports_syntax_highlighter = method_defined? :syntax_highlighter
- end
-
- @supports_syntax_highlighter
- end
- end
-
- unless supports_syntax_highlighter?
- def syntax_highlighter
- nil
- end
- end
- end
-end
diff --git a/lib/asciidoctor-epub3/ext/asciidoctor/logging_shim.rb b/lib/asciidoctor-epub3/ext/asciidoctor/logging_shim.rb
deleted file mode 100644
index b317309..0000000
--- a/lib/asciidoctor-epub3/ext/asciidoctor/logging_shim.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# frozen_string_literal: true
-
-module Asciidoctor
- module Logging
- class StubLogger
- class << self
- def debug(message = nil)
- puts %(asciidoctor: DEBUG: #{message || (block_given? ? yield : '???')}) if $VERBOSE
- end
-
- def info(message = nil)
- puts %(asciidoctor: INFO: #{message || (block_given? ? yield : '???')}) if $VERBOSE
- end
-
- def warn(message = nil)
- ::Kernel.warn %(asciidoctor: WARNING: #{message || (block_given? ? yield : '???')})
- end
-
- def error(message = nil)
- ::Kernel.warn %(asciidoctor: ERROR: #{message || (block_given? ? yield : '???')})
- end
-
- def fatal(message = nil)
- ::Kernel.warn %(asciidoctor: FATAL: #{message || (block_given? ? yield : '???')})
- end
- end
- end
-
- def logger
- StubLogger
- end
- end
-end
diff --git a/spec/highlight_spec.rb b/spec/highlight_spec.rb
index 2282fde..0f206c1 100644
--- a/spec/highlight_spec.rb
+++ b/spec/highlight_spec.rb
@@ -7,32 +7,21 @@ describe 'Asciidoctor::Epub3::Converter - Highlight' do
book, = to_epub fixture_file('source_highlight.adoc'), attributes: { 'source-highlighter' => 'coderay' }
article = book.item_by_href 'source_highlight.xhtml'
expect(article).not_to be_nil
- if Asciidoctor::Document.supports_syntax_highlighter?
- expect(article.content).to include '<span class="keyword">class</span> <span class="class">Foo</span>'
- expect(article.content).to include '<link rel="stylesheet" href="./coderay-asciidoctor.css"/>'
- expect(book.item_by_href('coderay-asciidoctor.css')).not_to be_nil
- else
- expect(article.content).to include '<span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Foo</span>'
- end
+ expect(article.content).to include '<span class="keyword">class</span> <span class="class">Foo</span>'
+ expect(article.content).to include '<link rel="stylesheet" href="./coderay-asciidoctor.css"/>'
+ expect(book.item_by_href('coderay-asciidoctor.css')).not_to be_nil
end
it 'highlights code listings with pygments.rb' do
book, = to_epub fixture_file('source_highlight.adoc'), attributes: { 'source-highlighter' => 'pygments' }
article = book.item_by_href 'source_highlight.xhtml'
expect(article).not_to be_nil
- if Asciidoctor::Document.supports_syntax_highlighter?
- expect(article.content).to include '<span class="tok-nc">Foo</span>'
- expect(article.content).to include '<link rel="stylesheet" href="./pygments-bw.css"/>'
- expect(book.item_by_href('pygments-bw.css')).not_to be_nil
- else
- expect(article.content).to include '<span style="font-weight: bold">class</span> <span style="font-weight: bold">Foo</span>'
- end
+ expect(article.content).to include '<span class="tok-nc">Foo</span>'
+ expect(article.content).to include '<link rel="stylesheet" href="./pygments-bw.css"/>'
+ expect(book.item_by_href('pygments-bw.css')).not_to be_nil
end
it 'highlights code listings with Rouge' do
- # TODO: This condition might be not quite correct
- skip 'No Rouge support in current Asciidoctor version' unless Asciidoctor::Document.supports_syntax_highlighter?
-
book, = to_epub fixture_file('source_highlight.adoc'), attributes: { 'source-highlighter' => 'rouge' }
article = book.item_by_href 'source_highlight.xhtml'
expect(article).not_to be_nil