View Source Gemtext.Parser (Gemtext v0.2.0)
Gemtext parser
Link to this section Summary
Link to this section Types
@type attributes() :: map()
@type content() :: String.t()
@type gemtext_block() :: {tag(), attributes(), content()} | {tag(), content()}
@type gemtext_blocks() :: [gemtext_block()]
@type tag() :: atom()
Link to this section Functions
@spec parse(String.t()) :: gemtext_blocks()
Parses a string of gemtext into a list of gemtext blocks
Note that empty lines are kept as :text
blocks with no content
as per specification.
examples
Examples
iex> Gemtext.Parser.parse("""
...> # Heading 1
...> ## Heading 2
...> ### Heading 3
...>
...> > Quotation Line 1
...> > Quotation Line 2
...>
...> This is normal text Line 1
...> This is normal text Line 2
...> This is a robot emoji 🤖
...>
...> => gemini://gemini.circumlunar.space This is a link
...> => /naked_link
...>
...> * Bullet 1
...> * Bullet 2
...> * Bullet 3
...>
...> ``` title
...> _______________________
...> # #
...> | This is preformatted |
...> | text with two lines |
...> #_______________________#
...> ```
...> """)
[
{:h1, "Heading 1"},
{:h2, "Heading 2"},
{:h3, "Heading 3"},
{:text, ""},
{:quote, "Quotation Line 1"},
{:quote, "Quotation Line 2"},
{:text, ""},
{:text, "This is normal text Line 1"},
{:text, "This is normal text Line 2"},
{:text, "This is a robot emoji 🤖"},
{:text, ""},
{:link, %{to: "gemini://gemini.circumlunar.space"}, "This is a link"},
{:link, %{to: "/naked_link"}, nil},
{:text, ""},
{:li, "Bullet 1"},
{:li, "Bullet 2"},
{:li, "Bullet 3"},
{:text, ""},
{:pre, %{title: "title"}, """
_______________________
# #
| This is preformatted |
| text with two lines |
#_______________________#
"""
},
{:text, ""}
]