extract-frontmatter 2.0.3

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 <!-- omit in toc -->

- [Overview]#overview
  - [Versioning]#versioning
  - [Repository information]#repository-information
- [Usage]#usage
  - [Selectors]#selectors
  - [Modifiers]#modifiers
  - [Example]#example

## 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.

[![Crates.io version](https://img.shields.io/crates/v/extract-frontmatter?style=for-the-badge)](https://docs.rs/extract-frontmatter/latest/extract-frontmatter/)
[![Crates.io downloads](https://img.shields.io/crates/d/extract-frontmatter?style=for-the-badge)](https://crates.io/crates/extract-frontmatter)
[![Gitlab pipeline status](https://img.shields.io/gitlab/pipeline/Kage-Yami/extract-frontmatter/main?style=for-the-badge)](https://gitlab.com/Kage-Yami/extract-frontmatter/pipelines/main/latest)
[![Gitlab code coverage](https://img.shields.io/gitlab/coverage/Kage-Yami/extract-frontmatter/main?style=for-the-badge)](https://gitlab.com/Kage-Yami/extract-frontmatter)
[![Lines of code](https://img.shields.io/tokei/lines/gitlab/Kage-Yami/extract-frontmatter?style=for-the-badge)](https://gitlab.com/Kage-Yami/extract-frontmatter)
[![Dependents](https://img.shields.io/librariesio/dependent-repos/cargo/extract-frontmatter?style=for-the-badge)](https://libraries.io/cargo/extract-frontmatter)
[![License](https://img.shields.io/crates/l/extract-frontmatter?style=for-the-badge)](https://gitlab.com/Kage-Yami/extract-frontmatter/-/blob/main/LICENSE)


### Versioning

This project follows [Semantic Versioning principals](https://semver.org/) starting with `v1.0.0`

### Repository information

This repository is located on [GitLab.com](https://gitlab.com/Kage-Yami/extract-frontmatter).


## Usage

To use this library:

1. Instantiate an instance of `Extractor`
2. Call a selector method on it
3. Call zero or more modifier methods on it
4. Call:
    - `extract()` (for a `String`), or
    - `collect()` (for a `Vec<&str>`)

### Selectors

| Method                                   | Description                                                      |
| ---------------------------------------- | ---------------------------------------------------------------- |
| `select_by_terminator(terminator: &str)` | Selects lines until the first one equal to `terminator` is found |
| `select_by_prefix(prefix: &str)`         | Selects consecutive lines starting with `prefix`                 |
| `select_by_line_count(count: usize)`     | Selects `count` lines                                            |

### Modifiers

| Method                       | Description                                                    |
| ---------------------------- | -------------------------------------------------------------- |
| `strip_prefix(prefix: &str)` | Strips the given `prefix` from all returned lines              |
| `strip_whitespace()`         | Strips leading and trailing whitespace from all returned lines |
| `discard_first_line()`       | Skips the first line to be returned                            |
| `discard_last_line()`        | Skips the last line to be returned                             |

### Example

Given a variable `input` with the following text:

```md
root:
  child1: true
  child2: two
---

## Example

This is an example Markdown file.
```

... and the following code:

```rust
use extract_frontmatter::Extractor;

let mut extractor = Extractor::new(input);
extractor.select_by_terminator("---");

let output: String = extractor.extract();
```

... the variable `output` will contain:

```yml
root:
  child1: true
  child2: two
```