From 5e08028fb36aa766957cba64c5c665edf9b96fb7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 21 Mar 2021 17:46:09 +0100 Subject: =?UTF-8?q?Syntax=20functions=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds overridable functions that markup desugars into. Specifically: - \ desugars into linebreak - Two newlines desugar into parbreak - * desugars into strong - _ desugars into emph - = .. desugars into heading - `..` desugars into raw --- src/exec/context.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/exec/context.rs') diff --git a/src/exec/context.rs b/src/exec/context.rs index 761977fc..f19f6561 100644 --- a/src/exec/context.rs +++ b/src/exec/context.rs @@ -11,7 +11,7 @@ use crate::geom::{Dir, Gen, Linear, Sides, Size}; use crate::layout::{ Node, PadNode, PageRun, ParNode, SpacingNode, StackNode, TextNode, Tree, }; -use crate::parse::is_newline; +use crate::parse::{is_newline, Scanner}; use crate::syntax::{Span, Spanned}; /// The context for execution. @@ -99,16 +99,19 @@ impl<'a> ExecContext<'a> { /// /// The text is split into lines at newlines. pub fn push_text(&mut self, text: &str) { - let mut newline = false; - for line in text.split_terminator(is_newline) { - if newline { + let mut scanner = Scanner::new(text); + let mut line = String::new(); + + while let Some(c) = scanner.eat_merging_crlf() { + if is_newline(c) { + self.push(self.make_text_node(mem::take(&mut line))); self.push_linebreak(); + } else { + line.push(c); } - - let node = self.make_text_node(line.into()); - self.push(node); - newline = true; } + + self.push(self.make_text_node(line)); } /// Apply a forced line break. -- cgit v1.2.3