Cohere.Markdown (Cohere v0.1.0)

Copy Markdown View Source

Frontmatter and section mechanics shared by every authored artifact — intent cards and design docs.

Frontmatter is a hand-parsed key/value block, deliberately not YAML: the keys cohere manages are flat strings, and a YAML parser would be a dependency consumers inherit for no expressive gain.

Summary

Functions

Appends a line to the named ## section, creating the section at the end if absent.

Backticked, fully-qualified code references in markdown text: [{module_string, function_name | nil, arity | nil}], deduped in order. HTML comments are stripped first — a ref in a skeleton prompt is an example, not a claim.

Whether a code_refs/1 tuple resolves in the compiled app: the module loads, and the function (when given) is exported at that arity.

Rewrites the frontmatter block, emitting keys in order with values from front. Keys whose value is nil or empty are dropped.

Parses ##-delimited sections into a %{"Heading" => content} map.

Splits a document into {:ok, frontmatter_map, body}, where the frontmatter is the leading --- block parsed as key: value lines.

Functions

append_to_section(text, section, line)

Appends a line to the named ## section, creating the section at the end if absent.

code_refs(text)

Backticked, fully-qualified code references in markdown text: [{module_string, function_name | nil, arity | nil}], deduped in order. HTML comments are stripped first — a ref in a skeleton prompt is an example, not a claim.

ref_exists?(arg)

Whether a code_refs/1 tuple resolves in the compiled app: the module loads, and the function (when given) is exported at that arity.

replace_frontmatter(text, keys, front)

Rewrites the frontmatter block, emitting keys in order with values from front. Keys whose value is nil or empty are dropped.

sections(body)

Parses ##-delimited sections into a %{"Heading" => content} map.

split_frontmatter(text)

@spec split_frontmatter(String.t()) ::
  {:ok, %{required(String.t()) => String.t()}, String.t()}
  | {:error, :no_frontmatter}

Splits a document into {:ok, frontmatter_map, body}, where the frontmatter is the leading --- block parsed as key: value lines.