diff options
author | Kyle McCarthy <km@kylemccarthy.io> | 2023-01-03 04:52:22 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 11:52:22 +0100 |
commit | 2045b0bfc467efeb605aad7d8297a1fa1fc3e0e9 (patch) | |
tree | 7dab2abbf993e04b269fbab3191d7bfa7b7663ae /src/to_mdast.rs | |
parent | af202d3f0ea24e0a957b02a6f9fb23c6c3b4afe7 (diff) | |
download | markdown-rs-2045b0bfc467efeb605aad7d8297a1fa1fc3e0e9.tar.gz markdown-rs-2045b0bfc467efeb605aad7d8297a1fa1fc3e0e9.tar.bz2 markdown-rs-2045b0bfc467efeb605aad7d8297a1fa1fc3e0e9.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/to_mdast.rs | 24 |
1 files changed, 14 insertions, 10 deletions
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") } |