Book

class lira.book.Book(root: pathlib.Path)

Class representation of a lira book.

The parse() method should be called to initialize the metadata and chapters attributes.

from pathlib import Path
from lira.book import Book

book = Book(Path('books/example/'))
book.parse()
print(chapter.metadata)
print(chapter.chapters)
Parameters

root – Path to the root directory of the book

chapters

List of lira.book.BookChapter instances

metadata

Dictionary with the metadata from the book

parse(all: bool = False)

Parse the book metadata.

Parameters

all – If True all chapters are parsed as well

class lira.book.BookChapter(*, book, file: pathlib.Path, title: str = None)

Class representation of a chapter.

The parse() method should be called to initialize the metadata and contents attributes.

Currently, the lira.parsers.rst.RSTParser parser is used by default.

from pathlib import Path
from lira.book import BookChapter

chapter = BookChapter(Path('intro.rst'))
chapter.parse()
print(chapter.metadata)
print(chapter.contents)
print(chapter.toc())
Parameters
  • file – File of the chapter

  • title – Title of the chapter (defaults to the name of the file)

contents

List of nodes from lira.parsers.nodes

metadata

Dictionary with the metadata from the book

parse()

Parse the chapter content and initialize its attributes.

toc(depth=2)

Return a list of tuples representing the table of contents.

The first element of the tuple is a lira.parsers.nodes.Section instance, and the second is a list of sub-sections (it can be empty if it doesn’t have subsections).

Parameters

depth – Depth of the table of contents.