Footnotes have captions

This commit is contained in:
Alex Kotov 2024-09-17 09:48:48 +04:00
parent 5bab57e254
commit e29c3202fe
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
7 changed files with 50 additions and 24 deletions

View file

@ -31,10 +31,10 @@ Chapter 2 paragraph text
## Related articles
=> ./foo-bar 1) 2024-09-12 Foo Bar
=> ./foo-bar 1) 2024-09-12 Foo Bar — Baz Car Cdr Qwe Rty
## Links
=> https://example.com 2) Example Domain
=> https://example.com 2) Example Domain — This domain is for use in illustrative examples in documents

View file

@ -87,6 +87,10 @@ September 12, 2024
</time>
</span>
<a href="./foo-bar">Foo Bar</a>
<span>
&mdash;
Baz Car Cdr Qwe Rty
</span>
</li>
</ol>
<h2>Links</h2>
@ -94,6 +98,10 @@ September 12, 2024
<ol>
<li id="link-example-com" value="2" class="fragment-highlight">
<a href="https://example.com">Example Domain</a>
<span>
&mdash;
This domain is for use in illustrative examples in documents
</span>
(<a href="https://web.archive.org/arch/example.com">web.archive.org</a>)
</li>
</ol>

View file

@ -55,9 +55,12 @@ article.footnotes_category 'Related articles' do |category|
slug: 'foo-bar',
index: 1,
url: './foo-bar',
text: 'Foo Bar',
link_text: 'Foo Bar',
date: '2024-09-12',
)
) do |footnote|
footnote.mdash
footnote.text 'Baz Car Cdr Qwe Rty'
end
end
article.footnotes_category 'Links' do |category|
@ -66,12 +69,15 @@ article.footnotes_category 'Links' do |category|
slug: 'example-com',
index: 2,
url: 'https://example.com',
text: 'Example Domain',
link_text: 'Example Domain',
alt_urls: [
{
name: 'web.archive.org',
url: 'https://web.archive.org/arch/example.com',
},
],
)
) do |footnote|
footnote.mdash
footnote.text 'This domain is for use in illustrative examples in documents'
end
end

View file

@ -44,7 +44,7 @@ require_relative 'repubmark/elems/list_item'
# Always inside Caption, Quote
require_relative 'repubmark/elems/joint'
# Always inside Blockquote, Figure, ListItem, Paragraph
# Always inside Blockquote, Figure, Footnote, ListItem, Paragraph
require_relative 'repubmark/elems/caption'
# Always inside Caption, Joint, Quote
require_relative 'repubmark/elems/quote'

View file

@ -5,7 +5,7 @@ module Repubmark
class Caption < Base
include Joint::ForwardingBuilders
parents :Blockquote, :Figure, :ListItem, :Paragraph
parents :Blockquote, :Figure, :Footnote, :ListItem, :Paragraph
def initialize(parent)
super parent

View file

@ -3,16 +3,14 @@
module Repubmark
module Elems
class Footnote < Base
EM_DASH = '—'
parents :FootnotesCategory
attr_reader :category, :slug, :index, :url,
:text, :descr, :date, :alt_urls
attr_reader :category, :slug, :index, :url, :link_text, :date, :alt_urls
def initialize(parent, **kwargs)
super parent
kwargs.each { |k, v| send :"#{k}=", v }
@caption = Caption.new self
end
#################
@ -39,15 +37,12 @@ module Repubmark
result += "</span>\n"
end
end
result += %(<a href="#{url}">#{text}</a>)
result += %(<a href="#{url}">#{link_text}</a>)
else
result += text
result += link_text
end
if descr
result += " &mdash; #{descr}\n"
else
result += "\n"
end
result += @caption.to_html
if alt_urls&.any?
result += %[(#{
alt_urls.map do |alt_url|
@ -64,15 +59,30 @@ module Repubmark
result += url ? "=> #{url}" : '*'
result += " #{index})"
result += " #{Date.parse(date)}" if date
result += " #{text}"
result += " #{EM_DASH} #{descr}" if descr
result += " #{link_text}" if link_text
result += " #{@caption.to_gemtext}"
result.freeze
end
###################
# Builder methods #
###################
def respond_to_missing?(method_name, _include_private)
@caption.respond_to?(method_name) || super
end
def method_missing(method_name, ...)
if @caption.respond_to? method_name
@caption.public_send(method_name, ...)
else
super
end
end
private
attr_writer :category, :slug, :index, :url,
:text, :descr, :date, :alt_urls
attr_writer :category, :slug, :index, :url, :link_text, :date, :alt_urls
end
end
end

View file

@ -38,7 +38,9 @@ module Repubmark
###################
def footnote(**kwargs)
@footnotes << Footnote.new(self, **kwargs)
footnote = Footnote.new(self, **kwargs)
@footnotes << footnote
yield footnote if block_given?
nil
end
end