extract_frontmatter/config.rs
1//! Configuration options that can be applied to [`Extractor`].
2//!
3//! [`Extractor`]: crate::Extractor
4
5/// Ways of distinguishing front-matter from the rest of the data in some text.
6#[derive(Debug)]
7#[non_exhaustive]
8pub enum Splitter<'opt> {
9 /// All lines before the first line matching this text (ignoring leading and trailing whitespace differences) will
10 /// be treated as front-matter; everything else (excluding this line, as it is discarded) will be returned as data.
11 /// If no line is found matching this text, then everything will be treated as front-matter.
12 DelimiterLine(&'opt str),
13
14 /// All lines before the second line matching this text (ignoring leading and trailing whitespace differences) will
15 /// be treated as front-matter (except for the first line if it also matches this text); everything else (excluding
16 /// the second matched line, as it is discarded) will be returned as data. If there is no second line matching this
17 /// text, then everything will be treated as front-matter (with the first line possibly removed).
18 EnclosingLines(&'opt str),
19
20 /// All lines before this line will be treated as front-matter; everything else (including this line) will be
21 /// returned as data. If there are less lines than specified here, then everything will be treated as front-matter.
22 LineIndex(usize),
23
24 /// All lines prefixed with this text, up to (and not including) the first line that is not prefixed, will be
25 /// treated as front-matter; everything else will be returned as data. If no lines are found with this prefix, then
26 /// everything will be treated as data. Note that the prefix will _not_ be stripped automatically; use
27 /// [`Modifier::StripPrefix`] to explicitly strip the prefix.
28 LinePrefix(&'opt str),
29}
30
31/// Modifiers that can be applied to extracted front-matter. Note that these will implicitly normalise newlines to just
32/// `\n` (LF).
33#[derive(Debug)]
34#[non_exhaustive]
35pub enum Modifier<'opt> {
36 /// Strip the first line from the front-matter returned.
37 StripFirstLine,
38
39 /// Strip the last line from the front-matter returned.
40 StripLastLine,
41
42 /// Strips the given prefix from the start of all front-matter lines.
43 StripPrefix(&'opt str),
44
45 /// Strip leading and trailing whitespace from all front-matter lines.
46 TrimWhitespace,
47}