Method: Asciidoctor::Document#doctitle

Defined in:
lib/asciidoctor/document.rb

#doctitle(opts = {}) ⇒ Title Also known as: name

Resolves the primary title for the document

Searches the locations to find the first non-empty value:

* document-level attribute named title
* header title (known as the document title)
* title of the first section
* document-level attribute named untitled-label (if :use_fallback option is set)

If no value can be resolved, nil is returned.

If the :partition attribute is specified, the value is parsed into an Document::Title object. If the :sanitize attribute is specified, XML elements are removed from the value.

TODO separate sanitization by type (:cdata for HTML/XML, :plain_text for non-SGML, false for none)

Returns:

  • (Title)

    Returns the resolved title as a Title if the :partition option is passed or a [String] if not or nil if no value can be resolved.



723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
# File 'lib/asciidoctor/document.rb', line 723

def doctitle opts = {}
  unless (val = @attributes['title'])
    if (sect = first_section)
      val = sect.title
    elsif !(opts[:use_fallback] && (val = @attributes['untitled-label']))
      return
    end
  end

  if (separator = opts[:partition])
    Title.new val, opts.merge({ separator: (separator == true ? @attributes['title-separator'] : separator) })
  elsif opts[:sanitize] && (val.include? '<')
    val.gsub(XmlSanitizeRx, '').squeeze(' ').strip
  else
    val
  end
end