riboseinc / asciidoctor-bibliography

Citations in AsciiDoc
MIT License
30 stars 8 forks source link

Fix parser discarding original header attributes #28

Closed ronaldtse closed 7 years ago

ronaldtse commented 7 years ago

Previously other header attributes (title, toc, etc) will be missing due to this code:

def extract_header_attributes(reader)
  ::Asciidoctor::Parser
  .parse(reader, ::Asciidoctor::Document.new, header_only: true)
  .attributes

The reason is that reader is shared by our gem and the original Asciidoctor::Document. In the gem if we first use parser to read all headers, the original Document no longer parses them because the reader's Cursor has already advanced past the header.

Therefore we use a newly created trio of the Document, Reader and Parser to achieve this parsing here.