Add new constructor for markdown::Content
This commit is contained in:
parent
bc2d662af7
commit
095859ed57
2 changed files with 6 additions and 6 deletions
|
|
@ -74,7 +74,7 @@ impl Markdown {
|
||||||
if enable_stream {
|
if enable_stream {
|
||||||
self.mode = Mode::Stream {
|
self.mode = Mode::Stream {
|
||||||
pending: self.content.text(),
|
pending: self.content.text(),
|
||||||
parsed: markdown::Content::parse(""),
|
parsed: markdown::Content::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollable::snap_to(
|
scrollable::snap_to(
|
||||||
|
|
|
||||||
|
|
@ -66,13 +66,17 @@ pub use core::text::Highlight;
|
||||||
pub use pulldown_cmark::HeadingLevel;
|
pub use pulldown_cmark::HeadingLevel;
|
||||||
pub use url::Url;
|
pub use url::Url;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
items: Vec<Item>,
|
items: Vec<Item>,
|
||||||
state: State,
|
state: State,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(markdown: &str) -> Self {
|
pub fn parse(markdown: &str) -> Self {
|
||||||
let mut state = State::default();
|
let mut state = State::default();
|
||||||
let items = parse_with(&mut state, markdown).collect();
|
let items = parse_with(&mut state, markdown).collect();
|
||||||
|
|
@ -595,16 +599,12 @@ fn parse_with<'a>(
|
||||||
pulldown_cmark::Event::Text(text) if !metadata && !table => {
|
pulldown_cmark::Event::Text(text) if !metadata && !table => {
|
||||||
#[cfg(feature = "highlighter")]
|
#[cfg(feature = "highlighter")]
|
||||||
if let Some(highlighter) = &mut highlighter {
|
if let Some(highlighter) = &mut highlighter {
|
||||||
let start = std::time::Instant::now();
|
|
||||||
|
|
||||||
for line in text.lines() {
|
for line in text.lines() {
|
||||||
spans.extend_from_slice(
|
spans.extend_from_slice(
|
||||||
highlighter.highlight_line(&format!("{line}\n")),
|
highlighter.highlight_line(&format!("{line}\n")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg!(start.elapsed());
|
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue