mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
use zero-copy traits for inline code detection
This commit is contained in:
parent
e2012dee99
commit
d8f692d807
1 changed files with 35 additions and 28 deletions
|
|
@ -104,7 +104,8 @@ impl Gemini {
|
||||||
let is_multiline_enabled = {
|
let is_multiline_enabled = {
|
||||||
let mut t: usize = 0;
|
let mut t: usize = 0;
|
||||||
for l in gemtext.lines() {
|
for l in gemtext.lines() {
|
||||||
if (l.starts_with(code::TAG) || l.ends_with(code::TAG)) && Inline::from(l).is_none()
|
if (l.starts_with(code::TAG) || l.ends_with(code::TAG))
|
||||||
|
&& inline::Gemtext::as_value(l).is_none()
|
||||||
{
|
{
|
||||||
t += 1;
|
t += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -115,9 +116,10 @@ impl Gemini {
|
||||||
// Parse gemtext lines
|
// Parse gemtext lines
|
||||||
for line in gemtext.lines() {
|
for line in gemtext.lines() {
|
||||||
// Is inline code
|
// Is inline code
|
||||||
if let Some(code) = Inline::from(line) {
|
{
|
||||||
|
if let Some(code) = inline::Gemtext::as_value(line) {
|
||||||
// Try auto-detect code syntax for given `value` @TODO optional
|
// Try auto-detect code syntax for given `value` @TODO optional
|
||||||
match syntax.highlight(&code.value, None) {
|
match syntax.highlight(code, None) {
|
||||||
Ok(highlight) => {
|
Ok(highlight) => {
|
||||||
for (syntax_tag, entity) in highlight {
|
for (syntax_tag, entity) in highlight {
|
||||||
// Register new tag
|
// Register new tag
|
||||||
|
|
@ -134,19 +136,24 @@ impl Gemini {
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Try ANSI/SGR format (terminal emulation) @TODO optional
|
// Try ANSI/SGR format (terminal emulation) @TODO optional
|
||||||
for (ansi_tag, entity) in ansi::format(&code.value) {
|
for (ansi_tag, entity) in ansi::format(code) {
|
||||||
// Register new tag
|
// Register new tag
|
||||||
if !tag.text_tag_table.add(&ansi_tag) {
|
if !tag.text_tag_table.add(&ansi_tag) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
// Append tag to buffer
|
// Append tag to buffer
|
||||||
buffer.insert_with_tags(&mut buffer.end_iter(), &entity, &[&ansi_tag]);
|
buffer.insert_with_tags(
|
||||||
|
&mut buffer.end_iter(),
|
||||||
|
&entity,
|
||||||
|
&[&ansi_tag],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} // @TODO handle
|
} // @TODO handle
|
||||||
}
|
}
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Is multiline code
|
// Is multiline code
|
||||||
if is_multiline_enabled {
|
if is_multiline_enabled {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue