mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Scale shorthand brackets
This commit is contained in:
parent
9d962c5c40
commit
a59b9fff93
@ -584,9 +584,9 @@ impl Eval for ast::MathDelimited {
|
|||||||
type Output = Content;
|
type Output = Content;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||||
let open = self.open().eval(vm)?;
|
let open = self.open().eval(vm)?.display_in_math();
|
||||||
let body = self.body().eval(vm)?;
|
let body = self.body().eval(vm)?;
|
||||||
let close = self.close().eval(vm)?;
|
let close = self.close().eval(vm)?.display_in_math();
|
||||||
Ok((vm.items.math_delimited)(open, body, close))
|
Ok((vm.items.math_delimited)(open, body, close))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -716,7 +716,7 @@ node! {
|
|||||||
|
|
||||||
impl MathDelimited {
|
impl MathDelimited {
|
||||||
/// The opening delimiter.
|
/// The opening delimiter.
|
||||||
pub fn open(&self) -> MathAtom {
|
pub fn open(&self) -> Expr {
|
||||||
self.0.cast_first_match().unwrap_or_default()
|
self.0.cast_first_match().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,7 +726,7 @@ impl MathDelimited {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The closing delimiter.
|
/// The closing delimiter.
|
||||||
pub fn close(&self) -> MathAtom {
|
pub fn close(&self) -> Expr {
|
||||||
self.0.cast_last_match().unwrap_or_default()
|
self.0.cast_last_match().unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SyntaxKind::MathAtom => {
|
SyntaxKind::MathAtom | SyntaxKind::Shorthand => {
|
||||||
if math_class(p.current_text()) == Some(MathClass::Fence) {
|
if math_class(p.current_text()) == Some(MathClass::Fence) {
|
||||||
math_delimited(p, MathClass::Fence)
|
math_delimited(p, MathClass::Fence)
|
||||||
} else if math_class(p.current_text()) == Some(MathClass::Opening) {
|
} else if math_class(p.current_text()) == Some(MathClass::Opening) {
|
||||||
@ -264,7 +264,6 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
|||||||
|
|
||||||
SyntaxKind::Linebreak
|
SyntaxKind::Linebreak
|
||||||
| SyntaxKind::Escape
|
| SyntaxKind::Escape
|
||||||
| SyntaxKind::Shorthand
|
|
||||||
| SyntaxKind::MathAlignPoint
|
| SyntaxKind::MathAlignPoint
|
||||||
| SyntaxKind::Str => p.eat(),
|
| SyntaxKind::Str => p.eat(),
|
||||||
|
|
||||||
@ -306,12 +305,12 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
|||||||
|
|
||||||
fn math_delimited(p: &mut Parser, stop: MathClass) {
|
fn math_delimited(p: &mut Parser, stop: MathClass) {
|
||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
p.assert(SyntaxKind::MathAtom);
|
p.eat();
|
||||||
let m2 = p.marker();
|
let m2 = p.marker();
|
||||||
while !p.eof() && !p.at(SyntaxKind::Dollar) {
|
while !p.eof() && !p.at(SyntaxKind::Dollar) {
|
||||||
if math_class(p.current_text()) == Some(stop) {
|
if math_class(p.current_text()) == Some(stop) {
|
||||||
p.wrap(m2, SyntaxKind::Math);
|
p.wrap(m2, SyntaxKind::Math);
|
||||||
p.assert(SyntaxKind::MathAtom);
|
p.eat();
|
||||||
p.wrap(m, SyntaxKind::MathDelimited);
|
p.wrap(m, SyntaxKind::MathDelimited);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -341,6 +340,13 @@ fn math_unparen(p: &mut Parser, m: Marker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn math_class(text: &str) -> Option<MathClass> {
|
fn math_class(text: &str) -> Option<MathClass> {
|
||||||
|
match text {
|
||||||
|
"[|" => return Some(MathClass::Opening),
|
||||||
|
"|]" => return Some(MathClass::Closing),
|
||||||
|
"||" => return Some(MathClass::Fence),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
let mut chars = text.chars();
|
let mut chars = text.chars();
|
||||||
chars
|
chars
|
||||||
.next()
|
.next()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user