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::prelude::*;
|
||||
|
||||
/// Monospaced text with optional syntax highlighting.
|
||||
/// Raw text with optional syntax highlighting.
|
||||
#[derive(Debug, Hash)]
|
||||
pub struct RawNode {
|
||||
/// The raw text.
|
||||
|
@ -66,7 +66,7 @@ pub struct LangItems {
|
||||
pub strong: fn(body: Content) -> Content,
|
||||
/// Emphasized content: `_Emphasized_`.
|
||||
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,
|
||||
/// A hyperlink: `https://typst.org`.
|
||||
pub link: fn(url: EcoString) -> Content,
|
||||
|
@ -5,7 +5,7 @@
|
||||
use std::num::NonZeroUsize;
|
||||
use std::ops::Deref;
|
||||
|
||||
use super::{NodeData, NodeKind, RawKind, Span, SyntaxNode, Unit};
|
||||
use super::{NodeData, NodeKind, RawFields, Span, SyntaxNode, Unit};
|
||||
use crate::util::EcoString;
|
||||
|
||||
/// A typed AST node.
|
||||
@ -80,7 +80,7 @@ pub enum MarkupNode {
|
||||
Strong(Strong),
|
||||
/// Emphasized content: `_Emphasized_`.
|
||||
Emph(Emph),
|
||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
||||
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||
Raw(Raw),
|
||||
/// A hyperlink: `https://typst.org`.
|
||||
Link(Link),
|
||||
@ -258,7 +258,7 @@ impl Emph {
|
||||
}
|
||||
|
||||
node! {
|
||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
||||
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||
Raw
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ impl Raw {
|
||||
}
|
||||
|
||||
/// The raw fields.
|
||||
fn get(&self) -> &RawKind {
|
||||
fn get(&self) -> &RawFields {
|
||||
match self.0.kind() {
|
||||
NodeKind::Raw(v) => v.as_ref(),
|
||||
_ => panic!("raw is of wrong kind"),
|
||||
|
@ -147,7 +147,7 @@ pub enum Category {
|
||||
Emph,
|
||||
/// A hyperlink.
|
||||
Link,
|
||||
/// Raw text or code.
|
||||
/// Raw text.
|
||||
Raw,
|
||||
/// A label.
|
||||
Label,
|
||||
|
@ -150,8 +150,8 @@ pub enum NodeKind {
|
||||
Strong,
|
||||
/// Emphasized content: `_Emphasized_`.
|
||||
Emph,
|
||||
/// A raw block with optional syntax highlighting: `` `...` ``.
|
||||
Raw(Arc<RawKind>),
|
||||
/// Raw text with optional syntax highlighting: `` `...` ``.
|
||||
Raw(Arc<RawFields>),
|
||||
/// A hyperlink: `https://typst.org`.
|
||||
Link(EcoString),
|
||||
/// A label: `<label>`.
|
||||
@ -254,9 +254,9 @@ pub enum NodeKind {
|
||||
Error(ErrorPos, EcoString),
|
||||
}
|
||||
|
||||
/// Fields of the node kind `Raw`.
|
||||
/// Fields of a [`Raw`](NodeKind::Raw) node.
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct RawKind {
|
||||
pub struct RawFields {
|
||||
/// An optional identifier specifying the language to syntax-highlight in.
|
||||
pub lang: Option<EcoString>,
|
||||
/// The raw text, determined as the raw string between the backticks trimmed
|
||||
|
@ -1,6 +1,6 @@
|
||||
use unscanny::Scanner;
|
||||
|
||||
use super::{is_ident, is_newline, RawKind};
|
||||
use super::{is_ident, is_newline, RawFields};
|
||||
use crate::util::EcoString;
|
||||
|
||||
/// 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.
|
||||
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 {
|
||||
let (tag, inner) = split_at_lang_tag(text);
|
||||
let (text, block) = trim_and_split_raw(column, inner);
|
||||
RawKind {
|
||||
RawFields {
|
||||
lang: is_ident(tag).then(|| tag.into()),
|
||||
text: text.into(),
|
||||
block,
|
||||
}
|
||||
} else {
|
||||
RawKind {
|
||||
RawFields {
|
||||
lang: None,
|
||||
text: split_lines(text).join("\n").into(),
|
||||
block: false,
|
||||
|
@ -4,7 +4,7 @@ use unicode_xid::UnicodeXID;
|
||||
use unscanny::Scanner;
|
||||
|
||||
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::util::{format_eco, EcoString};
|
||||
|
||||
@ -351,7 +351,7 @@ impl<'s> Tokens<'s> {
|
||||
|
||||
// Special case for empty inline block.
|
||||
if backticks == 2 {
|
||||
return NodeKind::Raw(Arc::new(RawKind {
|
||||
return NodeKind::Raw(Arc::new(RawFields {
|
||||
text: EcoString::new(),
|
||||
lang: None,
|
||||
block: false,
|
||||
@ -724,7 +724,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn Raw(text: &str, lang: Option<&str>, block: bool) -> NodeKind {
|
||||
NodeKind::Raw(Arc::new(RawKind {
|
||||
NodeKind::Raw(Arc::new(RawFields {
|
||||
text: text.into(),
|
||||
lang: lang.map(Into::into),
|
||||
block,
|
||||
|
Loading…
x
Reference in New Issue
Block a user