From 2045b0bfc467efeb605aad7d8297a1fa1fc3e0e9 Mon Sep 17 00:00:00 2001 From: Kyle McCarthy Date: Tue, 3 Jan 2023 04:52:22 -0600 Subject: Add support for serializing trees as JSON This adds support for serializing the mdast syntax tree as JSON, with serde, through a feature. Closes GH-10. Related-to GH-30. Closes GH-37. --- src/to_mdast.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/to_mdast.rs') diff --git a/src/to_mdast.rs b/src/to_mdast.rs index e76bad5..4659d7b 100644 --- a/src/to_mdast.rs +++ b/src/to_mdast.rs @@ -2,11 +2,12 @@ use crate::event::{Event, Kind, Name, Point as EventPoint}; use crate::mdast::{ - AttributeContent, AttributeValue, BlockQuote, Break, Code, Definition, Delete, Emphasis, - FootnoteDefinition, FootnoteReference, Heading, Html, Image, ImageReference, InlineCode, - InlineMath, Link, LinkReference, List, ListItem, Math, MdxFlowExpression, MdxJsxAttribute, - MdxJsxFlowElement, MdxJsxTextElement, MdxTextExpression, MdxjsEsm, Node, Paragraph, - ReferenceKind, Root, Strong, Table, TableCell, TableRow, Text, ThematicBreak, Toml, Yaml, + AttributeContent, AttributeValue, AttributeValueExpression, BlockQuote, Break, Code, + Definition, Delete, Emphasis, FootnoteDefinition, FootnoteReference, Heading, Html, Image, + ImageReference, InlineCode, InlineMath, Link, LinkReference, List, ListItem, Math, + MdxFlowExpression, MdxJsxAttribute, MdxJsxFlowElement, MdxJsxTextElement, MdxTextExpression, + MdxjsEsm, Node, Paragraph, ReferenceKind, Root, Strong, Table, TableCell, TableRow, Text, + ThematicBreak, Toml, Yaml, }; use crate::unist::{Point, Position}; use crate::util::{ @@ -14,7 +15,7 @@ use crate::util::{ decode as decode_character_reference, parse as parse_character_reference, }, infer::{gfm_table_align, list_item_loose, list_loose}, - mdx_collect::collect, + mdx_collect::{collect, Result as CollectResult}, normalize_identifier::normalize_identifier, slice::{Position as SlicePosition, Slice}, }; @@ -834,7 +835,7 @@ fn on_enter_mdx_jsx_tag_attribute(context: &mut CompileContext) -> Result<(), St fn on_enter_mdx_jsx_tag_attribute_expression(context: &mut CompileContext) -> Result<(), String> { on_enter_mdx_jsx_tag_any_attribute(context)?; - let result = collect( + let CollectResult { value, stops } = collect( context.events, context.bytes, context.index, @@ -846,7 +847,7 @@ fn on_enter_mdx_jsx_tag_attribute_expression(context: &mut CompileContext) -> Re .as_mut() .expect("expected tag") .attributes - .push(AttributeContent::Expression(result.value, result.stops)); + .push(AttributeContent::Expression { value, stops }); context.buffer(); @@ -855,7 +856,7 @@ fn on_enter_mdx_jsx_tag_attribute_expression(context: &mut CompileContext) -> Re /// Handle [`Enter`][Kind::Enter]:[`MdxJsxTagAttributeValueExpression`][Name::MdxJsxTagAttributeValueExpression]. fn on_enter_mdx_jsx_tag_attribute_value_expression(context: &mut CompileContext) { - let result = collect( + let CollectResult { value, stops } = collect( context.events, context.bytes, context.index, @@ -870,7 +871,10 @@ fn on_enter_mdx_jsx_tag_attribute_value_expression(context: &mut CompileContext) .attributes .last_mut() { - node.value = Some(AttributeValue::Expression(result.value, result.stops)); + node.value = Some(AttributeValue::Expression(AttributeValueExpression { + value, + stops, + })); } else { unreachable!("expected property") } -- cgit