checkmark

Link code in files with code blocks in markdown, and check that they are up to date, or update them automatically.

Types

Any error that can happen during checking or updating a markdown file. The error type depends on the IO library used.

pub type CheckError(e) {
  CouldNotReadFile(error: e)
  CouldNotWriteFile(error: e)
  TagNotFound(tag: String)
  MultipleTagsFound(tag: String, lines: List(Int))
  ContentDidNotMatch(tag: String)
}

Constructors

  • CouldNotReadFile(error: e)
  • CouldNotWriteFile(error: e)
  • TagNotFound(tag: String)
  • MultipleTagsFound(tag: String, lines: List(Int))
  • ContentDidNotMatch(tag: String)

Contains the configuration for checking files. Not tied to a single file, may contain more configuration later. The error type depends on the IO library used.

pub opaque type Checker(e)

A markdown file to check, which can be linked to snippets in multiple other files. The error type depends on the IO library used.

pub opaque type File(e)

Values

pub fn check(file: File(e)) -> Result(Nil, List(CheckError(e)))

Checks that the markdown file contains code blocks that match the content of the specified files.

pub fn check_or_update(
  file: File(e),
  when should_update: Bool,
) -> Result(Nil, List(CheckError(e)))

Convenience function for either checking or updating depending on a boolean.

pub fn file(checker: Checker(e), filename: String) -> File(e)

Configures a markdown file to be checked or updated.

pub fn new(
  read_file: fn(String) -> Result(String, e),
  write_file: fn(String, String) -> Result(Nil, e),
) -> Checker(e)

Builds a new checker with the provided file IO functions.

pub fn should_contain_contents_of(
  file: File(e),
  source: String,
  tagged tag: String,
) -> File(e)

Specify that the markdown file should contain the contents of another file as a code block. The tag is what comes after the block fence. e.g. “```gleam 1” would match the tag “gleam 1”. Whitespace is trimmed off the tag. Note that you still need to call check, update or check_or_update after this, this function only adds to the configuration.

pub fn update(file: File(e)) -> Result(Nil, List(CheckError(e)))

Updates the code blocks in the markdown file from the specified files.

Search Document