Highlighting and docs fixes

This commit is contained in:
Laurenz 2023-01-30 18:29:09 +01:00
parent 1d86f41831
commit 3a4c5ae4b9
4 changed files with 25 additions and 35 deletions

View File

@ -55,9 +55,9 @@ impl LayoutMath for VecNode {
/// ///
/// The elements of a row should be separated by commas, while the rows /// The elements of a row should be separated by commas, while the rows
/// themselves should be separated by semicolons. The semicolon syntax merges /// themselves should be separated by semicolons. The semicolon syntax merges
/// preceding arguments separated by commas into a array arguments. You /// preceding arguments separated by commas into an array. You can also use this
/// can also use this special syntax of math function calls to define custom /// special syntax of math function calls to define custom functions that take
/// functions that take 2D data. /// 2D data.
/// ///
/// Content in cells that are in the same row can be aligned with the `&` symbol. /// Content in cells that are in the same row can be aligned with the `&` symbol.
/// ///

View File

@ -107,26 +107,7 @@ pub fn module(sym: &Module) -> Module {
/// # Formula /// # Formula
/// A mathematical formula. /// A mathematical formula.
/// ///
/// ## Syntax /// Can be displayed inline with text or as a separate block.
/// This function also has dedicated syntax: Write mathematical markup within
/// dollar signs to create a formula. Starting and ending the formula with at
/// least one space lifts it into a separate block that is centered
/// horizontally.
///
/// In math, single letters are always displayed as is. Multiple letters,
/// however, are interpreted as variables, symbols or functions. To display
/// multiple letters verbatim, you can place them into quotes. Math mode also
/// supports extra shorthands to easily type various arrows and other symbols.
/// The [text](/docs/reference/text/) and [math](/docs/reference/math/) sections
/// list all of them.
///
/// When a variable and a symbol share the same name, the variable is preferred.
/// To force the symbol, surround it with colons. To access a variable with a
/// single letter name, you can prefix it with a `#`.
///
/// In math mode, the arguments to a function call are always parsed as
/// mathematical content. To work with other kinds of values, you first need to
/// enter a code block using the `[$#{..}$]` syntax.
/// ///
/// ## Example /// ## Example
/// ``` /// ```
@ -139,16 +120,21 @@ pub fn module(sym: &Module) -> Module {
/// ///
/// Prove by induction: /// Prove by induction:
/// $ sum_(k=1)^n k = (n(n+1)) / 2 $ /// $ sum_(k=1)^n k = (n(n+1)) / 2 $
///
/// We define the following set:
/// $ cal(A) :=
/// { x in RR | x "is natural" } $
/// ``` /// ```
/// ///
/// ## Parameters /// ## Syntax
/// - body: Content (positional, required) The contents of the formula. /// This function also has dedicated syntax: Write mathematical markup within
/// dollar signs to create a formula. Starting and ending the formula with at
/// least one space lifts it into a separate block that is centered
/// horizontally. For more details about math syntax, see the
/// [main math page](/docs/reference/math).
/// ///
/// - block: bool (named) Whether the formula is displayed as a separate block. /// ## Parameters
/// - body: Content (positional, required)
/// The contents of the formula.
///
/// - block: bool (named)
/// Whether the formula is displayed as a separate block.
/// ///
/// ## Category /// ## Category
/// math /// math

View File

@ -256,10 +256,14 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> {
/// Highlight an identifier based on context. /// Highlight an identifier based on context.
fn highlight_ident(node: &LinkedNode) -> Option<Category> { fn highlight_ident(node: &LinkedNode) -> Option<Category> {
// Are we directly before an argument list? // Are we directly before an argument list?
let next_leaf_kind = node.next_leaf().map(|leaf| leaf.kind()); let next_leaf = node.next_leaf();
if matches!(next_leaf_kind, Some(SyntaxKind::LeftParen | SyntaxKind::LeftBracket)) { if let Some(next) = &next_leaf {
if node.range().end == next.offset()
&& matches!(next.kind(), SyntaxKind::LeftParen | SyntaxKind::LeftBracket)
{
return Some(Category::Function); return Some(Category::Function);
} }
}
// Are we in math? // Are we in math?
if node.kind() == SyntaxKind::MathIdent { if node.kind() == SyntaxKind::MathIdent {
@ -273,7 +277,7 @@ fn highlight_ident(node: &LinkedNode) -> Option<Category> {
} }
// Are we directly before a show rule colon? // Are we directly before a show rule colon?
if next_leaf_kind == Some(SyntaxKind::Colon) if next_leaf.map(|leaf| leaf.kind()) == Some(SyntaxKind::Colon)
&& ancestor.parent_kind() == Some(SyntaxKind::ShowRule) && ancestor.parent_kind() == Some(SyntaxKind::ShowRule)
{ {
return Some(Category::Function); return Some(Category::Function);

View File

@ -507,7 +507,7 @@ fn embedded_code_expr(p: &mut Parser) {
fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) { fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) {
let m = p.marker(); let m = p.marker();
if let Some(op) = ast::UnOp::from_kind(p.current()) { if let (false, Some(op)) = (atomic, ast::UnOp::from_kind(p.current())) {
p.eat(); p.eat();
code_expr_prec(p, atomic, op.precedence()); code_expr_prec(p, atomic, op.precedence());
p.wrap(m, SyntaxKind::Unary); p.wrap(m, SyntaxKind::Unary);