diff --git a/examples/full.gmi b/examples/full.gmi index 05ca44a..3c77dd7 100644 --- a/examples/full.gmi +++ b/examples/full.gmi @@ -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 diff --git a/examples/full.html b/examples/full.html index 2e6dbed..fdc3e33 100644 --- a/examples/full.html +++ b/examples/full.html @@ -87,6 +87,10 @@ September 12, 2024 Foo Bar + +— +Baz Car Cdr Qwe Rty +

Links

@@ -94,6 +98,10 @@ September 12, 2024
diff --git a/examples/full.repub b/examples/full.repub index b2ca580..57ac233 100644 --- a/examples/full.repub +++ b/examples/full.repub @@ -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 diff --git a/lib/repubmark.rb b/lib/repubmark.rb index 8f3e242..de0507f 100644 --- a/lib/repubmark.rb +++ b/lib/repubmark.rb @@ -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' diff --git a/lib/repubmark/elems/caption.rb b/lib/repubmark/elems/caption.rb index 9a23eca..b3b5264 100644 --- a/lib/repubmark/elems/caption.rb +++ b/lib/repubmark/elems/caption.rb @@ -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 diff --git a/lib/repubmark/elems/footnote.rb b/lib/repubmark/elems/footnote.rb index 7394fa7..015a7a4 100644 --- a/lib/repubmark/elems/footnote.rb +++ b/lib/repubmark/elems/footnote.rb @@ -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 += "\n" end end - result += %(#{text}) + result += %(#{link_text}) else - result += text - end - if descr - result += " — #{descr}\n" - else - result += "\n" + result += link_text end + result += "\n" + 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 diff --git a/lib/repubmark/elems/footnotes_category.rb b/lib/repubmark/elems/footnotes_category.rb index 54aa4c9..cc1985c 100644 --- a/lib/repubmark/elems/footnotes_category.rb +++ b/lib/repubmark/elems/footnotes_category.rb @@ -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