lib/govspeak.rb in govspeak-8.1.0 vs lib/govspeak.rb in govspeak-8.2.0

- old
+ new

@@ -137,16 +137,17 @@ def footnote_definitions(source) is_legislative_list = source.scan(/\$LegislativeList.*?\[\^\d\]*.*?\$EndLegislativeList/m).size.positive? is_cta = source.scan(/\$CTA.*?\[\^\d\]*.*?\$CTA/m).size.positive? footnotes = source.scan(/^\s*\[\^(\d+)\]:(.*)/) - @acronyms = source.scan(/(?<=\*)\[(.*)\]:(.*)/) + @acronyms.concat(source.scan(/(?<=\*)\[(.*)\]:(.*)/)) if (is_legislative_list || is_cta) && footnotes.size.positive? list_items = footnotes.map do |footnote| number = footnote[0] text = footnote[1].strip footnote_definition = Govspeak::Document.new(text).to_html[/(?<=<p>).*(?=<\/p>)/] + footnote_definition = add_acronym_alt_text(footnote_definition) <<~HTML_SNIPPET <li id="fn:#{number}" role="doc-endnote"> <p> #{footnote_definition}<a href="#fnref:#{number}" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a> @@ -161,14 +162,10 @@ #{list_items.join.strip} </ol> </div> HTML_CONTAINER end - - unless @footnote_definition_html.nil? && @acronyms.size.positive? - add_acronym_alt_text(@footnote_definition_html) - end end def remove_forbidden_characters(source) # These are characters that are not deemed not suitable for # markup: https://www.w3.org/TR/unicode-xml/#Charlist @@ -324,10 +321,11 @@ lines.join end extension("call-to-action", surrounded_by("$CTA")) do |body| doc = Kramdown::Document.new(preprocess(body.strip), @options).to_html + doc = add_acronym_alt_text(doc) doc = %(\n<div class="call-to-action">\n#{doc}</div>\n) footnotes = body.scan(/\[\^(\d+)\]/).flatten footnotes.each do |footnote| html = "<sup id=\"fnref:#{footnote}\" role=\"doc-noteref\">" \ @@ -335,11 +333,10 @@ "[footnote #{footnote}]</a></sup>" doc.sub!(/(\[\^#{footnote}\])/, html) end - add_acronym_alt_text(doc) if @acronyms.size.positive? doc end # More specific tags must be defined first. Those defined earlier have a # higher precedence for being matched. For example $CTA must be defined @@ -356,10 +353,12 @@ %(\n<div class="address"><div class="adr org fn"><p>\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n) end extension("legislative list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body| Govspeak::KramdownOverrides.with_kramdown_ordered_lists_disabled do + body = add_acronym_alt_text(body.strip) + Kramdown::Document.new(body.strip).to_html.tap do |doc| doc.gsub!("<ul>", "<ol>") doc.gsub!("</ul>", "</ol>") doc.sub!("<ol>", '<ol class="legislative-list">') @@ -370,12 +369,10 @@ "<a href=\"#fn:#{footnote}\" class=\"footnote\" rel=\"footnote\">" \ "[footnote #{footnote}]</a></sup>" doc.sub!(/(\[\^#{footnote}\])/, html) end - - add_acronym_alt_text(doc) if @acronyms.size.positive? end end end extension("numbered list", /^[ \t]*((s\d+\.\s.*(?:\n|$))+)/) do |body| @@ -452,13 +449,14 @@ def encode(text) HTMLEntities.new.encode(text) end def add_acronym_alt_text(html) - # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now - # @acronyms.each do |acronym| - # html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>") - # end + @acronyms.each do |acronym| + html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>") + end + + html end end end I18n.load_path.unshift(