aboutsummaryrefslogtreecommitdiff
path: root/parse_wiki_text/src/bold_italic.rs
blob: e5ac613222beeb75b5509be2d744be210fa30c78 (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
// Copyright 2019 Fredrik Portström <https://portstrom.com>
// This is free software distributed under the terms specified in
// the file LICENSE at the top-level directory of this distribution.

pub fn parse_bold_italic(state: &mut crate::State) {
    let scan_position = state.scan_position;
    state.flush(scan_position);
    let start_position = state.scan_position;
    state.scan_position += 2;
    while state.get_byte(state.scan_position) == Some(b'\'') {
        state.scan_position += 1;
    }
    let length = state.scan_position - start_position;
    if length < 3 {
        state.flushed_position = state.scan_position;
        state.nodes.push(crate::Node::Italic {
            end: state.flushed_position,
            start: start_position,
        });
    } else if length < 5 {
        state.flushed_position = start_position + 3;
        state.nodes.push(crate::Node::Bold {
            end: state.flushed_position,
            start: start_position,
        });
    } else {
        state.flushed_position = start_position + 5;
        state.nodes.push(crate::Node::BoldItalic {
            end: state.flushed_position,
            start: start_position,
        });
    }
}