org v0.1.1 Org

This package implements an org-mode lexer and parser.

org-mode is the markup language used by the powerful org mode package for emacs.

This implementation supports only a small subset of the syntax at this point, but can already be useful for extracting information from well-formed documents.

Features supported are:

  • Comments
  • (nested) Sections
  • Paragraphs
  • Tables

Link to this section Summary

Functions

Extracts all contents from given section or document

Loads a document from a file at given path

Loads a document from the given source string

Extracts all paragraphs from the given section or document

Extracts a section at the given path of titles

Extracts all tables from the given section or document

Link to this section Types

Link to this type load_mode()
load_mode() :: :document | :tokens

Link to this section Functions

Link to this function contents(section_or_document)
contents(Org.Document.t() | Org.Section.t()) :: [Org.Content.t()]

Extracts all contents from given section or document

Link to this function load_file(path, load_mode \\ :document)
load_file(String.t(), load_mode()) :: Org.Document.t()

Loads a document from a file at given path

Link to this function load_string(data, load_mode \\ :document)
load_string(String.t(), load_mode()) :: Org.Document.t()

Loads a document from the given source string

Link to this function paragraphs(section_or_document)
paragraphs(Org.Section.t() | Org.Document.t()) :: [Org.Paragraph.t()]

Extracts all paragraphs from the given section or document

Example:

iex> doc = Org.load_string(~S{
...>First paragraph
...>| x | y |
...>| 1 | 7 |
...>Second paragraph
...>})
iex> Org.paragraphs(doc)
[%Org.Paragraph{lines: ["First paragraph"]}, %Org.Paragraph{lines: ["Second paragraph"]}]
Link to this function section(doc, path)
section(Org.Document.t(), [String.t()]) :: Org.Section.t()

Extracts a section at the given path of titles

Example:

iex> doc = Org.load_string(~S{
...>* First
...>** Second
...>*** Third
...>* Fourth
iex>})
iex> Org.section(doc, ["First"]).title
"First"
iex> Org.section(doc, ["First", "Second", "Third"]).title
"Third"
iex> Org.section(doc, ["Fourth"]).title
"Fourth"
Link to this function tables(section_or_document)

Extracts all tables from the given section or document

Example:

iex> doc = Org.load_string(~S{
...>First paragraph
...>| x | y |
...>| 1 | 7 |
...>Second paragraph
...>})
iex> Org.tables(doc)
[%Org.Table{rows: [%Org.Table.Row{cells: ["x", "y"]}, %Org.Table.Row{cells: ["1", "7"]}]}]