Search results

There are no results.

markdown.split_front_matter

Show source code
Hide source code
fn pub split_front_matter(input: String) -> (String, String) {
  if !input.starts_with?('---\n') { return ('', input) }

  match input.index_of(value: '\n---', starting_at: 3) {
    case Some(idx) -> {
      let mut rest = idx + 4

      # If the closing marker is followed by a newline, we'll swallow the
      # newline.
      if rest < input.size and input.get(rest).or_panic == 10 { rest += 1 }

      (
        if idx > 3 { input.slice(start: 4, end: idx).to_string } else { '' },
        input.slice(start: rest, end: input.size).to_string,
      )
    }
    case _ -> ('', input)
  }
}
fn pub static split_front_matter(input: String) -> (String, String)

Splits a document into two chunks: one containing the raw front matter, and the other containing the rest of the document.

This methods expects --- is used to signal the start and end of the front matter.

Examples

import markdown

markdown.extract_front_matter("---\nkey: value\n---\ntest")
# => ('key: value', 'test')