mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Rename RawKind
to RawFields
This commit is contained in:
parent
1937d746ab
commit
565b1977ae
@ -10,7 +10,7 @@ use super::{FontFamily, Hyphenate, LinebreakNode, TextNode};
|
|||||||
use crate::layout::BlockNode;
|
use crate::layout::BlockNode;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Monospaced text with optional syntax highlighting.
|
/// Raw text with optional syntax highlighting.
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
pub struct RawNode {
|
pub struct RawNode {
|
||||||
/// The raw text.
|
/// The raw text.
|
||||||
|
@ -66,7 +66,7 @@ pub struct LangItems {
|
|||||||
pub strong: fn(body: Content) -> Content,
|
pub strong: fn(body: Content) -> Content,
|
||||||
/// Emphasized content: `_Emphasized_`.
|
/// Emphasized content: `_Emphasized_`.
|
||||||
pub emph: fn(body: Content) -> Content,
|
pub emph: fn(body: Content) -> Content,
|
||||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||||
pub raw: fn(text: EcoString, tag: Option<EcoString>, block: bool) -> Content,
|
pub raw: fn(text: EcoString, tag: Option<EcoString>, block: bool) -> Content,
|
||||||
/// A hyperlink: `https://typst.org`.
|
/// A hyperlink: `https://typst.org`.
|
||||||
pub link: fn(url: EcoString) -> Content,
|
pub link: fn(url: EcoString) -> Content,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use super::{NodeData, NodeKind, RawKind, Span, SyntaxNode, Unit};
|
use super::{NodeData, NodeKind, RawFields, Span, SyntaxNode, Unit};
|
||||||
use crate::util::EcoString;
|
use crate::util::EcoString;
|
||||||
|
|
||||||
/// A typed AST node.
|
/// A typed AST node.
|
||||||
@ -80,7 +80,7 @@ pub enum MarkupNode {
|
|||||||
Strong(Strong),
|
Strong(Strong),
|
||||||
/// Emphasized content: `_Emphasized_`.
|
/// Emphasized content: `_Emphasized_`.
|
||||||
Emph(Emph),
|
Emph(Emph),
|
||||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||||
Raw(Raw),
|
Raw(Raw),
|
||||||
/// A hyperlink: `https://typst.org`.
|
/// A hyperlink: `https://typst.org`.
|
||||||
Link(Link),
|
Link(Link),
|
||||||
@ -258,7 +258,7 @@ impl Emph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
node! {
|
node! {
|
||||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||||
Raw
|
Raw
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ impl Raw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The raw fields.
|
/// The raw fields.
|
||||||
fn get(&self) -> &RawKind {
|
fn get(&self) -> &RawFields {
|
||||||
match self.0.kind() {
|
match self.0.kind() {
|
||||||
NodeKind::Raw(v) => v.as_ref(),
|
NodeKind::Raw(v) => v.as_ref(),
|
||||||
_ => panic!("raw is of wrong kind"),
|
_ => panic!("raw is of wrong kind"),
|
||||||
|
@ -147,7 +147,7 @@ pub enum Category {
|
|||||||
Emph,
|
Emph,
|
||||||
/// A hyperlink.
|
/// A hyperlink.
|
||||||
Link,
|
Link,
|
||||||
/// Raw text or code.
|
/// Raw text.
|
||||||
Raw,
|
Raw,
|
||||||
/// A label.
|
/// A label.
|
||||||
Label,
|
Label,
|
||||||
|
@ -150,8 +150,8 @@ pub enum NodeKind {
|
|||||||
Strong,
|
Strong,
|
||||||
/// Emphasized content: `_Emphasized_`.
|
/// Emphasized content: `_Emphasized_`.
|
||||||
Emph,
|
Emph,
|
||||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||||
Raw(Arc<RawKind>),
|
Raw(Arc<RawFields>),
|
||||||
/// A hyperlink: `https://typst.org`.
|
/// A hyperlink: `https://typst.org`.
|
||||||
Link(EcoString),
|
Link(EcoString),
|
||||||
/// A label: `<label>`.
|
/// A label: `<label>`.
|
||||||
@ -254,9 +254,9 @@ pub enum NodeKind {
|
|||||||
Error(ErrorPos, EcoString),
|
Error(ErrorPos, EcoString),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fields of the node kind `Raw`.
|
/// Fields of a [`Raw`](NodeKind::Raw) node.
|
||||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||||
pub struct RawKind {
|
pub struct RawFields {
|
||||||
/// An optional identifier specifying the language to syntax-highlight in.
|
/// An optional identifier specifying the language to syntax-highlight in.
|
||||||
pub lang: Option<EcoString>,
|
pub lang: Option<EcoString>,
|
||||||
/// The raw text, determined as the raw string between the backticks trimmed
|
/// The raw text, determined as the raw string between the backticks trimmed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use unscanny::Scanner;
|
use unscanny::Scanner;
|
||||||
|
|
||||||
use super::{is_ident, is_newline, RawKind};
|
use super::{is_ident, is_newline, RawFields};
|
||||||
use crate::util::EcoString;
|
use crate::util::EcoString;
|
||||||
|
|
||||||
/// Resolve all escape sequences in a string.
|
/// Resolve all escape sequences in a string.
|
||||||
@ -44,17 +44,17 @@ pub fn resolve_hex(sequence: &str) -> Option<char> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the language tag and trim the raw text.
|
/// Resolve the language tag and trim the raw text.
|
||||||
pub fn resolve_raw(column: usize, backticks: usize, text: &str) -> RawKind {
|
pub fn resolve_raw(column: usize, backticks: usize, text: &str) -> RawFields {
|
||||||
if backticks > 1 {
|
if backticks > 1 {
|
||||||
let (tag, inner) = split_at_lang_tag(text);
|
let (tag, inner) = split_at_lang_tag(text);
|
||||||
let (text, block) = trim_and_split_raw(column, inner);
|
let (text, block) = trim_and_split_raw(column, inner);
|
||||||
RawKind {
|
RawFields {
|
||||||
lang: is_ident(tag).then(|| tag.into()),
|
lang: is_ident(tag).then(|| tag.into()),
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
block,
|
block,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RawKind {
|
RawFields {
|
||||||
lang: None,
|
lang: None,
|
||||||
text: split_lines(text).join("\n").into(),
|
text: split_lines(text).join("\n").into(),
|
||||||
block: false,
|
block: false,
|
||||||
|
@ -4,7 +4,7 @@ use unicode_xid::UnicodeXID;
|
|||||||
use unscanny::Scanner;
|
use unscanny::Scanner;
|
||||||
|
|
||||||
use super::resolve::{resolve_hex, resolve_raw, resolve_string};
|
use super::resolve::{resolve_hex, resolve_raw, resolve_string};
|
||||||
use super::{ErrorPos, NodeKind, RawKind, Unit};
|
use super::{ErrorPos, NodeKind, RawFields, Unit};
|
||||||
use crate::geom::{AbsUnit, AngleUnit};
|
use crate::geom::{AbsUnit, AngleUnit};
|
||||||
use crate::util::{format_eco, EcoString};
|
use crate::util::{format_eco, EcoString};
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ impl<'s> Tokens<'s> {
|
|||||||
|
|
||||||
// Special case for empty inline block.
|
// Special case for empty inline block.
|
||||||
if backticks == 2 {
|
if backticks == 2 {
|
||||||
return NodeKind::Raw(Arc::new(RawKind {
|
return NodeKind::Raw(Arc::new(RawFields {
|
||||||
text: EcoString::new(),
|
text: EcoString::new(),
|
||||||
lang: None,
|
lang: None,
|
||||||
block: false,
|
block: false,
|
||||||
@ -724,7 +724,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn Raw(text: &str, lang: Option<&str>, block: bool) -> NodeKind {
|
fn Raw(text: &str, lang: Option<&str>, block: bool) -> NodeKind {
|
||||||
NodeKind::Raw(Arc::new(RawKind {
|
NodeKind::Raw(Arc::new(RawFields {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
lang: lang.map(Into::into),
|
lang: lang.map(Into::into),
|
||||||
block,
|
block,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user