checkmark
Link code in files with code blocks in markdown or comments, 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)
FailedToLoadCodeSegment(file: String, reason: String)
CouldNotParseSnippetSource
}
Constructors
-
CouldNotReadFile(error: e) -
CouldNotWriteFile(error: e) -
TagNotFound(tag: String) -
MultipleTagsFound(tag: String, lines: List(Int)) -
ContentDidNotMatch(tag: String) -
FailedToLoadCodeSegment(file: String, reason: String) -
CouldNotParseSnippetSource
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)
pub type CodeSegment {
Function(name: String)
FunctionBody(name: String)
TypeDefinition(name: String)
}
Constructors
-
Function(name: String) -
FunctionBody(name: String) -
TypeDefinition(name: String)
A gleam source file, from which snippets can be loaded.
pub opaque type CodeSnippetSource
Values
pub fn check(file: File(e)) -> Result(Nil, List(CheckError(e)))
Checks that the markdown or Gleam source code file contains code blocks that match the content as specified.
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 comments_in(
checker: Checker(e),
filename: String,
) -> File(e)
Configures comments in a gleam source file to be checked or updated.
pub fn document(checker: Checker(e), filename: String) -> File(e)
Configures a markdown document to be checked or updated.
pub fn file(checker: Checker(e), filename: String) -> File(e)
Deprecated: Use document instead
Configures a markdown file to be checked or updated.
pub fn load_snippet_source(
checker: Checker(e),
filename: String,
) -> Result(CodeSnippetSource, CheckError(e))
Loads a gleam source file to extract snippets from.
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),
filename: String,
tagged tag: String,
) -> File(e)
Specify that the 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 should_contain_snippet_from(
file: File(e),
source: CodeSnippetSource,
segment: CodeSegment,
tagged tag: String,
) -> File(e)
Specify that the file should contain a code snippet from a Gleam source file.
The tag is what comes after the block fence and gleam.
e.g. “```gleam 1” would match the tag “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 or Gleam source file from the specified files.