Module: Asciidoctor::BeautifyUri::PdfCard
- Defined in:
- lib/asciidoctor/beautify_uri/pdf_card.rb
Overview
PDF has no HTML/CSS renderer to pass a template through, so the PDF card is its own node — a plain :uri_card block carrying the already-resolved data (title, subtitle, thumbnail URL/dimensions, link text/target, icon path) as attributes, with no markup or nested AST of its own. See DESIGN-asciidoctor-beautify-uri.adoc, "Provider Architecture": "Every feature MUST be implemented in both versions unless it is genuinely specific to one converter." There is no PDF backend at all in the Asciidoctor.js/npm ecosystem, so this file has no JS counterpart.
An earlier version of this composed the card as real AsciiDoc source (a two-column table) and let asciidoctor-pdf's own table converter render it. That fought the table converter's own opinions the whole way — "a|" cells reporting unbounded width, an opaque table background painting over a hand-drawn border, a table having no border-radius at all — and its very last unresolved bug (an SVG-wrapped thumbnail, the rounded-corner technique, no longer top-aligning with the title text the way a plain raster image did) turned out to be inherent to routing the thumbnail through Prawn's inline-image-in-formatted-text layout (arrange_images) rather than something fixable at this level. Drawing the card directly with Prawn (see PdfConverter#convert_uri_card) means every position is one this code chooses explicitly — the thumbnail and the title's cap-height start at the exact same y — and rounding the thumbnail's corners is a real Prawn clip path, not an SVG detour.
Constant Summary collapse
- ICON_DIR =
File.('../../../templates/icons', __dir__)
Class Method Summary collapse
- .build(parent, provider, data, thumbnail: true) ⇒ Object
-
.escape(text) ⇒ Object
Still needed by extensions.rb, which drops the generated reftext into a real AsciiDoc emphasis paragraph (
_#{...}_) beneath the card on the PDF backend — quote marks that would open unwanted italic/bold spans there.
Class Method Details
.build(parent, provider, data, thumbnail: true) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/asciidoctor/beautify_uri/pdf_card.rb', line 32 def self.build(parent, provider, data, thumbnail: true) doc = parent.document thumb_url = thumbnail ? data[:thumbnail_url] : nil if thumb_url && !doc.attr?('allow-uri-read') # allow-uri-read can only be set via the API (Asciidoctor hardcodes # it into attribute_overrides for exactly this reason — a document, # or an extension acting on its behalf, cannot grant itself # remote-fetch access). PdfConverter#thumb_local_path hits the same # gate again at real conversion time (via resolve_image_path); this # is just an earlier, more specific log line. Logging.debug('thumbnail requires -a allow-uri-read (or attributes: {"allow-uri-read"=>""} via the API) to embed in PDF output') end attributes = { 'role' => 'uri-card', 'uri-card-title' => data[:title], 'uri-card-link-text' => provider.link_text, 'uri-card-target-url' => data[:target_url], 'uri-card-icon-path' => File.join(ICON_DIR, "#{provider.key}.svg") } attributes['uri-card-subtitle'] = data[:subtitle] if data[:subtitle] && !data[:subtitle].empty? if thumb_url attributes['uri-card-thumb-url'] = thumb_url attributes['uri-card-thumb-native-w'] = data[:thumbnail_width] attributes['uri-card-thumb-native-h'] = data[:thumbnail_height] # A provider-mandated corner radius (e.g. Spotify's design # guidelines) overrides the generic uri_card.thumbnail_border_radius # theme key, which exists for providers with no such brand rule. if provider.respond_to?(:pdf_thumbnail_radius_pt) && (radius = provider.pdf_thumbnail_radius_pt) attributes['uri-card-thumb-radius-pt'] = radius end end ::Asciidoctor::Block.new(parent, :uri_card, content_model: :empty, attributes: attributes) end |
.escape(text) ⇒ Object
Still needed by extensions.rb, which drops the generated reftext into
a real AsciiDoc emphasis paragraph (_#{...}_) beneath the card on
the PDF backend — quote marks that would open unwanted italic/bold
spans there.
68 69 70 |
# File 'lib/asciidoctor/beautify_uri/pdf_card.rb', line 68 def self.escape(text) text.to_s.gsub('*', '\*').gsub('_', '\_') end |