Module: Asciidoctor::Rhrev::Helpers
- Included in:
- PDF::Rhrev::Converter, Html5Converter
- Defined in:
- lib/asciidoctor/rhrev/helpers.rb
Instance Method Summary collapse
-
#antora_build?(doc) ⇒ Boolean
Check if we’re running under Antora (vs standalone asciidoctor-pdf).
-
#convert_anchor_to_xref(anchor, doc = nil) ⇒ Object
Convert Antora-style anchor ID to standard AsciiDoc xref format for export.
- #debug_log(message, doc = nil) ⇒ Object
- #format_prev_rev(prev_title, prev_date, doc) ⇒ Object
- #needs_asciidoc_cell?(content) ⇒ Boolean
- #preprocess_attribute_content(content_string) ⇒ Object
- #with_attribute_missing_suppressed(doc) ⇒ Object
Instance Method Details
#antora_build?(doc) ⇒ Boolean
Check if we’re running under Antora (vs standalone asciidoctor-pdf)
5 6 7 8 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 5 def antora_build? doc # Antora sets these attributes automatically doc.attr?('page-component-name') || doc.attr?('page-module') || doc.attr?('page-relative-src-path') end |
#convert_anchor_to_xref(anchor, doc = nil) ⇒ Object
Convert Antora-style anchor ID to standard AsciiDoc xref format for export
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 11 def convert_anchor_to_xref anchor, doc = nil return anchor unless anchor # For PDF generation (even in Antora), we want internal links if possible. # Returning the anchor ID directly allows Asciidoctor PDF to resolve it internally. # The previous logic converted to file.adoc#id which creates broken external links in PDF. return anchor # Skip transformation for standalone asciidoctor-pdf builds return anchor if doc && !antora_build?(doc) # Auto-detect separator from the anchor itself # Check for xml_ids separator first (---- four dashes), then default (:::) separator = if anchor.include?('----') '----' elsif anchor.include?(':::') ':::' else nil end if separator # Split into page and fragment parts = anchor.split(separator, 2) page_id = parts[0] fragment = parts[1] "#{page_id}.adoc##{fragment}" else # No separator - just a page reference, add .adoc suffix "#{anchor}.adoc" end end |
#debug_log(message, doc = nil) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 90 def debug_log(, doc = nil) return unless doc&.attr?('rhrev-debug') if doc.respond_to?(:logger) doc.logger.debug "[RHREV] #{}" else warn "[RHREV] #{}" end end |
#format_prev_rev(prev_title, prev_date, doc) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 55 def format_prev_rev prev_title, prev_date, doc return "" if prev_title.to_s.empty? # Only include date if rhrev-customization-prevrev-include-date attribute is set include_date = doc.attr? 'rhrev-customization-prevrev-include-date' if include_date && !prev_date.to_s.empty? date_format = doc.attr 'rhrev-customization-date-format', '%Y-%m-%d' begin # Try to parse and format date if possible parsed_date = Date.parse(prev_date) formatted_date = parsed_date.strftime(date_format) "#{prev_title} - #{formatted_date}" rescue # Fallback if date parsing fails "#{prev_title} - #{prev_date}" end else "#{prev_title}" end end |
#needs_asciidoc_cell?(content) ⇒ Boolean
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 77 def needs_asciidoc_cell? content return false unless content # Check for AsciiDoc formatting markers content.include?('*') || content.include?('_') || content.include?('`') || content.include?('http') || content.include?('xref:') || content.include?('<<') || content.include?('link:') || content.include?('+') # Line breaks end |
#preprocess_attribute_content(content_string) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 44 def preprocess_attribute_content content_string # Preprocess attribute content to handle AsciiDoc line continuations # Compatible with both .yml and .adoc import statements return content_string unless content_string # Replace " +" with hard line break, but preserve escaped " \+" # Also handle literal \n sequences if they come from YAML content_string.gsub('\\n', "\n") .gsub(/(?<!\\) \+$/, " +") end |
#with_attribute_missing_suppressed(doc) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/asciidoctor/rhrev/helpers.rb', line 99 def with_attribute_missing_suppressed doc # Suppress attribute-missing warnings # Save current attribute-missing setting saved_attribute_missing = doc.attr 'attribute-missing' # Set to skip to suppress warnings doc.set_attr 'attribute-missing', 'skip' yield ensure # Restore attribute-missing setting if saved_attribute_missing doc.set_attr 'attribute-missing', saved_attribute_missing else doc.delete_attr 'attribute-missing' end end |