Footnotes have captions
This commit is contained in:
parent
5bab57e254
commit
e29c3202fe
7 changed files with 50 additions and 24 deletions
|
@ -31,10 +31,10 @@ Chapter 2 paragraph text
|
||||||
|
|
||||||
## Related articles
|
## Related articles
|
||||||
|
|
||||||
=> ./foo-bar 1) 2024-09-12 Foo Bar
|
=> ./foo-bar 1) 2024-09-12 Foo Bar — Baz Car Cdr Qwe Rty
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
||||||
=> https://example.com 2) Example Domain
|
=> https://example.com 2) Example Domain — This domain is for use in illustrative examples in documents
|
||||||
|
|
|
@ -87,6 +87,10 @@ September 12, 2024
|
||||||
</time>
|
</time>
|
||||||
</span>
|
</span>
|
||||||
<a href="./foo-bar">Foo Bar</a>
|
<a href="./foo-bar">Foo Bar</a>
|
||||||
|
<span>
|
||||||
|
—
|
||||||
|
Baz Car Cdr Qwe Rty
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
<h2>Links</h2>
|
<h2>Links</h2>
|
||||||
|
@ -94,6 +98,10 @@ September 12, 2024
|
||||||
<ol>
|
<ol>
|
||||||
<li id="link-example-com" value="2" class="fragment-highlight">
|
<li id="link-example-com" value="2" class="fragment-highlight">
|
||||||
<a href="https://example.com">Example Domain</a>
|
<a href="https://example.com">Example Domain</a>
|
||||||
|
<span>
|
||||||
|
—
|
||||||
|
This domain is for use in illustrative examples in documents
|
||||||
|
</span>
|
||||||
(<a href="https://web.archive.org/arch/example.com">web.archive.org</a>)
|
(<a href="https://web.archive.org/arch/example.com">web.archive.org</a>)
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
|
@ -55,9 +55,12 @@ article.footnotes_category 'Related articles' do |category|
|
||||||
slug: 'foo-bar',
|
slug: 'foo-bar',
|
||||||
index: 1,
|
index: 1,
|
||||||
url: './foo-bar',
|
url: './foo-bar',
|
||||||
text: 'Foo Bar',
|
link_text: 'Foo Bar',
|
||||||
date: '2024-09-12',
|
date: '2024-09-12',
|
||||||
)
|
) do |footnote|
|
||||||
|
footnote.mdash
|
||||||
|
footnote.text 'Baz Car Cdr Qwe Rty'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
article.footnotes_category 'Links' do |category|
|
article.footnotes_category 'Links' do |category|
|
||||||
|
@ -66,12 +69,15 @@ article.footnotes_category 'Links' do |category|
|
||||||
slug: 'example-com',
|
slug: 'example-com',
|
||||||
index: 2,
|
index: 2,
|
||||||
url: 'https://example.com',
|
url: 'https://example.com',
|
||||||
text: 'Example Domain',
|
link_text: 'Example Domain',
|
||||||
alt_urls: [
|
alt_urls: [
|
||||||
{
|
{
|
||||||
name: 'web.archive.org',
|
name: 'web.archive.org',
|
||||||
url: 'https://web.archive.org/arch/example.com',
|
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
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ require_relative 'repubmark/elems/list_item'
|
||||||
|
|
||||||
# Always inside Caption, Quote
|
# Always inside Caption, Quote
|
||||||
require_relative 'repubmark/elems/joint'
|
require_relative 'repubmark/elems/joint'
|
||||||
# Always inside Blockquote, Figure, ListItem, Paragraph
|
# Always inside Blockquote, Figure, Footnote, ListItem, Paragraph
|
||||||
require_relative 'repubmark/elems/caption'
|
require_relative 'repubmark/elems/caption'
|
||||||
# Always inside Caption, Joint, Quote
|
# Always inside Caption, Joint, Quote
|
||||||
require_relative 'repubmark/elems/quote'
|
require_relative 'repubmark/elems/quote'
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Repubmark
|
||||||
class Caption < Base
|
class Caption < Base
|
||||||
include Joint::ForwardingBuilders
|
include Joint::ForwardingBuilders
|
||||||
|
|
||||||
parents :Blockquote, :Figure, :ListItem, :Paragraph
|
parents :Blockquote, :Figure, :Footnote, :ListItem, :Paragraph
|
||||||
|
|
||||||
def initialize(parent)
|
def initialize(parent)
|
||||||
super parent
|
super parent
|
||||||
|
|
|
@ -3,16 +3,14 @@
|
||||||
module Repubmark
|
module Repubmark
|
||||||
module Elems
|
module Elems
|
||||||
class Footnote < Base
|
class Footnote < Base
|
||||||
EM_DASH = '—'
|
|
||||||
|
|
||||||
parents :FootnotesCategory
|
parents :FootnotesCategory
|
||||||
|
|
||||||
attr_reader :category, :slug, :index, :url,
|
attr_reader :category, :slug, :index, :url, :link_text, :date, :alt_urls
|
||||||
:text, :descr, :date, :alt_urls
|
|
||||||
|
|
||||||
def initialize(parent, **kwargs)
|
def initialize(parent, **kwargs)
|
||||||
super parent
|
super parent
|
||||||
kwargs.each { |k, v| send :"#{k}=", v }
|
kwargs.each { |k, v| send :"#{k}=", v }
|
||||||
|
@caption = Caption.new self
|
||||||
end
|
end
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
@ -39,15 +37,12 @@ module Repubmark
|
||||||
result += "</span>\n"
|
result += "</span>\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
result += %(<a href="#{url}">#{text}</a>)
|
result += %(<a href="#{url}">#{link_text}</a>)
|
||||||
else
|
else
|
||||||
result += text
|
result += link_text
|
||||||
end
|
|
||||||
if descr
|
|
||||||
result += " — #{descr}\n"
|
|
||||||
else
|
|
||||||
result += "\n"
|
|
||||||
end
|
end
|
||||||
|
result += "\n"
|
||||||
|
result += @caption.to_html
|
||||||
if alt_urls&.any?
|
if alt_urls&.any?
|
||||||
result += %[(#{
|
result += %[(#{
|
||||||
alt_urls.map do |alt_url|
|
alt_urls.map do |alt_url|
|
||||||
|
@ -64,15 +59,30 @@ module Repubmark
|
||||||
result += url ? "=> #{url}" : '*'
|
result += url ? "=> #{url}" : '*'
|
||||||
result += " #{index})"
|
result += " #{index})"
|
||||||
result += " #{Date.parse(date)}" if date
|
result += " #{Date.parse(date)}" if date
|
||||||
result += " #{text}"
|
result += " #{link_text}" if link_text
|
||||||
result += " #{EM_DASH} #{descr}" if descr
|
result += " #{@caption.to_gemtext}"
|
||||||
result.freeze
|
result.freeze
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
attr_writer :category, :slug, :index, :url,
|
attr_writer :category, :slug, :index, :url, :link_text, :date, :alt_urls
|
||||||
:text, :descr, :date, :alt_urls
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,9 @@ module Repubmark
|
||||||
###################
|
###################
|
||||||
|
|
||||||
def footnote(**kwargs)
|
def footnote(**kwargs)
|
||||||
@footnotes << Footnote.new(self, **kwargs)
|
footnote = Footnote.new(self, **kwargs)
|
||||||
|
@footnotes << footnote
|
||||||
|
yield footnote if block_given?
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue