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').false? { return ('', input) }

  match input.byte_index(of: '\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.byte(rest) == 10 { rest += 1 }

      (
        input.slice(start: 4, size: idx - 4).into_string,
        input.slice(start: rest, size: input.size).into_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')