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
t() :: %Org.Document{comments: [String.t()], contents: [Org.Content.t()], sections: [Org.Section.t()]}
Link to this section 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.
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"]}]
Update the last prepended content. Yields the content to the given updater.