Module: Asciidoctor::Html5s::Converter::Helpers
- Defined in:
- lib/asciidoctor/html5s/converter.rb
Overview
Add custom functions to this module that you want to use in your Slim templates. Within the template you can invoke them as top-level functions just like in Haml.
Constant Summary collapse
- CDN_BASE_URI =
URIs of external assets.
'https://cdnjs.cloudflare.com/ajax/libs'- FONT_AWESOME_URI =
for highlighters in Asciidoctor >=2.0.0
'https://cdn.jsdelivr.net/npm/[email protected]/css/font-awesome.min.css'- HIGHLIGHTJS_BASE_URI =
'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/'- KATEX_CSS_URI =
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css'- KATEX_JS_URI =
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js'- DEFAULT_HIGHLIGHTJS_THEME =
Defaults
'github'- DEFAULT_LANG =
'en'- DEFAULT_SECTNUMLEVELS =
3- DEFAULT_TOCLEVELS =
2- CURLY_QUOTES =
[ [%w[af en eo ga hi ia id ko mt th tr zh], ['‘', '’', '“', '”']], # ‘…’ “…” [%w[bs fi sv], ['’', '’', '”', '”']], # ’…’ ”…” [%w[cs da de is lt sl sk sr], ['‚', '‘', '„', '“']], # ‚…‘ „…“ [%w[nl], ['‚', '’', '„', '”']], # ‚…’ „…” [%w[hu pl ro], ['«', '»', '„', '”']], # «…» „…” ].reduce({}) do |hsh, (langs, codes)| langs.each { |lang| hsh[lang] = codes } hsh end
- KATEX_RENDER_CODE =
<<-JS.gsub(/\s+/, ' ') document.addEventListener("DOMContentLoaded", function() { var elements = document.getElementsByClassName("math"); for (var i = 0; i < elements.length; i++) { var el = elements[i]; if (el.getAttribute("data-lang") !== "tex") { continue; } katex.render(el.textContent.slice(2, -2), el, { "displayMode": el.nodeName.toUpperCase() !== "SPAN", "throwOnError": false, }); } }); JS
- VOID_ELEMENTS =
%w(area base br col command embed hr img input keygen link meta param source track wbr)
Instance Method Summary collapse
-
#abstract_allowed? ⇒ Boolean
Returns
trueif an abstract block is allowed in this document type, otherwise prints warning and returnsfalse. -
#admonition_aria ⇒ String?
WAI-ARIA role of this admonition.
-
#admonition_aside? ⇒ Boolean
Should be this admonition wrapped in aside element?.
-
#autowidth?(node = self) ⇒ Boolean
——————————————————– block_table.
-
#bibref_text ⇒ String?
Text of the bibref anchor, or
nilif not found. - #block_with_caption(position = :bottom, attrs = {}, &block) ⇒ Object
-
#block_with_title(attrs = {}, title = @title) { ... } ⇒ String
Wraps a block in a div element with the specified class and optionally the node’s
idandrole(s). -
#callout_list ⇒ Asciidoctor::List?
Returns the callout list attached to this listing node, or
nilif none. -
#capture(&block) ⇒ Object
Captures the given block for later yield.
-
#delimit_stem(equation, type) ⇒ String
Delimite the given equation as a STEM of the specified type.
-
#double_quoted(text) ⇒ String
Quoted text.
-
#footnote_id(index = local_attr(:index)) ⇒ String
Footnote id to be used in a link.
-
#footnoteref_id(index = local_attr(:index)) ⇒ String
Footnoteref id to be used in a link.
-
#formatted_source ⇒ String?
See SyntaxHighlighter#format.
-
#html_meta_if(name, content) ⇒ String?
Returns HTML meta tag if the given
contentis notnil. -
#html_tag(name, attributes = {}, content = nil) { ... } ⇒ String
Creates an HTML tag with the given name and optionally attributes.
-
#html_tag_if(condition, name, attributes = {}, content = nil) { ... } ⇒ String
Conditionally wraps a block in an element.
-
#icon_fa_classes ⇒ Array
Style classes for a Font Awesome icon.
-
#image_link ⇒ String?
An URL for the image’s link.
-
#image_link_label ⇒ String?
A label/title of the image link.
- #link_rel ⇒ Object
-
#local_attr(name, default_val = nil) ⇒ Object
Gets the value of the specified attribute in this node.
-
#local_attr?(name, expect_val = nil) ⇒ Boolean
Checks if the attribute is defined on this node, optionally performing a comparison of its value if
expect_valis not nil. - #log ⇒ Logger
- #nowrap? ⇒ Boolean
-
#partintro_allowed? ⇒ Boolean
Returns
trueif a partintro block is allowed in this context, otherwise prints warning and returnsfalse. - #print_item_content(item) ⇒ Object
-
#revdate_iso ⇒ String?
The revision date in ISO 8601, or nil if not available or in invalid format.
-
#section_level(sec = self) ⇒ Integer
Returns corrected section level.
-
#section_title(sec = self, drop_anchors: false) ⇒ String
Returns the captioned section’s title, optionally numbered.
-
#single_quoted(text) ⇒ String
Quoted text.
-
#source_code_class ⇒ Object
This is needed only for Asciidoctor <2.0.0.
- #source_lang ⇒ Object
-
#stem_lang ⇒ String
Language of STEM block or inline node (tex or asciimath).
- #stretch? ⇒ Boolean
-
#style_value(declarations) ⇒ String?
Formats the given hash as CSS declarations for an inline style.
-
#styles_and_scripts ⇒ Object
Returns formatted style/link and script tags for header.
-
#url_query(params) ⇒ Object
Formats URL query parameters.
- #urlize(*segments) ⇒ Object
-
#video_iframe? ⇒ Boolean
trueif the video should be embedded in an iframe. - #video_uri ⇒ Object
-
#xref_text ⇒ String
Text of the xref anchor.
-
#yield_capture(*params) ⇒ Object
Yields the captured block (see #capture).
Instance Method Details
#abstract_allowed? ⇒ Boolean
Returns true if an abstract block is allowed in this document type, otherwise prints warning and returns false.
530 531 532 533 534 535 536 |
# File 'lib/asciidoctor/html5s/converter.rb', line 530 def abstract_allowed? if result = (parent == document && document.doctype == 'book') log.warn 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.' end !result end |
#admonition_aria ⇒ String?
Returns WAI-ARIA role of this admonition.
440 441 442 443 444 445 446 447 448 449 |
# File 'lib/asciidoctor/html5s/converter.rb', line 440 def admonition_aria case attr(:name) when 'note' 'note' # https://www.w3.org/TR/wai-aria/roles#note when 'tip' 'doc-tip' # https://www.w3.org/TR/dpub-aria-1.0/#doc-tip when 'caution', 'important', 'warning' 'doc-notice' # https://www.w3.org/TR/dpub-aria-1.0/#doc-notice end end |
#admonition_aside? ⇒ Boolean
Returns should be this admonition wrapped in aside element?.
434 435 436 |
# File 'lib/asciidoctor/html5s/converter.rb', line 434 def admonition_aside? %w[note tip].include? attr(:name) end |
#autowidth?(node = self) ⇒ Boolean
block_table
553 554 555 |
# File 'lib/asciidoctor/html5s/converter.rb', line 553 def autowidth?(node = self) node.option? :autowidth end |
#bibref_text ⇒ String?
Returns text of the bibref anchor, or nil if not found.
732 733 734 735 736 737 738 |
# File 'lib/asciidoctor/html5s/converter.rb', line 732 def bibref_text if ::Asciidoctor::VERSION[0] == '1' text else # Asciidoctor >= 2.0.0 "[#{reftext || id}]" end end |
#block_with_caption(position = :bottom, attrs = {}, &block) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/asciidoctor/html5s/converter.rb', line 224 def block_with_caption(position = :bottom, attrs = {}, &block) if (klass = attrs[:class]).is_a? String klass = klass.split(' ') end attrs[:class] = [klass, role].flatten.uniq attrs[:id] = id if title.nil_or_empty? html_tag :div, attrs, yield else html_tag :figure, attrs do ary = [yield, html_tag(:figcaption) { captioned_title }] ary.reverse! if position == :top ary.compact.join("\n") end end end |
#block_with_title(attrs = {}, title = @title) { ... } ⇒ String
Wraps a block in a div element with the specified class and optionally the node’s id and role(s). If the node’s title is not empty, then a nested div with the class “title” and the title’s content is added as well.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/asciidoctor/html5s/converter.rb', line 205 def block_with_title(attrs = {}, title = @title, &block) if (klass = attrs[:class]).is_a? String klass = klass.split(' ') end attrs[:class] = [klass, role].flatten.uniq attrs[:id] = id if title.nil_or_empty? # XXX quick hack nested = is_a?(::Asciidoctor::List) && (parent.is_a?(::Asciidoctor::ListItem) || parent.is_a?(::Asciidoctor::List)) html_tag_if !nested, :div, attrs, yield else html_tag :section, attrs do [html_tag(:h6, {class: 'block-title'}, title), yield].join("\n") end end end |
#callout_list ⇒ Asciidoctor::List?
Returns the callout list attached to this listing node, or nil if none.
Note: This variable is set by extension AttachedColistTreeprocessor.
506 507 508 |
# File 'lib/asciidoctor/html5s/converter.rb', line 506 def callout_list @html5s_colist end |
#capture(&block) ⇒ Object
Captures the given block for later yield.
90 91 92 93 |
# File 'lib/asciidoctor/html5s/converter.rb', line 90 def capture(&block) @_html5s_capture = block nil end |
#delimit_stem(equation, type) ⇒ String
Delimite the given equation as a STEM of the specified type.
Note: This is not needed nor used for KaTeX, but keep this for the case user wants to use a different method.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/asciidoctor/html5s/converter.rb', line 252 def delimit_stem(equation, type) if (@_html5s_stem_type ||= document.attr('html5s-force-stem-type')) type = @_html5s_stem_type end if is_a? ::Asciidoctor::Block open, close = ::Asciidoctor::BLOCK_MATH_DELIMITERS[type.to_sym] else open, close = ::Asciidoctor::INLINE_MATH_DELIMITERS[type.to_sym] end if !equation.start_with?(open) || !equation.end_with?(close) equation = [open, equation, close].join end equation end |
#double_quoted(text) ⇒ String
Returns quoted text.
759 760 761 762 |
# File 'lib/asciidoctor/html5s/converter.rb', line 759 def double_quoted(text) quotes = CURLY_QUOTES[attr(:lang, DEFAULT_LANG, true)] "#{quotes[2]}#{text}#{quotes[3]}" end |
#footnote_id(index = local_attr(:index)) ⇒ String
Returns footnote id to be used in a link.
352 353 354 |
# File 'lib/asciidoctor/html5s/converter.rb', line 352 def footnote_id(index = local_attr(:index)) "_footnote_#{index}" end |
#footnoteref_id(index = local_attr(:index)) ⇒ String
Returns footnoteref id to be used in a link.
359 360 361 |
# File 'lib/asciidoctor/html5s/converter.rb', line 359 def footnoteref_id(index = local_attr(:index)) "_footnoteref_#{index}" end |
#formatted_source ⇒ String?
See SyntaxHighlighter#format.
487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/asciidoctor/html5s/converter.rb', line 487 def formatted_source hl = document.syntax_highlighter or return nil opts = { nowrap: nowrap? } if hl.highlight? opts[:css_mode] = document.attr("#{hl.name}-css", :class).to_sym opts[:style] = document.attr("#{hl.name}-style") end hl.format(self, source_lang, opts) end |
#html_meta_if(name, content) ⇒ String?
Returns HTML meta tag if the given content is not nil.
634 635 636 |
# File 'lib/asciidoctor/html5s/converter.rb', line 634 def (name, content) %(<meta name="#{name}" content="#{content}">) if content end |
#html_tag(name, attributes = {}, content = nil) { ... } ⇒ String
Creates an HTML tag with the given name and optionally attributes. Can take a block that will run between the opening and closing tags.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/asciidoctor/html5s/converter.rb', line 115 def html_tag(name, attributes = {}, content = nil) attrs = attributes.inject([]) do |attrs, (k, v)| next attrs if !v || v.nil_or_empty? v = v.compact.join(' ') if v.is_a? Array attrs << (v == true ? k : %(#{k}="#{v}")) end attrs_str = attrs.empty? ? '' : ' ' + attrs.join(' ') if VOID_ELEMENTS.include? name.to_s %(<#{name}#{attrs_str}>) else content ||= yield if block_given? %(<#{name}#{attrs_str}>#{content}</#{name}>) end end |
#html_tag_if(condition, name, attributes = {}, content = nil) { ... } ⇒ String
Conditionally wraps a block in an element. If condition is true then it renders the specified tag with optional attributes and the given block inside, otherwise it just renders the block.
For example:
= html_tag_if link?, 'a', {class: 'image', href: (attr :link)}
img src='./img/tux.png'
will produce:
<a href="http://example.org" class="image">
<img src="./img/tux.png">
</a>
if link? is truthy, and just
<img src="./img/tux.png">
otherwise.
161 162 163 164 165 166 167 |
# File 'lib/asciidoctor/html5s/converter.rb', line 161 def html_tag_if(condition, name, attributes = {}, content = nil, &block) if condition html_tag name, attributes, content, &block else content || yield end end |
#icon_fa_classes ⇒ Array
Returns style classes for a Font Awesome icon.
745 746 747 748 749 750 751 |
# File 'lib/asciidoctor/html5s/converter.rb', line 745 def icon_fa_classes [ "fa fa-#{target}", ("fa-#{attr :size}" if attr? :size), ("fa-rotate-#{attr :rotate}" if attr? :rotate), ("fa-flip-#{attr :flip}" if attr? :flip) ].compact end |
#image_link ⇒ String?
Returns an URL for the image’s link.
457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/asciidoctor/html5s/converter.rb', line 457 def image_link @_html5s_image_link ||= case (link = attr(:link)) when 'none', 'false' return when 'self' image_uri(attr(:target)) when nil, '' image_uri(attr(:target)) if document.attr?('html5s-image-default-link', 'self') else link end end |
#image_link_label ⇒ String?
Returns a label/title of the image link.
473 474 475 476 477 |
# File 'lib/asciidoctor/html5s/converter.rb', line 473 def image_link_label if image_uri(attr(:target)) == image_link document.attr('html5s-image-self-link-label', 'Open the image in full size') end end |
#link_rel ⇒ Object
419 420 421 422 423 424 425 426 |
# File 'lib/asciidoctor/html5s/converter.rb', line 419 def link_rel rel = [ ('nofollow' if option?('nofollow')), ('noopener' if option?('noopener') || local_attr(:window) == '_blank') ].compact rel.empty? ? nil : rel.join(' ') end |
#local_attr(name, default_val = nil) ⇒ Object
Gets the value of the specified attribute in this node.
This is just an alias for attr method with disabled inherit to make it more clear.
329 330 331 |
# File 'lib/asciidoctor/html5s/converter.rb', line 329 def local_attr(name, default_val = nil) attr(name, default_val, false) end |
#local_attr?(name, expect_val = nil) ⇒ Boolean
Checks if the attribute is defined on this node, optionally performing a comparison of its value if expect_val is not nil.
This is just an alias for attr? method with disabled inherit to make it more clear.
345 346 347 |
# File 'lib/asciidoctor/html5s/converter.rb', line 345 def local_attr?(name, expect_val = nil) attr?(name, expect_val, false) end |
#log ⇒ Logger
62 63 64 |
# File 'lib/asciidoctor/html5s/converter.rb', line 62 def log ::Asciidoctor::LoggerManager.logger end |
#nowrap? ⇒ Boolean
363 364 365 |
# File 'lib/asciidoctor/html5s/converter.rb', line 363 def nowrap? 'nowrap' if !document.attr?(:prewrap) || option?('nowrap') end |
#partintro_allowed? ⇒ Boolean
Returns true if a partintro block is allowed in this context, otherwise prints warning and returns false.
541 542 543 544 545 546 547 |
# File 'lib/asciidoctor/html5s/converter.rb', line 541 def partintro_allowed? if result = (level != 0 || parent.context != :section || document.doctype != 'book') log.warn "asciidoctor: ERROR: partintro block can only be used when doctype is book and must be a child of a book part. Excluding block content." end !result end |
#print_item_content(item) ⇒ Object
367 368 369 370 |
# File 'lib/asciidoctor/html5s/converter.rb', line 367 def print_item_content(item) wrap = item.blocks? && !item.blocks.all? { |b| b.is_a? ::Asciidoctor::List } [ (html_tag_if(wrap, :p) { item.text } if item.text?), item.content ].join end |
#revdate_iso ⇒ String?
Returns the revision date in ISO 8601, or nil if not available or in invalid format.
621 622 623 624 625 |
# File 'lib/asciidoctor/html5s/converter.rb', line 621 def revdate_iso ::Date.parse(revdate).iso8601 if defined? ::Date rescue ArgumentError nil end |
#section_level(sec = self) ⇒ Integer
Returns corrected section level.
378 379 380 |
# File 'lib/asciidoctor/html5s/converter.rb', line 378 def section_level(sec = self) (sec.level == 0 && sec.special) ? 1 : sec.level end |
#section_title(sec = self, drop_anchors: false) ⇒ String
Returns the captioned section’s title, optionally numbered.
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/asciidoctor/html5s/converter.rb', line 389 def section_title(sec = self, drop_anchors: false) title = if sec.caption sec.captioned_title elsif sec.numbered && sec.level <= document.attr(:sectnumlevels, DEFAULT_SECTNUMLEVELS).to_i if sec.level < 2 && document.doctype == 'book' && %w[chapter part].include?(sec.sectname) signifier = document.attr("#{sec.sectname}-signifier") sectnum = sec.sectname == 'part' ? sec.sectnum(nil, ':') : sec.sectnum "#{signifier&.+ ' '}#{sectnum} #{sec.title}" else "#{sec.sectnum} #{sec.title}" end else sec.title end if drop_anchors && title.include?('<a') title.gsub(/<(?:a[^>+]+|\/a)>/, '') else title end end |
#single_quoted(text) ⇒ String
Returns quoted text.
766 767 768 769 |
# File 'lib/asciidoctor/html5s/converter.rb', line 766 def single_quoted(text) quotes = CURLY_QUOTES[attr(:lang, DEFAULT_LANG, true)] "#{quotes[0]}#{text}#{quotes[1]}" end |
#source_code_class ⇒ Object
This is needed only for Asciidoctor <2.0.0.
515 516 517 518 519 520 521 |
# File 'lib/asciidoctor/html5s/converter.rb', line 515 def source_code_class if document.attr? 'source-highlighter', 'highlightjs' "language-#{source_lang || 'none'} hljs" elsif source_lang "language-#{source_lang}" end end |
#source_lang ⇒ Object
510 511 512 |
# File 'lib/asciidoctor/html5s/converter.rb', line 510 def source_lang local_attr :language, false end |
#stem_lang ⇒ String
Returns language of STEM block or inline node (tex or asciimath).
414 415 416 417 |
# File 'lib/asciidoctor/html5s/converter.rb', line 414 def stem_lang value = (inline? ? type : style).to_s value == 'latexmath' ? 'tex' : value end |
#stretch? ⇒ Boolean
557 558 559 560 561 |
# File 'lib/asciidoctor/html5s/converter.rb', line 557 def stretch? if !autowidth? || local_attr?('width') 'stretch' if attr? :tablepcwidth, 100 end end |
#style_value(declarations) ⇒ String?
Formats the given hash as CSS declarations for an inline style.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/asciidoctor/html5s/converter.rb', line 291 def style_value(declarations) decls = [] declarations.each do |prop, value| next if value.nil? if value.is_a? Array value, unit = value next if value.nil? value = value.to_s + unit unless value.end_with? unit end prop = prop.to_s.gsub('_', '-') decls << "#{prop}: #{value}" end decls.empty? ? nil : decls.join('; ') + ';' end |
#styles_and_scripts ⇒ Object
Returns formatted style/link and script tags for header.
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/asciidoctor/html5s/converter.rb', line 639 def styles_and_scripts scripts = [] styles = [] = [] stylesheet = attr :stylesheet stylesdir = attr :stylesdir, '' default_style = ::Asciidoctor::DEFAULT_STYLESHEET_KEYS.include? stylesheet ss = ::Asciidoctor::Stylesheets.instance if attr?(:linkcss) path = default_style ? ::Asciidoctor::DEFAULT_STYLESHEET_NAME : stylesheet styles << { href: [stylesdir, path] } elsif default_style styles << { text: ss.primary_stylesheet_data } else styles << { text: read_asset(normalize_system_path(stylesheet, stylesdir), true) } end if attr? :icons, 'font' if attr? 'iconfont-remote' styles << { href: attr('iconfont-cdn', FONT_AWESOME_URI) } else styles << { href: [stylesdir, "#{attr 'iconfont-name', 'font-awesome'}.css"] } end end if attr? 'stem' styles << { href: KATEX_CSS_URI } scripts << { src: KATEX_JS_URI } scripts << { text: KATEX_RENDER_CODE } end if !defined?(::Asciidoctor::SyntaxHighlighter) # Asciidoctor <2.0.0 if attr? 'source-highlighter', 'highlightjs' hjs_base = attr :highlightjsdir, HIGHLIGHTJS_BASE_URI hjs_theme = attr 'highlightjs-theme', DEFAULT_HIGHLIGHTJS_THEME scripts << { src: [hjs_base, 'highlight.min.js'] } scripts << { text: 'hljs.initHighlightingOnLoad()' } styles << { href: [hjs_base, "styles/#{hjs_theme}.min.css"] } end end styles.each do |item| if item.key?(:text) << html_tag(:style) { item[:text] } else << html_tag(:link, rel: 'stylesheet', href: urlize(*item[:href])) end end scripts.each do |item| if item.key? :text << html_tag(:script, type: item[:type]) { item[:text] } else << html_tag(:script, type: item[:type], src: urlize(*item[:src])) end end if defined?(::Asciidoctor::SyntaxHighlighter) && (hl = syntax_highlighter) # Asciidoctor >=2.0.0 # XXX: We don't care about the declared location and put all to head. [:head, :footer].each do |location| if hl.docinfo?(location) << hl.docinfo(location, self, cdn_base_url: CDN_BASE_URI, linkcss: attr?(:linkcss)) end end end .join("\n") end |
#url_query(params) ⇒ Object
Formats URL query parameters.
605 606 607 608 609 610 611 612 |
# File 'lib/asciidoctor/html5s/converter.rb', line 605 def url_query(params) str = params.map { |k, v| next if v.nil? || v.to_s.empty? [k, v] * '=' }.compact.join('&') '?' + str unless str.empty? end |
#urlize(*segments) ⇒ Object
309 310 311 312 313 314 315 316 |
# File 'lib/asciidoctor/html5s/converter.rb', line 309 def urlize(*segments) path = segments * '/' if path.start_with? '//' @_html5s_uri_scheme ||= document.attr('asset-uri-scheme', 'https') path = "#{@_html5s_uri_scheme}:#{path}" unless @_html5s_uri_scheme.empty? end normalize_web_path path end |
#video_iframe? ⇒ Boolean
Returns true if the video should be embedded in an iframe.
568 569 570 |
# File 'lib/asciidoctor/html5s/converter.rb', line 568 def video_iframe? ['vimeo', 'youtube'].include? attr(:poster) end |
#video_uri ⇒ Object
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/asciidoctor/html5s/converter.rb', line 572 def video_uri case attr(:poster, '').to_sym when :vimeo params = { autoplay: (1 if option? 'autoplay'), loop: (1 if option? 'loop'), muted: (1 if option? 'muted') } start_anchor = "#at=#{attr :start}" if attr? :start "//player.vimeo.com/video/#{attr :target}#{start_anchor}#{url_query params}" when :youtube video_id, list_id = attr(:target).split('/', 2) params = { rel: 0, start: (attr :start), end: (attr :end), list: (attr :list, list_id), autoplay: (1 if option? 'autoplay'), loop: (1 if option? 'loop'), muted: (1 if option? 'muted'), controls: (0 if option? 'nocontrols') } "//www.youtube.com/embed/#{video_id}#{url_query params}" else anchor = [attr(:start), attr(:end)].join(',').chomp(',') anchor = '' if anchor == ',' # XXX: https://github.com/opal/opal/issues/1902 anchor = '#t=' + anchor unless anchor.empty? media_uri "#{attr :target}#{anchor}" end end |
#xref_text ⇒ String
Returns text of the xref anchor.
716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/asciidoctor/html5s/converter.rb', line 716 def xref_text str = if text text elsif (path = local_attr :path) path else ref = document.catalog[:refs][attr :refid] if ref.kind_of? Asciidoctor::AbstractNode ref.xreftext(attr(:xrefstyle, nil, true)) end end (str || "[#{attr :refid}]").tr_s("\n", ' ') end |
#yield_capture(*params) ⇒ Object
Yields the captured block (see #capture).
101 102 103 |
# File 'lib/asciidoctor/html5s/converter.rb', line 101 def yield_capture(*params) @_html5s_capture.call(*params) if @_html5s_capture end |