extract-frontmatter 4.0.0

A library that allows a user to extract an arbitrary number of lines of 'front-matter' from the start of any string
Documentation

extract-frontmatter

Overview

A Rust library that allows a user to extract an arbitrary number of lines of "front-matter" from the start of any multiline string.

Note that absolutely no parsing of extracted front-matter is performed; this is designed to output its results for another library to then parse.

docs.io documentation crates.io version crates.io downloads Dependents License

Versioning

This project follows Semantic Versioning principals starting with v1.0.0

Repository information

This repository is located on GitLab.com.

Usage

Example 1 (Markdown with TOML)

Input:

[meta]
field_one = 10
field_two = [2, 4]
+++

# Markdown example

This is an example markdown document that contains the following TOML front-matter:

    [meta]
    field_one = 10
    field_two = [2, 4]

Code:

fn example(input: &str) {
    let (_front_matter, _data) = Extractor::new(Splitter::DelimiterLine("+++")).extract(input);
}

Front-matter output:

[meta]
field_one = 10
field_two = [2, 4]

Data output:

## Markdown example

This is an example markdown document that contains the following TOML front-matter:

    [meta]
    field_one = 10
    field_two = [2, 4]

Example 2 (SQL with YAML)

Input:

-- meta:
--   field_one: 10
--   field_two:
--     - 2
--     - 4
SELECT version();

Code:

fn example(input: &str) {
    let (_front_matter, _data) = Extractor::new(Splitter::LinePrefix("-- "))
        .with_modifier(Modifier::StripPrefix("-- "))
        .extract(input);
}

Front-matter output:

meta:
  field_one: 10
  field_two:
    - 2
    - 4

Data output:

SELECT version();