///|
/// The type for CommonMark documents.
#derive(Debug)
pub(all) struct Doc {
  nl : String
  block : Block
  defs : LabelDefs
}

///|
#deprecated
#doc(hidden)
pub extend Doc with @debug.Debug::{to_repr}

///|
pub fn Doc::new(
  nl~ : String = "\n",
  defs~ : LabelDefs = Map([]),
  block : Block,
) -> Doc {
  { nl, block, defs, }
}

///|
pub fn Doc::empty() -> Doc {
  Doc::new(Block::empty())
}

///|
/// Selects the math span delimiters available with `strict=false`.
/// `Dollar` enables `$…$` and `$$…$$`; `Latex` enables `\(…\)` and `\[…\]`.
/// `Both` enables both families. This selection does not affect `math` fences.
pub(all) enum MathDelimiters {
  Dollar
  Latex
  Both
}

///|
/// Parse CommonMark. `math_delimiters` defaults to `Dollar` and is ignored
/// when `strict=true`.
pub fn Doc::from_string(
  defs~ : LabelDefs = Map([]),
  resolver~ : LabelResolverFn = LabelContext::default_resolver,
  nested_links~ : Bool = false,
  heading_auto_ids~ : Bool = false,
  layout~ : Bool = false,
  locs~ : Bool = false,
  file~ : FilePath = file_path_none,
  strict~ : Bool = true,
  math_delimiters~ : MathDelimiters = Dollar,
  s : String,
) -> Doc {
  let p = Parser::new(
    defs~,
    resolver~,
    nested_links~,
    heading_auto_ids~,
    layout~,
    locs~,
    file~,
    strict~,
    math_delimiters~,
    s,
  )
  let (nl, doc) = p.parse_block()
  let block = p.block_struct_to_doc(doc)
  Doc::new(nl~, block, defs=p.defs)
}