socketry-markdown 0.1.1

CommonMark compliant markdown parser in Rust with ASTs and extensions
Documentation
// Released under the MIT License.
// Copyright, 2024, by Bnchi.
// Copyright, 2024, by Titus Wormer.
// Copyright, 2026, by Samuel Williams.

//! JS equivalent https://github.com/syntax-tree/mdast-util-to-markdown/blob/main/lib/util/format-code-as-indented.js
use crate::markdown::state::State;
use crate::mdast::Code;
use regex::Regex;

pub fn format_code_as_indented(code: &Code, state: &State) -> bool {
    let non_whitespace = code.value.chars().any(|c| !c.is_whitespace());
    let blank = Regex::new(r"^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$").unwrap();

    !state.options.fences
        && !code.value.is_empty()
        && code.lang.is_none()
        && non_whitespace
        && !blank.is_match(&code.value)
}