diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-01-30 12:50:58 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-01-30 22:46:59 +0100 |
| commit | 8d1ce390e21ce0a5812a4211c893ec359906d6f1 (patch) | |
| tree | 5dbe1ad96af8ce8f9f01887340fe06025462e959 /src/eval | |
| parent | d7072f378fef733ae994fd9a1e767df4e4dd878e (diff) | |
Rework strong and emph
- Star and underscore not parsed as strong/emph inside of words
- Stars/underscores must be balanced and they cannot go over paragraph break
- New `strong` and `emph` classes
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/mod.rs | 26 | ||||
| -rw-r--r-- | src/eval/styles.rs | 13 |
2 files changed, 18 insertions, 21 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 2fa07d49..a453a357 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -213,15 +213,9 @@ impl Eval for MarkupNode { Self::Space => Node::Space, Self::Linebreak => Node::Linebreak, Self::Parbreak => Node::Parbreak, - Self::Strong => { - ctx.styles.toggle(TextNode::STRONG); - Node::new() - } - Self::Emph => { - ctx.styles.toggle(TextNode::EMPH); - Node::new() - } Self::Text(text) => Node::Text(text.clone()), + Self::Strong(strong) => strong.eval(ctx)?, + Self::Emph(emph) => emph.eval(ctx)?, Self::Raw(raw) => raw.eval(ctx)?, Self::Math(math) => math.eval(ctx)?, Self::Heading(heading) => heading.eval(ctx)?, @@ -232,6 +226,22 @@ impl Eval for MarkupNode { } } +impl Eval for StrongNode { + type Output = Node; + + fn eval(&self, ctx: &mut EvalContext) -> TypResult<Self::Output> { + Ok(self.body().eval(ctx)?.styled(TextNode::STRONG, true)) + } +} + +impl Eval for EmphNode { + type Output = Node; + + fn eval(&self, ctx: &mut EvalContext) -> TypResult<Self::Output> { + Ok(self.body().eval(ctx)?.styled(TextNode::EMPH, true)) + } +} + impl Eval for RawNode { type Output = Node; diff --git a/src/eval/styles.rs b/src/eval/styles.rs index bdc01f1f..508996a1 100644 --- a/src/eval/styles.rs +++ b/src/eval/styles.rs @@ -87,19 +87,6 @@ impl StyleMap { } } - /// Toggle a boolean style property, removing it if it exists and inserting - /// it with `true` if it doesn't. - pub fn toggle<P: Property<Value = bool>>(&mut self, key: P) { - for (i, entry) in self.0.iter_mut().enumerate() { - if entry.is::<P>() { - self.0.swap_remove(i); - return; - } - } - - self.0.push(Entry::new(key, true)); - } - /// Mark all contained properties as _scoped_. This means that they only /// apply to the first descendant node (of their type) in the hierarchy and /// not its children, too. This is used by class constructors. |
