diff --git a/qbittorrent-web-api-gen/src/md_parser/md_token.rs b/qbittorrent-web-api-gen/src/md_parser/md_token.rs index ac3e62d..998a3cf 100644 --- a/qbittorrent-web-api-gen/src/md_parser/md_token.rs +++ b/qbittorrent-web-api-gen/src/md_parser/md_token.rs @@ -52,30 +52,6 @@ pub enum MdToken { } impl MdToken { - fn parse_token(line: &str) -> MdToken { - if line.starts_with('#') { - let mut level = 0; - for char in line.chars() { - if char != '#' { - break; - } - - level += 1; - } - - MdToken::Header(Header { - level, - content: line.trim_matches('#').trim().to_string(), - }) - } else if line.starts_with('*') { - MdToken::Content(MdContent::Asterisk( - line.trim_matches('*').trim().to_string(), - )) - } else { - MdToken::Content(MdContent::Text(line.to_string())) - } - } - pub fn from(content: &str) -> Vec { // to prevent infinite loops let mut max_iterator_checker = MaxIteratorChecker::default(); @@ -90,8 +66,13 @@ impl MdToken { if line.contains('|') { let table = TableParser::new(&mut max_iterator_checker, &mut iter).parse(line); output.push(MdToken::Content(table)); + } else if line.starts_with('#') { + output.push(parse_header(line)); + } else if line.starts_with('*') { + let asterisk = MdContent::Asterisk(line.trim_matches('*').trim().to_string()); + output.push(MdToken::Content(asterisk)); } else { - output.push(MdToken::parse_token(line)); + output.push(MdToken::Content(MdContent::Text(line.to_string()))); } } @@ -99,6 +80,21 @@ impl MdToken { } } +fn parse_header(line: &str) -> MdToken { + let mut level = 0; + for char in line.chars() { + if char != '#' { + break; + } + + level += 1; + } + MdToken::Header(Header { + level, + content: line.trim_matches('#').trim().to_string(), + }) +} + struct TableParser<'a, 'b> { max_iterator_checker: &'a mut MaxIteratorChecker, iter: &'a mut std::iter::Peekable>,