blogatto/config/markdown

Configuration for rendering blog articles from markdown files.

The MarkdownConfig controls how markdown files are discovered, parsed, and rendered into HTML. It holds Components used for rendering markdown AST nodes, the filesystem paths to search for markdown files, and an optional template function for customizing blog post page layout.

Example

import blogatto/config/markdown

let md_config =
  markdown.default()
  |> markdown.markdown_path("./blog")
  |> markdown.h1(fn(id, children) {
    html.h1([attribute.id(id), attribute.class("title")], children)
  })

Types

Text alignment for table cells.

pub type Alignment {
  Left
  Center
  Right
}

Constructors

  • Left

    Left-aligned text (the default for most table cells).

  • Center

    Center-aligned text.

  • Right

    Right-aligned text.

A record of view functions that control how each markdown element is rendered.

Components are rendered bottom-up: children are rendered first, then passed to the parent component function as a List(Element(msg)). When implementing a custom component, you must pass the children into the element you return, otherwise they will not appear in the output.

pub type Components(msg) {
  Components(
    a: fn(
      String,
      option.Option(String),
      List(element.Element(msg)),
    ) -> element.Element(msg),
    blockquote: fn(List(element.Element(msg))) -> element.Element(
      msg,
    ),
    checkbox: fn(Bool) -> element.Element(msg),
    code: fn(option.Option(String), List(element.Element(msg))) -> element.Element(
      msg,
    ),
    del: fn(List(element.Element(msg))) -> element.Element(msg),
    em: fn(List(element.Element(msg))) -> element.Element(msg),
    footnote: fn(Int, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    h1: fn(String, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    h2: fn(String, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    h3: fn(String, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    h4: fn(String, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    h5: fn(String, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    h6: fn(String, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    hr: fn() -> element.Element(msg),
    img: fn(String, String, option.Option(String)) -> element.Element(
      msg,
    ),
    li: fn(List(element.Element(msg))) -> element.Element(msg),
    mark: fn(List(element.Element(msg))) -> element.Element(msg),
    ol: fn(option.Option(Int), List(element.Element(msg))) -> element.Element(
      msg,
    ),
    p: fn(List(element.Element(msg))) -> element.Element(msg),
    pre: fn(List(element.Element(msg))) -> element.Element(msg),
    strong: fn(List(element.Element(msg))) -> element.Element(msg),
    table: fn(List(element.Element(msg))) -> element.Element(msg),
    tbody: fn(List(element.Element(msg))) -> element.Element(msg),
    td: fn(Alignment, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    th: fn(Alignment, List(element.Element(msg))) -> element.Element(
      msg,
    ),
    thead: fn(List(element.Element(msg))) -> element.Element(msg),
    tr: fn(List(element.Element(msg))) -> element.Element(msg),
    ul: fn(List(element.Element(msg))) -> element.Element(msg),
  )
}

Constructors

Configuration for discovering and rendering blog articles from markdown files.

The components field specifies the components used to render each markdown AST node (headings, paragraphs, code blocks, etc.). The paths field lists directories to recursively search for markdown post directories. The route_prefix field sets the URL prefix under which blog posts are placed in the output directory (e.g., "blog" produces output_dir/blog/{slug}/index.html). The template field optionally overrides the default blog post page template.

pub type MarkdownConfig(msg) {
  MarkdownConfig(
    components: Components(msg),
    excerpt_len: Int,
    paths: List(String),
    route_prefix: option.Option(String),
    template: option.Option(
      fn(post.Post(msg), List(post.Post(msg))) -> element.Element(
        msg,
      ),
    ),
  )
}

Constructors

  • MarkdownConfig(
      components: Components(msg),
      excerpt_len: Int,
      paths: List(String),
      route_prefix: option.Option(String),
      template: option.Option(
        fn(post.Post(msg), List(post.Post(msg))) -> element.Element(
          msg,
        ),
      ),
    )

    Arguments

    components

    Components used for rendering markdown AST nodes into Lustre elements.

    excerpt_len

    Maximum character length for auto-generated post excerpts. (default: 200)

    paths

    Directories to recursively search for markdown post directories.

    route_prefix

    URL prefix for blog post output paths. When None, posts are written directly under output_dir/{slug}/index.html. When Some("blog"), posts are written to output_dir/blog/{slug}/index.html.

    template

    Optional custom template for rendering a blog post page. Receives the parsed Post, and all the other posts, and returns a full page element. When None, Blogatto uses a minimal default template.

Values

pub fn a(
  config: MarkdownConfig(msg),
  view: fn(
    String,
    option.Option(String),
    List(element.Element(msg)),
  ) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the a component used for links.

The first argument is the link href, the second is an optional title, and the third is the list of children elements.

pub fn blockquote(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the blockquote component used for block quotes.

pub fn checkbox(
  config: MarkdownConfig(msg),
  view: fn(Bool) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the checkbox component used for task list checkboxes.

The argument indicates whether the checkbox is checked.

pub fn code(
  config: MarkdownConfig(msg),
  view: fn(option.Option(String), List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the code component used for inline code and code blocks.

The first argument is the optional language identifier (e.g. Some("gleam") for fenced code blocks with a language tag, None for inline code).

pub fn components(
  config: MarkdownConfig(msg),
  components: Components(msg),
) -> MarkdownConfig(msg)

Set the Components used for rendering markdown.

pub fn default() -> MarkdownConfig(msg)

Create a default MarkdownConfig with default components, no search paths, no route prefix, and no custom template.

pub fn default_components() -> Components(msg)

Return the default components, rendering each markdown element as its corresponding HTML element without additional attributes or styling.

pub fn del(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the del component used for strikethrough text.

pub fn em(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the em component used for emphasized (italic) text.

pub fn excerpt_len(
  config: MarkdownConfig(msg),
  len: Int,
) -> MarkdownConfig(msg)

Set the maximum character length for auto-generated post excerpts.

pub fn footnote(
  config: MarkdownConfig(msg),
  view: fn(Int, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the footnote component used for footnote references.

The first argument is the footnote number, the second is the children elements.

pub fn h1(
  config: MarkdownConfig(msg),
  view: fn(String, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the h1 component used for level 1 headings.

The first argument is the heading id, the second is the children elements.

pub fn h2(
  config: MarkdownConfig(msg),
  view: fn(String, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the h2 component used for level 2 headings.

The first argument is the heading id, the second is the children elements.

pub fn h3(
  config: MarkdownConfig(msg),
  view: fn(String, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the h3 component used for level 3 headings.

The first argument is the heading id, the second is the children elements.

pub fn h4(
  config: MarkdownConfig(msg),
  view: fn(String, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the h4 component used for level 4 headings.

The first argument is the heading id, the second is the children elements.

pub fn h5(
  config: MarkdownConfig(msg),
  view: fn(String, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the h5 component used for level 5 headings.

The first argument is the heading id, the second is the children elements.

pub fn h6(
  config: MarkdownConfig(msg),
  view: fn(String, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the h6 component used for level 6 headings.

The first argument is the heading id, the second is the children elements.

pub fn hr(
  config: MarkdownConfig(msg),
  view: fn() -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the hr component used for thematic breaks (horizontal rules).

pub fn img(
  config: MarkdownConfig(msg),
  view: fn(String, String, option.Option(String)) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the img component used for images.

The first argument is the image URI, the second is the alt text, and the third is an optional title.

pub fn li(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the li component used for list items.

pub fn mark(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the mark component used for highlighted text.

pub fn markdown_path(
  config: MarkdownConfig(msg),
  path: String,
) -> MarkdownConfig(msg)

Add a directory path to search for markdown post directories.

Paths are searched recursively, so adding "./blog" also covers "./blog/nested". There is no need to add subdirectories separately.

pub fn ol(
  config: MarkdownConfig(msg),
  view: fn(option.Option(Int), List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the ol component used for ordered lists.

The first argument is an optional start number, the second is the list of children elements.

pub fn p(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the p component used for paragraphs.

pub fn pre(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the pre component used for preformatted code blocks.

pub fn route_prefix(
  config: MarkdownConfig(msg),
  prefix: String,
) -> MarkdownConfig(msg)

Set the URL prefix used for blog post output paths.

When set to "blog", posts are written to output_dir/blog/{slug}/index.html (or output_dir/blog/{lang}/{slug}/index.html for localized posts). When not set, posts go directly under output_dir.

This prefix also affects the absolute URLs generated for each post (used in RSS feeds and sitemaps). For example, with a site URL of "https://example.com" and a route prefix of "blog", post URLs become "https://example.com/blog/{slug}/".

pub fn strong(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the strong component used for bold text.

pub fn table(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the table component used for tables.

pub fn tbody(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the tbody component used for table body groups.

pub fn td(
  config: MarkdownConfig(msg),
  view: fn(Alignment, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the td component used for table data cells.

The first argument is the column alignment, the second is the list of children elements.

pub fn template(
  config: MarkdownConfig(msg),
  template: fn(post.Post(msg), List(post.Post(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set a custom template function for rendering blog post pages.

The template receives a fully parsed Post (with rendered contents) and all the other posts, and returns the complete page element. When not set, Blogatto uses a minimal default template with the post title and contents.

pub fn th(
  config: MarkdownConfig(msg),
  view: fn(Alignment, List(element.Element(msg))) -> element.Element(
    msg,
  ),
) -> MarkdownConfig(msg)

Set the th component used for table header cells.

The first argument is the column alignment, the second is the list of children elements.

pub fn thead(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the thead component used for table header groups.

pub fn tr(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the tr component used for table rows.

pub fn ul(
  config: MarkdownConfig(msg),
  view: fn(List(element.Element(msg))) -> element.Element(msg),
) -> MarkdownConfig(msg)

Set the ul component used for unordered lists.

Search Document