Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to allow automatic figure number to be based on chapter number #188

Open
rlopez133 opened this issue Jun 13, 2015 · 3 comments
Assignees
Milestone

Comments

@rlopez133
Copy link

Currently, when adding an image and providing a title it numbers a Figure as Figure 1. <Title>, Figure 2. <Title> etc, it be great if it would label the Figure based upon its chapter. Assuming you have two images in Chapter 2 and one image in Chapter 3, it would be Figure 2.1 <Title>, Figure 2.2 <Title>, Figure 3.1 <Title>, etc.

@mojavelinux mojavelinux changed the title Enhancement Request: Auto number of Figures based upon Chapter Add setting to allow automatic figure number to be based on chapter number Jun 14, 2015
@mojavelinux mojavelinux added this to the v1.5.0 milestone Jun 14, 2015
@mojavelinux mojavelinux self-assigned this Jun 14, 2015
@mojavelinux
Copy link
Member

Technically, this issue needs to be resolved in core. However, we can experiment with a solution here and then migrate it upstream once we're happy with the approach.

@mojavelinux mojavelinux modified the milestones: v1.5.0, v2.0.0 Nov 22, 2019
@graphitefriction graphitefriction modified the milestones: v2.0.0, v2.1.x Apr 25, 2022
@mojavelinux mojavelinux modified the milestones: v2.1.x, v2.2.x Jun 21, 2022
@mojavelinux mojavelinux modified the milestones: v2.2.x, v2.3.x Jul 22, 2022
@mojavelinux mojavelinux modified the milestones: v2.3.x, v3.0.x Aug 16, 2022
@mojavelinux
Copy link
Member

See asciidoctor/asciidoctor#2291

@mojavelinux
Copy link
Member

Here's a super quick extension to insert the section number after the figure caption and before the figure number.

Asciidoctor::Extensions.register do
  tree_processor do
    process do |doc|
      figcaption = doc.attr 'figure-caption'
      doc.find_by context: :image do |image|
        next unless image.title?
        section = parent_section image
        fignum = image.attributes[:attribute_entries].find {|it| it.name === 'figure-number' }.value
        image.caption = %(#{figcaption} #{section.sectnum} #{fignum}. )
      end
    end
    nil

    def parent_section block
      ancestor = block
      while (ancestor = ancestor.parent).context != :section
      end
      ancestor
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants