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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Fragment and text parsing
use crate::ast::*;
use tsv_lang::{Error, Span};
use super::parser_impl::SvelteParser;
impl<'a, 'arena> SvelteParser<'a, 'arena> {
/// Parse text content between nodes
///
/// Stores the original source text; HTML entities decode lazily via
/// `Text::data` with text-content rules (`TextDecoding::Fragment`).
pub(crate) fn parse_text(&self, start: usize, end: usize) -> Result<Text, Error> {
let span = Span {
start: start as u32,
end: end as u32,
};
Ok(Text::new(span, TextDecoding::Fragment, span, self.source))
}
/// Parse an HTML comment: <!-- content -->
///
/// The current token is TokenKind::Comment, which includes the full
/// <!-- ... --> delimiters. We extract just the content field.
pub(crate) fn parse_comment(&mut self) -> Result<HtmlComment, Error> {
let start = self.current_start();
let end = self.current_end();
// Token value is the full comment including <!-- and -->
let token_value = self.current_value();
// Content span: text between <!-- and --> (strip "<!--" = 4, "-->" = 3),
// a pure source sub-slice recovered via `HtmlComment::content`.
let content_span = if token_value.len() >= 7 {
Span {
start: (start + 4) as u32,
end: (end - 3) as u32,
}
} else {
Span {
start: start as u32,
end: start as u32,
}
};
self.advance()?;
Ok(HtmlComment {
content_span,
span: Span {
start: start as u32,
end: end as u32,
},
})
}
}