Skip to main content

sevenmark_parser/parser/text/
text.rs

1use crate::ast::{Element, Span, TextElement};
2use crate::parser::ParserInput;
3use winnow::Result;
4use winnow::prelude::*;
5use winnow::stream::Location as StreamLocation;
6use winnow::token::take_while;
7
8/// 특수문자가 아닌 일반 텍스트 파싱 (기존 md_content_parser 역할)
9pub fn text_parser(parser_input: &mut ParserInput) -> Result<Element> {
10    let start = parser_input.current_token_start();
11    let parsed_content = take_while(1.., |c: char| {
12        !matches!(
13            c,
14            '*' | '~' | '_' | '^' | ',' | '{' | '}' | '[' | ']' | '/' | '\\' | '\n' | '<'
15        )
16    })
17    .parse_next(parser_input)?;
18    let end = parser_input.previous_token_end();
19
20    Ok(Element::Text(TextElement {
21        span: Span { start, end },
22        value: parsed_content.to_string(),
23    }))
24}