Skip to content

Commit 7460a2f

Browse files
kivikakkyannham
authored andcommitted
nodes: remedy some can_contain_type omissions, document EscapedTag issue.
1 parent 373e8d1 commit 7460a2f

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/nodes.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,6 @@ impl<'a> From<Ast> for AstNode<'a> {
666666
/// Validation errors produced by [Node::validate].
667667
#[derive(Debug, Clone)]
668668
pub enum ValidationError<'a> {
669-
/// Children were found for a node that isn't supposed to have chilrden.
670-
UnexpectedChildren(&'a AstNode<'a>),
671669
/// The type of a child node is not allowed in the parent node. This can happen when an inline
672670
/// node is found in a block container, a block is found in an inline node, etc.
673671
InvalidChildType {
@@ -756,7 +754,16 @@ pub fn can_contain_type<'a>(node: &'a AstNode<'a>, child: &NodeValue) -> bool {
756754
| NodeValue::Strong
757755
| NodeValue::Link(..)
758756
| NodeValue::Image(..)
759-
| NodeValue::WikiLink(..) => !child.block(),
757+
| NodeValue::WikiLink(..)
758+
| NodeValue::Strikethrough
759+
| NodeValue::Superscript
760+
| NodeValue::SpoileredText
761+
| NodeValue::Underline
762+
// XXX: this is quite a hack: the EscapedTag _contains_ whatever was
763+
// possibly going to fall into the spoiler. This should be fixed in
764+
// inlines.
765+
| NodeValue::EscapedTag(_)
766+
=> !child.block(),
760767

761768
NodeValue::Table(..) => matches!(*child, NodeValue::TableRow(..)),
762769

@@ -775,22 +782,30 @@ pub fn can_contain_type<'a>(node: &'a AstNode<'a>, child: &NodeValue) -> bool {
775782
| NodeValue::HtmlInline(..)
776783
| NodeValue::Math(..)
777784
| NodeValue::WikiLink(..)
785+
| NodeValue::FootnoteReference(..)
786+
| NodeValue::Superscript
787+
| NodeValue::SpoileredText
788+
| NodeValue::Underline
778789
),
779790

780791
#[cfg(feature = "shortcodes")]
781792
NodeValue::TableCell => matches!(
782793
*child,
783794
NodeValue::Text(..)
784-
| NodeValue::Code(..)
785-
| NodeValue::Emph
786-
| NodeValue::Strong
787-
| NodeValue::Link(..)
788-
| NodeValue::Image(..)
789-
| NodeValue::ShortCode(..)
790-
| NodeValue::Strikethrough
791-
| NodeValue::HtmlInline(..)
792-
| NodeValue::Math(..)
793-
| NodeValue::WikiLink(..)
795+
| NodeValue::Code(..)
796+
| NodeValue::Emph
797+
| NodeValue::Strong
798+
| NodeValue::Link(..)
799+
| NodeValue::Image(..)
800+
| NodeValue::Strikethrough
801+
| NodeValue::HtmlInline(..)
802+
| NodeValue::Math(..)
803+
| NodeValue::WikiLink(..)
804+
| NodeValue::FootnoteReference(..)
805+
| NodeValue::Superscript
806+
| NodeValue::SpoileredText
807+
| NodeValue::Underline
808+
| NodeValue::ShortCode(..)
794809
),
795810

796811
NodeValue::MultilineBlockQuote(_) => {

src/tests/commonmark.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ fn commonmark_avoids_spurious_backslash() {
2626

2727
let p1 = ast(NodeValue::Paragraph);
2828
p1.append(ast(NodeValue::Text("Line 1".to_owned())));
29+
p1.append(ast(NodeValue::LineBreak));
2930
root.append(p1);
3031

31-
root.append(ast(NodeValue::LineBreak));
32-
3332
let p2 = ast(NodeValue::Paragraph);
3433
p2.append(ast(NodeValue::Text("Line 2".to_owned())));
3534
root.append(p2);

0 commit comments

Comments
 (0)