aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
blob: dc2c07abc792ec927325719c54d38789f2fbdcf4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Turn a string of markdown into events.

use crate::content::document::document;
use crate::event::{Event, Point};
use crate::{Constructs, Options};

/// Information needed, in all content types, when parsing markdown.
///
/// Importantly, this contains a set of known definitions.
/// It also references the input value as a `Vec<char>`.
#[derive(Debug)]
pub struct ParseState<'a> {
    pub constructs: &'a Constructs,
    /// List of chars.
    pub bytes: &'a [u8],
    /// Set of defined identifiers.
    pub definitions: Vec<String>,
}

/// Turn a string of markdown into events.
///
/// Passes the codes back so the compiler can access the source.
pub fn parse<'a>(value: &'a str, options: &'a Options) -> (Vec<Event>, &'a [u8]) {
    let mut parse_state = ParseState {
        constructs: &options.constructs,
        bytes: value.as_bytes(),
        definitions: vec![],
    };

    let events = document(
        &mut parse_state,
        Point {
            line: 1,
            column: 1,
            index: 0,
            vs: 0,
        },
    );

    (events, parse_state.bytes)
}