summaryrefslogtreecommitdiff
path: root/src/exec/context.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-21 17:46:09 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-21 17:50:56 +0100
commit5e08028fb36aa766957cba64c5c665edf9b96fb7 (patch)
tree912799dad3c1e25b7032f3e3bee009537c6f555b /src/exec/context.rs
parent898728f260923a91444eb23b522d0abf01a4299b (diff)
Syntax functions 🚀
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
Diffstat (limited to 'src/exec/context.rs')
-rw-r--r--src/exec/context.rs19
1 files changed, 11 insertions, 8 deletions
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.