From 233980903a8a661b0f154e2480ed6cf605bc3a65 Mon Sep 17 00:00:00 2001 From: Marat Radchenko Date: Sun, 12 May 2024 15:38:59 +0300 Subject: [PATCH] resolves #472 fix crash when section title contains inline anchor --- CHANGELOG.adoc | 4 ++++ lib/asciidoctor-epub3/converter.rb | 8 +++++--- spec/converter_spec.rb | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index d349173..822a584 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -5,6 +5,10 @@ This document provides a high-level view of the changes to the {project-name} by release. For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub. +== Unreleased + +* fix crash when section title contains inline anchor (#472) + == 2.1.0 (2024-02-04) - @slonopotamus * drop MOBI support diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index 0492daf..652e7f0 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -95,6 +95,11 @@ def write(output, target) def initialize(backend, opts = {}) super + + @xrefs_seen = Set.new + @media_files = {} + @footnotes = [] + basebackend 'html' outfilesuffix '.epub' htmlsyntax 'xml' @@ -149,9 +154,6 @@ def convert_document(node) @extract = node.attr? 'ebook-extract' @compress = node.attr 'ebook-compress' @epubcheck_path = node.attr 'ebook-epubcheck-path' - @xrefs_seen = ::Set.new - @media_files = {} - @footnotes = [] @book = GEPUB::Book.new 'EPUB/package.opf' @book.epub_backward_compat = true diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb index a400384..47394b1 100644 --- a/spec/converter_spec.rb +++ b/spec/converter_spec.rb @@ -277,6 +277,20 @@ expect(book).not_to be_nil end + # Test for https://github.com/asciidoctor/asciidoctor-epub3/issues/472 + it 'does not crash when sees inline anchor' do + book = to_epub <<~EOS + = Test + :doctype: book + + [[chapter-1]] + == Chapter 1 + + == <> Chapter 2 + EOS + expect(book).not_to be_nil + end + it 'supports video' do book, = to_epub fixture_file('video/book.adoc') chapter = book.item_by_href '_chapter.xhtml'