mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Use newly stabilized intra doc links ↩
This commit is contained in:
parent
f105663037
commit
761931405c
12
src/diag.rs
12
src/diag.rs
@ -7,9 +7,7 @@
|
|||||||
use crate::syntax::SpanVec;
|
use crate::syntax::SpanVec;
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
|
||||||
/// The result of some pass: Some output `T` and [feedback] data.
|
/// The result of some pass: Some output `T` and [`Feedback`] data.
|
||||||
///
|
|
||||||
/// [feedback]: struct.Feedback.html
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Pass<T> {
|
pub struct Pass<T> {
|
||||||
/// The output of this compilation pass.
|
/// The output of this compilation pass.
|
||||||
@ -118,7 +116,7 @@ pub enum Deco {
|
|||||||
DictKey,
|
DictKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a diagnostic with [`Error`] level.
|
/// Construct a diagnostic with [`Error`](Level::Error) level.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use typst::error;
|
/// # use typst::error;
|
||||||
@ -131,8 +129,6 @@ pub enum Deco {
|
|||||||
/// // Create spanned errors.
|
/// // Create spanned errors.
|
||||||
/// let spanned = error!(span, "there is an error here");
|
/// let spanned = error!(span, "there is an error here");
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// [`Error`]: diag/enum.Level.html#variant.Error
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
($($tts:tt)*) => {
|
($($tts:tt)*) => {
|
||||||
@ -140,12 +136,10 @@ macro_rules! error {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a diagnostic with [`Warning`] level.
|
/// Construct a diagnostic with [`Warning`](Level::Warning) level.
|
||||||
///
|
///
|
||||||
/// This works exactly like `error!`. See its documentation for more
|
/// This works exactly like `error!`. See its documentation for more
|
||||||
/// information.
|
/// information.
|
||||||
///
|
|
||||||
/// [`Warning`]: diag/enum.Level.html#variant.Warning
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! warning {
|
macro_rules! warning {
|
||||||
($($tts:tt)*) => {
|
($($tts:tt)*) => {
|
||||||
|
@ -28,10 +28,8 @@ impl Args {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is the same as [`get`], except that it generates an error about a
|
/// This is the same as [`get`](Self::get), except that it generates an error about a
|
||||||
/// missing argument with the given `name` if the key does not exist.
|
/// missing argument with the given `name` if the key does not exist.
|
||||||
///
|
|
||||||
/// [`get`]: #method.get
|
|
||||||
pub fn need<'a, K, T>(
|
pub fn need<'a, K, T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut EvalContext,
|
ctx: &mut EvalContext,
|
||||||
|
@ -85,10 +85,7 @@ macro_rules! convert_ident {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A value type that matches [identifier] and [string] values.
|
/// A value type that matches [identifier](Value::Ident) and [string](Value::Str) values.
|
||||||
///
|
|
||||||
/// [identifier]: enum.Value.html#variant.Ident
|
|
||||||
/// [string]: enum.Value.html#variant.Str
|
|
||||||
pub struct StringLike(pub String);
|
pub struct StringLike(pub String);
|
||||||
|
|
||||||
impl From<StringLike> for String {
|
impl From<StringLike> for String {
|
||||||
|
@ -91,8 +91,6 @@ impl EvalContext {
|
|||||||
/// Push a layout node to the active group.
|
/// Push a layout node to the active group.
|
||||||
///
|
///
|
||||||
/// Spacing nodes will be handled according to their [`Softness`].
|
/// Spacing nodes will be handled according to their [`Softness`].
|
||||||
///
|
|
||||||
/// [`Softness`]: ../layout/nodes/enum.Softness.html
|
|
||||||
pub fn push(&mut self, node: impl Into<LayoutNode>) {
|
pub fn push(&mut self, node: impl Into<LayoutNode>) {
|
||||||
let node = node.into();
|
let node = node.into();
|
||||||
|
|
||||||
@ -196,21 +194,16 @@ impl EvalContext {
|
|||||||
|
|
||||||
/// Start a layouting group.
|
/// Start a layouting group.
|
||||||
///
|
///
|
||||||
/// All further calls to [`push`] will collect nodes for this group.
|
/// All further calls to [`push`](Self::push) will collect nodes for this group.
|
||||||
/// The given metadata will be returned alongside the collected nodes
|
/// The given metadata will be returned alongside the collected nodes
|
||||||
/// in a matching call to [`end_group`].
|
/// in a matching call to [`end_group`](Self::end_group).
|
||||||
///
|
|
||||||
/// [`push`]: #method.push
|
|
||||||
/// [`end_group`]: #method.end_group
|
|
||||||
fn start_group<T: 'static>(&mut self, meta: T) {
|
fn start_group<T: 'static>(&mut self, meta: T) {
|
||||||
self.groups.push((Box::new(meta), std::mem::take(&mut self.inner)));
|
self.groups.push((Box::new(meta), std::mem::take(&mut self.inner)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// End a layouting group started with [`start_group`].
|
/// End a layouting group started with [`start_group`](Self::start_group).
|
||||||
///
|
///
|
||||||
/// This returns the stored metadata and the collected nodes.
|
/// This returns the stored metadata and the collected nodes.
|
||||||
///
|
|
||||||
/// [`start_group`]: #method.start_group
|
|
||||||
fn end_group<T: 'static>(&mut self) -> (T, Vec<LayoutNode>) {
|
fn end_group<T: 'static>(&mut self) -> (T, Vec<LayoutNode>) {
|
||||||
if let Some(&LayoutNode::Spacing(spacing)) = self.inner.last() {
|
if let Some(&LayoutNode::Spacing(spacing)) = self.inner.last() {
|
||||||
if spacing.softness == Softness::Soft {
|
if spacing.softness == Softness::Soft {
|
||||||
|
@ -134,7 +134,6 @@ pub type ValueDict = Dict<SpannedEntry<Value>>;
|
|||||||
/// [`Value`] when directly putting the `Rc` in there, see the [Rust
|
/// [`Value`] when directly putting the `Rc` in there, see the [Rust
|
||||||
/// Issue].
|
/// Issue].
|
||||||
///
|
///
|
||||||
/// [`Value`]: enum.Value.html
|
|
||||||
/// [Rust Issue]: https://github.com/rust-lang/rust/issues/31740
|
/// [Rust Issue]: https://github.com/rust-lang/rust/issues/31740
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ValueFunc(pub Rc<Func>);
|
pub struct ValueFunc(pub Rc<Func>);
|
||||||
|
@ -18,8 +18,7 @@ use crate::layout::{BoxLayout, LayoutElement};
|
|||||||
/// pass in the font loader used for typesetting such that the fonts can be
|
/// pass in the font loader used for typesetting such that the fonts can be
|
||||||
/// included in the _PDF_.
|
/// included in the _PDF_.
|
||||||
///
|
///
|
||||||
/// The raw _PDF_ is written into the `target` writable, returning the number of
|
/// Returns the raw bytes making up the _PDF_ document.
|
||||||
/// bytes written.
|
|
||||||
pub fn export(layouts: &[BoxLayout], loader: &FontLoader) -> Vec<u8> {
|
pub fn export(layouts: &[BoxLayout], loader: &FontLoader) -> Vec<u8> {
|
||||||
PdfExporter::new(layouts, loader).write()
|
PdfExporter::new(layouts, loader).write()
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@ use super::*;
|
|||||||
/// A relative length.
|
/// A relative length.
|
||||||
///
|
///
|
||||||
/// _Note_: `50%` is represented as `0.5` here, but stored as `50.0` in the
|
/// _Note_: `50%` is represented as `0.5` here, but stored as `50.0` in the
|
||||||
/// corresponding [literal].
|
/// corresponding [literal](crate::syntax::Lit::Percent).
|
||||||
///
|
|
||||||
/// [literal]: ../syntax/ast/enum.Lit.html#variant.Percent
|
|
||||||
#[derive(Default, Copy, Clone, PartialEq, PartialOrd)]
|
#[derive(Default, Copy, Clone, PartialEq, PartialOrd)]
|
||||||
pub struct Relative(f64);
|
pub struct Relative(f64);
|
||||||
|
|
||||||
|
@ -23,9 +23,7 @@ impl Document {
|
|||||||
pub struct Pages {
|
pub struct Pages {
|
||||||
/// The size of the pages.
|
/// The size of the pages.
|
||||||
pub size: Size,
|
pub size: Size,
|
||||||
/// The layout node that produces the actual pages (typically a [stack]).
|
/// The layout node that produces the actual pages (typically a [`Stack`]).
|
||||||
///
|
|
||||||
/// [stack]: struct.Stack.html
|
|
||||||
pub child: LayoutNode,
|
pub child: LayoutNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +124,7 @@ impl Expansion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The result of [layouting] a node.
|
/// The result of [layouting](Layout::layout) a node.
|
||||||
///
|
|
||||||
/// [layouting]: trait.Layout.html#method.layout
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Layouted {
|
pub enum Layouted {
|
||||||
/// Spacing that should be added to the parent.
|
/// Spacing that should be added to the parent.
|
||||||
|
@ -50,7 +50,6 @@ impl Debug for LayoutNode {
|
|||||||
/// [`LayoutNode`] when directly putting the `Box` in there, see the
|
/// [`LayoutNode`] when directly putting the `Box` in there, see the
|
||||||
/// [Rust Issue].
|
/// [Rust Issue].
|
||||||
///
|
///
|
||||||
/// [`LayoutNode`]: enum.LayoutNode.html
|
|
||||||
/// [Rust Issue]: https://github.com/rust-lang/rust/issues/31740
|
/// [Rust Issue]: https://github.com/rust-lang/rust/issues/31740
|
||||||
pub struct Dynamic(pub Box<dyn DynNode>);
|
pub struct Dynamic(pub Box<dyn DynNode>);
|
||||||
|
|
||||||
@ -102,8 +101,6 @@ impl PartialEq for Dynamic {
|
|||||||
/// DynNode>` able to implement `Clone` and `PartialEq`. However, these are
|
/// DynNode>` able to implement `Clone` and `PartialEq`. However, these are
|
||||||
/// automatically provided by a blanket impl as long as the type in question
|
/// automatically provided by a blanket impl as long as the type in question
|
||||||
/// implements[`Layout`], `Debug`, `PartialEq`, `Clone` and is `'static`.
|
/// implements[`Layout`], `Debug`, `PartialEq`, `Clone` and is `'static`.
|
||||||
///
|
|
||||||
/// [`Layout`]: ../trait.Layout.html
|
|
||||||
pub trait DynNode: Debug + Layout + 'static {
|
pub trait DynNode: Debug + Layout + 'static {
|
||||||
/// Convert into a `dyn Any` to enable downcasting.
|
/// Convert into a `dyn Any` to enable downcasting.
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
|
@ -7,10 +7,8 @@ use super::*;
|
|||||||
pub struct Spacing {
|
pub struct Spacing {
|
||||||
/// The amount of spacing to insert.
|
/// The amount of spacing to insert.
|
||||||
pub amount: Length,
|
pub amount: Length,
|
||||||
/// Spacing interaction, see [Softness's] documentation for more
|
/// Spacing interaction, see [`Softness`]'s documentation for more
|
||||||
/// information.
|
/// information.
|
||||||
///
|
|
||||||
/// [Softness's]: enum.Softness.html
|
|
||||||
pub softness: Softness,
|
pub softness: Softness,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/lib.rs
24
src/lib.rs
@ -3,30 +3,26 @@
|
|||||||
//! # Steps
|
//! # Steps
|
||||||
//! - **Parsing:** The parsing step first transforms a plain string into an
|
//! - **Parsing:** The parsing step first transforms a plain string into an
|
||||||
//! [iterator of tokens][tokens]. This token stream is [parsed] into a [syntax
|
//! [iterator of tokens][tokens]. This token stream is [parsed] into a [syntax
|
||||||
//! tree]. The structures describing the tree can be found in the [AST]
|
//! tree]. The structures describing the tree can be found in the [syntax]
|
||||||
//! module.
|
//! module.
|
||||||
//! - **Evaluation:** The next step is to [evaluate] the parsed "script" to a
|
//! - **Evaluation:** The next step is to [evaluate] the parsed "script" to a
|
||||||
//! [document], a high-level, fully styled representation. The [nodes] of the
|
//! [document], a high-level, fully styled representation. The nodes of the
|
||||||
//! document tree are fully self-contained and order-independent and thus much
|
//! document tree are fully self-contained and order-independent and thus much
|
||||||
//! better suited for layouting than the syntax tree.
|
//! better suited for layouting than the syntax tree.
|
||||||
//! - **Layouting:** The next step is to [layout] the document into a portable
|
//! - **Layouting:** The next step is to [layout] the document into a portable
|
||||||
//! version of the typeset document. The output of this is a vector of
|
//! version of the typeset document. The output of this is a vector of
|
||||||
//! [`BoxLayouts`] (corresponding to pages), ready for exporting.
|
//! [`BoxLayout`]s (corresponding to pages), ready for exporting.
|
||||||
//! - **Exporting:** The finished layout can be exported into a supported
|
//! - **Exporting:** The finished layout can be exported into a supported
|
||||||
//! format. Submodules for these formats are located in the [export] module.
|
//! format. Submodules for these formats are located in the [export] module.
|
||||||
//! Currently, the only supported output format is [_PDF_].
|
//! Currently, the only supported output format is [_PDF_].
|
||||||
//!
|
//!
|
||||||
//! [tokens]: parse/struct.Tokens.html
|
//! [tokens]: parse::Tokens
|
||||||
//! [parsed]: parse/fn.parse.html
|
//! [parsed]: parse::parse
|
||||||
//! [syntax tree]: syntax/ast/type.SynTree.html
|
//! [syntax tree]: syntax::SynTree
|
||||||
//! [AST]: syntax/ast/index.html
|
//! [evaluate]: eval::eval
|
||||||
//! [evaluate]: eval/fn.eval.html
|
//! [document]: layout::Document
|
||||||
//! [document]: layout/nodes/struct.Document.html
|
//! [layout]: layout::layout
|
||||||
//! [nodes]: layout/nodes/index.html
|
//! [_PDF_]: export::pdf
|
||||||
//! [layout]: layout/fn.layout.html
|
|
||||||
//! [`BoxLayouts`]: layout/struct.BoxLayout.html
|
|
||||||
//! [export]: export/index.html
|
|
||||||
//! [_PDF_]: export/pdf/index.html
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod diag;
|
pub mod diag;
|
||||||
|
@ -59,8 +59,6 @@ impl Debug for Shaped {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Shape text into a box containing [`Shaped`] runs.
|
/// Shape text into a box containing [`Shaped`] runs.
|
||||||
///
|
|
||||||
/// [`Shaped`]: struct.Shaped.html
|
|
||||||
pub fn shape(
|
pub fn shape(
|
||||||
loader: &mut FontLoader,
|
loader: &mut FontLoader,
|
||||||
text: &str,
|
text: &str,
|
||||||
|
@ -21,9 +21,7 @@ pub enum Lit {
|
|||||||
/// A percent literal: `50%`.
|
/// A percent literal: `50%`.
|
||||||
///
|
///
|
||||||
/// _Note_: `50%` is stored as `50.0` here, but as `0.5` in the
|
/// _Note_: `50%` is stored as `50.0` here, but as `0.5` in the
|
||||||
/// corresponding [value].
|
/// corresponding [value](crate::geom::Relative).
|
||||||
///
|
|
||||||
/// [value]: ../../geom/struct.Relative.html
|
|
||||||
Percent(f64),
|
Percent(f64),
|
||||||
/// A color literal: `#ffccee`.
|
/// A color literal: `#ffccee`.
|
||||||
Color(RgbaColor),
|
Color(RgbaColor),
|
||||||
|
@ -76,9 +76,7 @@ pub enum Token<'s> {
|
|||||||
/// A percentage: `50%`.
|
/// A percentage: `50%`.
|
||||||
///
|
///
|
||||||
/// _Note_: `50%` is stored as `50.0` here, as in the corresponding
|
/// _Note_: `50%` is stored as `50.0` here, as in the corresponding
|
||||||
/// [literal].
|
/// [literal](super::Lit::Percent).
|
||||||
///
|
|
||||||
/// [literal]: ../ast/enum.Lit.html#variant.Percent
|
|
||||||
Percent(f64),
|
Percent(f64),
|
||||||
/// A hex value: `#20d82a`.
|
/// A hex value: `#20d82a`.
|
||||||
Hex(&'s str),
|
Hex(&'s str),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user