lib/govspeak.rb in govspeak-8.4.1 vs lib/govspeak.rb in govspeak-8.5.0

- old
+ new

@@ -12,15 +12,18 @@ require "govspeak/header_extractor" require "govspeak/structured_header_extractor" require "govspeak/html_validator" require "govspeak/html_sanitizer" require "govspeak/blockquote_extra_quote_remover" +require "govspeak/embed_extractor" +require "govspeak/embedded_content" require "govspeak/post_processor" require "govspeak/link_extractor" require "govspeak/template_renderer" require "govspeak/presenters/attachment_presenter" require "govspeak/presenters/contact_presenter" +require "govspeak/presenters/embed_presenter" require "govspeak/presenters/h_card_presenter" require "govspeak/presenters/image_presenter" require "govspeak/presenters/attachment_image_presenter" module Govspeak @@ -35,11 +38,11 @@ NEW_PARAGRAPH_LOOKBEHIND = %q{(?<=\A|\n\n|\r\n\r\n)}.freeze @extensions = [] attr_accessor :images - attr_reader :attachments, :contacts, :links, :locale + attr_reader :attachments, :contacts, :links, :locale, :embeds def self.to_html(source, options = {}) new(source, options).to_html end @@ -55,10 +58,11 @@ @allowed_elements = options.delete(:allowed_elements) || [] @allowed_image_hosts = options.delete(:allowed_image_hosts) || [] @attachments = Array.wrap(options.delete(:attachments)) @links = Array.wrap(options.delete(:links)) @contacts = Array.wrap(options.delete(:contacts)) + @embeds = Array.wrap(options.delete(:embeds)) @locale = options.fetch(:locale, "en") @options = { input: PARSER_CLASS_NAME, sanitize: true, syntax_highlighter: nil }.merge(options) @options[:entity_output] = :symbolic @@ -251,9 +255,16 @@ extension("attachment image", /\[embed:attachments:image:\s*(.*?)\s*\]/) do |content_id| attachment = attachments.detect { |a| a[:content_id] == content_id } next "" unless attachment render_image(AttachmentImagePresenter.new(attachment)) + end + + extension("embeds", Govspeak::EmbeddedContent::EMBED_REGEX) do |_embed_code, _document_type, content_id| + embed = embeds.detect { |e| e[:content_id] == content_id } + next "" unless embed + + EmbedPresenter.new(embed).render end # As of version 1.12.0 of Kramdown the block elements (div & figcaption) # inside this html block will have it's < > converted into HTML Entities # when ever this code is used inside block level elements.