summaryrefslogtreecommitdiff
path: root/src/library/markup.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-06-09 00:37:13 +0200
committerLaurenz <laurmaedje@gmail.com>2021-06-09 00:37:13 +0200
commit5afb42ad89abb518a01a09051f0f9b6f75bd383e (patch)
treeb12368a287f22de711df8d759c20ee742ed5b4c2 /src/library/markup.rs
parentd69dfa84ec957ac4037f60a3335416a9f73b97c8 (diff)
Lists with indent-based parsing
- Unordered lists with indent-based parsing and basic layout using stacks - Headings are now also indent based - Removes syntax functions since they will be superseded by select & transform
Diffstat (limited to 'src/library/markup.rs')
-rw-r--r--src/library/markup.rs170
1 files changed, 0 insertions, 170 deletions
diff --git a/src/library/markup.rs b/src/library/markup.rs
deleted file mode 100644
index 0a80fe74..00000000
--- a/src/library/markup.rs
+++ /dev/null
@@ -1,170 +0,0 @@
-use super::*;
-use crate::syntax::{HeadingNode, RawNode};
-
-/// `linebreak`: Start a new line.
-///
-/// # Syntax
-/// This function has dedicated syntax:
-/// ```typst
-/// This line ends here, \
-/// And a new one begins.
-/// ```
-///
-/// # Return value
-/// A template that inserts a line break.
-pub fn linebreak(_: &mut EvalContext, _: &mut FuncArgs) -> Value {
- Value::template(Node::LINEBREAK, move |ctx| {
- ctx.linebreak();
- })
-}
-
-/// `parbreak`: Start a new paragraph.
-///
-/// # Return value
-/// A template that inserts a paragraph break.
-pub fn parbreak(_: &mut EvalContext, _: &mut FuncArgs) -> Value {
- Value::template(Node::PARBREAK, move |ctx| {
- ctx.parbreak();
- })
-}
-
-/// `strong`: Strong text.
-///
-/// # Syntax
-/// This function has dedicated syntax.
-/// ```typst
-/// This is *important*!
-/// ```
-///
-/// # Positional parameters
-/// - Body: optional, of type `template`.
-///
-/// # Return value
-/// A template that flips the boldness of text. The effect is scoped to the
-/// body if present.
-pub fn strong(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
- let body = args.eat::<TemplateValue>(ctx);
- Value::template(Node::STRONG, move |ctx| {
- let snapshot = ctx.state.clone();
- ctx.state.font.strong ^= true;
-
- if let Some(body) = &body {
- body.exec(ctx);
- ctx.state = snapshot;
- }
- })
-}
-
-/// `emph`: Emphasized text.
-///
-/// # Syntax
-/// This function has dedicated syntax.
-/// ```typst
-/// I would have _never_ thought so!
-/// ```
-///
-/// # Positional parameters
-/// - Body: optional, of type `template`.
-///
-/// # Return value
-/// A template that flips whether text is set in italics. The effect is scoped
-/// to the body if present.
-pub fn emph(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
- let body = args.eat::<TemplateValue>(ctx);
- Value::template(Node::EMPH, move |ctx| {
- let snapshot = ctx.state.clone();
- ctx.state.font.emph ^= true;
-
- if let Some(body) = &body {
- body.exec(ctx);
- ctx.state = snapshot;
- }
- })
-}
-
-/// `heading`: A section heading.
-///
-/// # Syntax
-/// This function has dedicated syntax.
-/// ```typst
-/// = Section
-/// ...
-///
-/// == Subsection
-/// ...
-/// ```
-///
-/// # Positional parameters
-/// - Body, of type `template`.
-///
-/// # Named parameters
-/// - Section depth: `level`, of type `integer` between 1 and 6.
-///
-/// # Return value
-/// A template that sets the body as a section heading, that is, large and in
-/// bold.
-pub fn heading(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
- let level = args.eat_named(ctx, HeadingNode::LEVEL).unwrap_or(1);
- let body = args
- .eat_expect::<TemplateValue>(ctx, HeadingNode::BODY)
- .unwrap_or_default();
-
- Value::template(Node::HEADING, move |ctx| {
- let snapshot = ctx.state.clone();
- let upscale = 1.6 - 0.1 * level as f64;
- ctx.state.font.scale *= upscale;
- ctx.state.font.strong = true;
-
- body.exec(ctx);
- ctx.state = snapshot;
-
- ctx.parbreak();
- })
-}
-
-/// `raw`: Raw text.
-///
-/// # Syntax
-/// This function has dedicated syntax:
-/// - For inline-level raw text:
-/// ```typst
-/// `...`
-/// ```
-/// - For block-level raw text:
-/// ````typst
-/// ```rust
-/// println!("Hello World!");
-/// ```
-/// ````
-///
-/// # Positional parameters
-/// - Text, of type `string`.
-///
-/// # Named parameters
-/// - Language for syntax highlighting: `lang`, of type `string`.
-/// - Whether the item is block level (split in its own paragraph): `block`, of
-/// type `boolean`.
-///
-/// # Return value
-/// A template that sets the text raw, that is, in monospace and optionally with
-/// syntax highlighting.
-pub fn raw(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
- let text = args.eat_expect::<String>(ctx, RawNode::TEXT).unwrap_or_default();
- let _lang = args.eat_named::<String>(ctx, RawNode::LANG);
- let block = args.eat_named(ctx, RawNode::BLOCK).unwrap_or(false);
-
- Value::template(Node::RAW, move |ctx| {
- if block {
- ctx.parbreak();
- }
-
- let snapshot = ctx.state.clone();
- ctx.set_monospace();
- ctx.push_text(&text);
- ctx.state = snapshot;
-
- if block {
- ctx.parbreak();
- }
- })
-}