Dextrin.Schema.Docs.Markdown (Dextrin v0.3.3)

Copy Markdown View Source

The Markdown a schema's comments are written in, as HTML -- a small, fixed subset, so that every implementation renders a comment the same:

  • blocks: paragraphs, separated by a blank line; a bullet list, each item a line starting -; a numbered list, each item a line starting 1. (any number). An item continues on the lines below it that are indented.
  • inline: `code`, **strong**, *emphasis*, and [text](https://...) links.

A code span that names a definition the documentation knows becomes a link to it; link answers the address for a name, or nil. Everything else is escaped and kept as written.

Summary

Functions

text with the characters HTML gives a meaning to escaped.

One line of text with its inline markup as HTML.

text as HTML, link resolving a code span to an address.

Functions

escape(text)

@spec escape(String.t()) :: String.t()

text with the characters HTML gives a meaning to escaped.

iex> Dextrin.Schema.Docs.Markdown.escape(~s(<a & "b">))
"&lt;a &amp; &quot;b&quot;&gt;"

inline(text, link)

@spec inline(String.t(), (String.t() -> String.t() | nil)) :: String.t()

One line of text with its inline markup as HTML.

iex> Dextrin.Schema.Docs.Markdown.inline("[guide](https://example.com) *now*", fn _ -> nil end)
~s(<a href="https://example.com">guide</a> <em>now</em>)

to_html(text, link)

@spec to_html(String.t(), (String.t() -> String.t() | nil)) :: String.t()

text as HTML, link resolving a code span to an address.

iex> Dextrin.Schema.Docs.Markdown.to_html("An **exact** `amount`.", fn _ -> nil end)
"<p>An <strong>exact</strong> <code>amount</code>.</p>"