sokf-core 0.9.0

sokf-core holds the logic of the sokf command-line tool: it loads and validates Superdev Open Knowledge Format (SOKF) knowledge stores, and runs each sokf command. Unstable: its interface can change in any release.
Documentation
//! This module holds SOKF's dialect of Markdown, and runs the parser and
//! the marker checks of the Markdown engine with it.

use tramlines_md::{
    grammar::Condition,
    markdown::{Body, Dialect, Segments},
};

/// `SOKF` is the dialect of SOKF's markers: `sokf:only`, `sokf:guidance`, and
/// `sokf:optional`, the include block, the definition block `sokf:links`, and
/// `sokf:` labels.
// sokf-implements: SOKF_FORMAT_139
// sokf-implements: SOKF_FORMAT_154
pub const SOKF: Dialect = Dialect {
    namespace: "sokf",
    region: Some("include"),
    trailer: Some("links"),
    scheme: Some("sokf"),
};

/// `segments` returns the markers of `body`, whose first line is line
/// `first_line` of the file.
pub fn segments(body: &str, first_line: usize) -> Segments {
    tramlines_md::markdown::segments(body, first_line, &SOKF)
}

/// `parse` returns the parsed `body`, whose first line is line `first_line` of
/// the file.
pub fn parse(body: &str, first_line: usize, segments: &Segments) -> Body {
    tramlines_md::markdown::parse(body, first_line, segments, &SOKF)
}

/// `is_only_marker` reports whether `line` is a `sokf:only` marker.
pub fn is_only_marker(line: &str) -> bool {
    SOKF.is_only_marker(line)
}

/// `is_guidance_marker` reports whether `line` is a `sokf:guidance` marker.
pub fn is_guidance_marker(line: &str) -> bool {
    SOKF.is_guidance_marker(line)
}

/// `is_optional_mark` reports whether `line` is either end of a `sokf:optional`
/// region.
pub fn is_optional_mark(line: &str) -> bool {
    SOKF.is_optional_mark(line)
}

/// `only_marker` returns the marker's condition when `line` is a `sokf:only`
/// marker: each map from a dimension to its states, with the maps joined by
/// ` | `.
pub fn only_marker(line: &str) -> Option<Condition> {
    SOKF.only_marker(line)
}

/// `is_markdown` returns whether the file at `path` is Markdown: whether
/// its name ends in `.md`, as every check of sokf reads it.
#[expect(
    clippy::case_sensitive_file_extension_comparisons,
    reason = "only a name that ends in a lowercase `.md` is Markdown, so the comparison is case-sensitive on purpose"
)]
pub fn is_markdown(path: &crate::RepoPath) -> bool {
    path.as_str().ends_with(".md")
}