org v0.1.0 Org.Document

Represents an interpreted document.

Documents are organized as a tree of sections, each of which has a title and optional contents. The document can also have contents at the top level.

Link to this section Summary

Functions

Prepend a comment to the list of comments. Used by the parser

Retrieve current contents of document

Prepend content to the currently deepest section, or toplevel if no sections exist

Reverses the document’s entire content recursively

Update the last prepended content. Yields the content to the given updater

Link to this section Types

Link to this type t()
t() :: %Org.Document{comments: [String.t()], contents: [Org.Content.t()], sections: [Org.Section.t()]}

Link to this section Functions

Link to this function add_comment(doc, comment)

Prepend a comment to the list of comments. Used by the parser

Link to this function add_subsection(doc, level, title)
Link to this function contents(document)

Retrieve current contents of document

Link to this function prepend_content(doc, content)

Prepend content to the currently deepest section, or toplevel if no sections exist.

Link to this function reverse_recursive(doc)

Reverses the document’s entire content recursively.

Uses Org.Section.reverse_recursive/1 and Org.Content.reverse_recursive/1 to reverse sections and contents.

Example (comments):

iex> doc = %Org.Document{}
iex> doc = Org.Document.add_comment(doc, "first")
iex> doc = Org.Document.add_comment(doc, "second")
iex> doc = Org.Document.add_comment(doc, "third")
iex> doc.comments
["third", "second", "first"]
iex> doc = Org.Document.reverse_recursive(doc)
iex> doc.comments
["first", "second", "third"]

Example (sections):

iex> doc = %Org.Document{}
iex> doc = Org.Document.add_subsection(doc, 1, "First")
iex> doc = Org.Document.add_subsection(doc, 1, "Second")
iex> doc = Org.Document.add_subsection(doc, 1, "Third")
iex> for %Org.Section{title: title} <- doc.sections, do: title
["Third", "Second", "First"]
iex> doc = Org.Document.reverse_recursive(doc)
iex> for %Org.Section{title: title} <- doc.sections, do: title
["First", "Second", "Third"]

Example (contents):

iex> doc = %Org.Document{}
iex> doc = Org.Document.prepend_content(doc, %Org.Paragraph{lines: ["first paragraph, first line"]})
iex> doc = Org.Document.update_content(doc, fn p -> Org.Paragraph.prepend_line(p, "first paragraph, second line") end)
iex> doc = Org.Document.prepend_content(doc, %Org.Paragraph{lines: ["second paragraph, first line"]})
iex> doc = Org.Document.update_content(doc, fn p -> Org.Paragraph.prepend_line(p, "second paragraph, second line") end)
iex> Org.Document.contents(doc)
[%Org.Paragraph{lines: ["second paragraph, second line", "second paragraph, first line"]},
 %Org.Paragraph{lines: ["first paragraph, second line", "first paragraph, first line"]}]
iex> doc = Org.Document.reverse_recursive(doc)
iex> Org.Document.contents(doc)
[%Org.Paragraph{lines: ["first paragraph, first line", "first paragraph, second line"]},
 %Org.Paragraph{lines: ["second paragraph, first line", "second paragraph, second line"]}]
Link to this function update_content(doc, updater)

Update the last prepended content. Yields the content to the given updater.