Markdown parser fork with extended syntax for personal use.

Fix serde, change `BlockQuote` -> `Blockquote`

Closes GH-72.
Closes GH-74.
Closes GH-135.

authored by

Harsha Teja Kanna and committed by
GitHub
fa8f9060 af3ebbcf

+180 -186
+1 -1
.github/workflows/main.yml
··· 20 20 - uses: dtolnay/rust-toolchain@v1 21 21 with: 22 22 toolchain: stable 23 - - run: cargo install cargo-tarpaulin && cargo tarpaulin --out xml 23 + - run: cargo install cargo-tarpaulin && cargo tarpaulin --features json --out xml 24 24 - uses: codecov/codecov-action@v4
+1
Cargo.toml
··· 32 32 env_logger = "0.11" 33 33 criterion = "0.5" 34 34 pretty_assertions = "1" 35 + serde_json = { version = "1" } 35 36 swc_core = { version = "0.100", features = [ 36 37 "ecma_ast", 37 38 "ecma_visit",
+3 -3
readme.md
··· 254 254 ``` 255 255 * format: 256 256 ```sh 257 - cargo fmt && cargo fix --all-targets 257 + cargo fmt && cargo fix --all-targets --all-features 258 258 ``` 259 259 * lint: 260 260 ```sh 261 - cargo fmt --check && cargo clippy --examples --tests --benches --all-features 261 + cargo fmt --check && cargo clippy --examples --tests --benches --all-features --all-features 262 262 ``` 263 263 * test: 264 264 ```sh 265 - RUST_BACKTRACE=1 cargo test 265 + RUST_BACKTRACE=1 cargo test --all-features 266 266 ``` 267 267 * docs: 268 268 ```sh
+49 -178
src/mdast.rs
··· 86 86 #[cfg_attr( 87 87 feature = "serde", 88 88 derive(serde::Serialize, serde::Deserialize), 89 - serde(tag = "type", rename = "type") 89 + serde(tag = "type", rename_all = "camelCase") 90 90 )] 91 91 pub enum Node { 92 92 // Document: ··· 95 95 96 96 // Container: 97 97 /// Block quote. 98 - BlockQuote(BlockQuote), 98 + Blockquote(Blockquote), 99 99 /// Footnote definition. 100 100 FootnoteDefinition(FootnoteDefinition), 101 101 /// MDX: JSX element (container). ··· 183 183 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 184 184 match self { 185 185 Node::Root(x) => x.fmt(f), 186 - Node::BlockQuote(x) => x.fmt(f), 186 + Node::Blockquote(x) => x.fmt(f), 187 187 Node::FootnoteDefinition(x) => x.fmt(f), 188 188 Node::MdxJsxFlowElement(x) => x.fmt(f), 189 189 Node::List(x) => x.fmt(f), ··· 231 231 match self { 232 232 // Parents. 233 233 Node::Root(x) => children_to_string(&x.children), 234 - Node::BlockQuote(x) => children_to_string(&x.children), 234 + Node::Blockquote(x) => children_to_string(&x.children), 235 235 Node::FootnoteDefinition(x) => children_to_string(&x.children), 236 236 Node::MdxJsxFlowElement(x) => children_to_string(&x.children), 237 237 Node::List(x) => children_to_string(&x.children), ··· 280 280 Node::Root(x) => Some(&x.children), 281 281 Node::Paragraph(x) => Some(&x.children), 282 282 Node::Heading(x) => Some(&x.children), 283 - Node::BlockQuote(x) => Some(&x.children), 283 + Node::Blockquote(x) => Some(&x.children), 284 284 Node::List(x) => Some(&x.children), 285 285 Node::ListItem(x) => Some(&x.children), 286 286 Node::Emphasis(x) => Some(&x.children), ··· 305 305 Node::Root(x) => Some(&mut x.children), 306 306 Node::Paragraph(x) => Some(&mut x.children), 307 307 Node::Heading(x) => Some(&mut x.children), 308 - Node::BlockQuote(x) => Some(&mut x.children), 308 + Node::Blockquote(x) => Some(&mut x.children), 309 309 Node::List(x) => Some(&mut x.children), 310 310 Node::ListItem(x) => Some(&mut x.children), 311 311 Node::Emphasis(x) => Some(&mut x.children), ··· 328 328 pub fn position(&self) -> Option<&Position> { 329 329 match self { 330 330 Node::Root(x) => x.position.as_ref(), 331 - Node::BlockQuote(x) => x.position.as_ref(), 331 + Node::Blockquote(x) => x.position.as_ref(), 332 332 Node::FootnoteDefinition(x) => x.position.as_ref(), 333 333 Node::MdxJsxFlowElement(x) => x.position.as_ref(), 334 334 Node::List(x) => x.position.as_ref(), ··· 367 367 pub fn position_mut(&mut self) -> Option<&mut Position> { 368 368 match self { 369 369 Node::Root(x) => x.position.as_mut(), 370 - Node::BlockQuote(x) => x.position.as_mut(), 370 + Node::Blockquote(x) => x.position.as_mut(), 371 371 Node::FootnoteDefinition(x) => x.position.as_mut(), 372 372 Node::MdxJsxFlowElement(x) => x.position.as_mut(), 373 373 Node::List(x) => x.position.as_mut(), ··· 406 406 pub fn position_set(&mut self, position: Option<Position>) { 407 407 match self { 408 408 Node::Root(x) => x.position = position, 409 - Node::BlockQuote(x) => x.position = position, 409 + Node::Blockquote(x) => x.position = position, 410 410 Node::FootnoteDefinition(x) => x.position = position, 411 411 Node::MdxJsxFlowElement(x) => x.position = position, 412 412 Node::List(x) => x.position = position, ··· 448 448 #[cfg_attr( 449 449 feature = "serde", 450 450 derive(serde::Serialize, serde::Deserialize), 451 - serde(tag = "type", rename = "mdxJsxExpressionAttribute") 451 + serde(untagged, rename = "mdxJsxExpressionAttribute") 452 452 )] 453 453 pub enum AttributeContent { 454 454 /// JSX expression. ··· 483 483 #[cfg_attr( 484 484 feature = "serde", 485 485 derive(serde::Serialize, serde::Deserialize), 486 - serde(tag = "type", rename = "type") 486 + serde(untagged) 487 487 )] 488 488 pub enum AttributeValue { 489 489 /// Expression value. ··· 499 499 /// > | <a b="c" /> 500 500 /// ^^^ 501 501 /// ``` 502 - #[cfg_attr(feature = "serde", serde(rename = "literal"))] 503 502 Literal(String), 504 503 } 505 504 ··· 510 509 /// ^ 511 510 /// ``` 512 511 #[derive(Clone, Debug, Eq, PartialEq)] 513 - #[cfg_attr( 514 - feature = "serde", 515 - derive(serde::Serialize, serde::Deserialize), 516 - serde(tag = "type", rename = "root") 517 - )] 512 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 518 513 pub struct Root { 519 514 // Parent. 520 515 /// Content model. ··· 530 525 /// ^ 531 526 /// ``` 532 527 #[derive(Clone, Debug, Eq, PartialEq)] 533 - #[cfg_attr( 534 - feature = "serde", 535 - derive(serde::Serialize, serde::Deserialize), 536 - serde(tag = "type", rename = "paragraph") 537 - )] 528 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 538 529 pub struct Paragraph { 539 530 // Parent. 540 531 /// Content model. ··· 550 541 /// ^^^ 551 542 /// ``` 552 543 #[derive(Clone, Debug, Eq, PartialEq)] 553 - #[cfg_attr( 554 - feature = "serde", 555 - derive(serde::Serialize, serde::Deserialize), 556 - serde(tag = "type", rename = "heading") 557 - )] 544 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 558 545 pub struct Heading { 559 546 // Parent. 560 547 /// Content model. ··· 573 560 /// ^^^ 574 561 /// ``` 575 562 #[derive(Clone, Debug, Eq, PartialEq)] 576 - #[cfg_attr( 577 - feature = "serde", 578 - derive(serde::Serialize, serde::Deserialize), 579 - serde(tag = "type", rename = "thematicBreak") 580 - )] 563 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 581 564 pub struct ThematicBreak { 582 565 // Void. 583 566 /// Positional info. ··· 591 574 /// ^^^ 592 575 /// ``` 593 576 #[derive(Clone, Debug, Eq, PartialEq)] 594 - #[cfg_attr( 595 - feature = "serde", 596 - derive(serde::Serialize, serde::Deserialize), 597 - serde(tag = "type", rename = "blockquote") 598 - )] 599 - pub struct BlockQuote { 577 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 578 + pub struct Blockquote { 600 579 // Parent. 601 580 /// Content model. 602 581 pub children: Vec<Node>, ··· 611 590 /// ^^^ 612 591 /// ``` 613 592 #[derive(Clone, Debug, Eq, PartialEq)] 614 - #[cfg_attr( 615 - feature = "serde", 616 - derive(serde::Serialize, serde::Deserialize), 617 - serde(tag = "type", rename = "list") 618 - )] 593 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 619 594 pub struct List { 620 595 // Parent. 621 596 /// Content model. ··· 640 615 /// ^^^ 641 616 /// ``` 642 617 #[derive(Clone, Debug, Eq, PartialEq)] 643 - #[cfg_attr( 644 - feature = "serde", 645 - derive(serde::Serialize, serde::Deserialize), 646 - serde(tag = "type", rename = "listItem") 647 - )] 618 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 648 619 pub struct ListItem { 649 620 // Parent. 650 621 /// Content model. ··· 667 638 /// ^^^ 668 639 /// ``` 669 640 #[derive(Clone, Debug, Eq, PartialEq)] 670 - #[cfg_attr( 671 - feature = "serde", 672 - derive(serde::Serialize, serde::Deserialize), 673 - serde(tag = "type", rename = "html") 674 - )] 641 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 675 642 pub struct Html { 676 643 // Text. 677 644 /// Content model. ··· 691 658 /// ^^^ 692 659 /// ``` 693 660 #[derive(Clone, Debug, Eq, PartialEq)] 694 - #[cfg_attr( 695 - feature = "serde", 696 - derive(serde::Serialize, serde::Deserialize), 697 - serde(tag = "type", rename = "code") 698 - )] 661 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 699 662 pub struct Code { 700 663 // Text. 701 664 /// Content model. ··· 720 683 /// ^^ 721 684 /// ``` 722 685 #[derive(Clone, Debug, Eq, PartialEq)] 723 - #[cfg_attr( 724 - feature = "serde", 725 - derive(serde::Serialize, serde::Deserialize), 726 - serde(tag = "type", rename = "math") 727 - )] 686 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 728 687 pub struct Math { 729 688 // Text. 730 689 /// Content model. ··· 743 702 /// ^^^^^^ 744 703 /// ``` 745 704 #[derive(Clone, Debug, Eq, PartialEq)] 746 - #[cfg_attr( 747 - feature = "serde", 748 - derive(serde::Serialize, serde::Deserialize), 749 - serde(tag = "type", rename = "definition") 750 - )] 705 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 751 706 pub struct Definition { 752 707 // Void. 753 708 /// Positional info. ··· 780 735 /// ^ 781 736 /// ``` 782 737 #[derive(Clone, Debug, Eq, PartialEq)] 783 - #[cfg_attr( 784 - feature = "serde", 785 - derive(serde::Serialize, serde::Deserialize), 786 - serde(tag = "type", rename = "text") 787 - )] 738 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 788 739 pub struct Text { 789 740 // Text. 790 741 /// Content model. ··· 800 751 /// ^^^ 801 752 /// ``` 802 753 #[derive(Clone, Debug, Eq, PartialEq)] 803 - #[cfg_attr( 804 - feature = "serde", 805 - derive(serde::Serialize, serde::Deserialize), 806 - serde(tag = "type", rename = "emphasis") 807 - )] 754 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 808 755 pub struct Emphasis { 809 756 // Parent. 810 757 /// Content model. ··· 820 767 /// ^^^^^ 821 768 /// ``` 822 769 #[derive(Clone, Debug, Eq, PartialEq)] 823 - #[cfg_attr( 824 - feature = "serde", 825 - derive(serde::Serialize, serde::Deserialize), 826 - serde(tag = "type", rename = "strong") 827 - )] 770 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 828 771 pub struct Strong { 829 772 // Parent. 830 773 /// Content model. ··· 840 783 /// ^^^ 841 784 /// ``` 842 785 #[derive(Clone, Debug, Eq, PartialEq)] 843 - #[cfg_attr( 844 - feature = "serde", 845 - derive(serde::Serialize, serde::Deserialize), 846 - serde(tag = "type", rename = "inlineCode") 847 - )] 786 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 848 787 pub struct InlineCode { 849 788 // Text. 850 789 /// Content model. ··· 860 799 /// ^^^ 861 800 /// ``` 862 801 #[derive(Clone, Debug, Eq, PartialEq)] 863 - #[cfg_attr( 864 - feature = "serde", 865 - derive(serde::Serialize, serde::Deserialize), 866 - serde(tag = "type", rename = "inlineMath") 867 - )] 802 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 868 803 pub struct InlineMath { 869 804 // Text. 870 805 /// Content model. ··· 881 816 /// | b 882 817 /// ``` 883 818 #[derive(Clone, Debug, Eq, PartialEq)] 884 - #[cfg_attr( 885 - feature = "serde", 886 - derive(serde::Serialize, serde::Deserialize), 887 - serde(tag = "type", rename = "break") 888 - )] 819 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 889 820 pub struct Break { 890 821 // Void. 891 822 /// Positional info. ··· 899 830 /// ^^^^^^ 900 831 /// ``` 901 832 #[derive(Clone, Debug, Eq, PartialEq)] 902 - #[cfg_attr( 903 - feature = "serde", 904 - derive(serde::Serialize, serde::Deserialize), 905 - serde(tag = "type", rename = "link") 906 - )] 833 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 907 834 pub struct Link { 908 835 // Parent. 909 836 /// Content model. ··· 925 852 /// ^^^^^^^ 926 853 /// ``` 927 854 #[derive(Clone, Debug, Eq, PartialEq)] 928 - #[cfg_attr( 929 - feature = "serde", 930 - derive(serde::Serialize, serde::Deserialize), 931 - serde(tag = "type", rename = "image") 932 - )] 855 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 933 856 pub struct Image { 934 857 // Void. 935 858 /// Positional info. ··· 953 876 /// ^^^ 954 877 /// ``` 955 878 #[derive(Clone, Debug, Eq, PartialEq)] 956 - #[cfg_attr( 957 - feature = "serde", 958 - derive(serde::Serialize, serde::Deserialize), 959 - serde(tag = "type", rename = "linkReference") 960 - )] 879 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 961 880 pub struct LinkReference { 962 881 // Parent. 963 882 /// Content model. ··· 990 909 /// ^^^^ 991 910 /// ``` 992 911 #[derive(Clone, Debug, Eq, PartialEq)] 993 - #[cfg_attr( 994 - feature = "serde", 995 - derive(serde::Serialize, serde::Deserialize), 996 - serde(tag = "type", rename = "imageReference") 997 - )] 912 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 998 913 pub struct ImageReference { 999 914 // Void. 1000 915 /// Positional info. ··· 1029 944 /// ^^^^^^^ 1030 945 /// ``` 1031 946 #[derive(Clone, Debug, Eq, PartialEq)] 1032 - #[cfg_attr( 1033 - feature = "serde", 1034 - derive(serde::Serialize, serde::Deserialize), 1035 - serde(tag = "type", rename = "footnoteDefinition") 1036 - )] 947 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1037 948 pub struct FootnoteDefinition { 1038 949 // Parent. 1039 950 /// Content model. ··· 1062 973 /// ^^^^ 1063 974 /// ``` 1064 975 #[derive(Clone, Debug, Eq, PartialEq)] 1065 - #[cfg_attr( 1066 - feature = "serde", 1067 - derive(serde::Serialize, serde::Deserialize), 1068 - serde(tag = "type", rename = "footnoteReference") 1069 - )] 976 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1070 977 pub struct FootnoteReference { 1071 978 // Void. 1072 979 /// Positional info. ··· 1095 1002 /// ^^^^^ 1096 1003 /// ``` 1097 1004 #[derive(Clone, Debug, Eq, PartialEq)] 1098 - #[cfg_attr( 1099 - feature = "serde", 1100 - derive(serde::Serialize, serde::Deserialize), 1101 - serde(tag = "type", rename = "table") 1102 - )] 1005 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1103 1006 pub struct Table { 1104 1007 // Parent. 1105 1008 /// Content model. ··· 1118 1021 /// ^^^^^ 1119 1022 /// ``` 1120 1023 #[derive(Clone, Debug, Eq, PartialEq)] 1121 - #[cfg_attr( 1122 - feature = "serde", 1123 - derive(serde::Serialize, serde::Deserialize), 1124 - serde(tag = "type", rename = "tableRow") 1125 - )] 1024 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1126 1025 pub struct TableRow { 1127 1026 // Parent. 1128 1027 /// Content model. ··· 1138 1037 /// ^^^^^ 1139 1038 /// ``` 1140 1039 #[derive(Clone, Debug, Eq, PartialEq)] 1141 - #[cfg_attr( 1142 - feature = "serde", 1143 - derive(serde::Serialize, serde::Deserialize), 1144 - serde(tag = "type", rename = "tableCell") 1145 - )] 1040 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1146 1041 pub struct TableCell { 1147 1042 // Parent. 1148 1043 /// Content model. ··· 1158 1053 /// ^^^^^ 1159 1054 /// ``` 1160 1055 #[derive(Clone, Debug, Eq, PartialEq)] 1161 - #[cfg_attr( 1162 - feature = "serde", 1163 - derive(serde::Serialize, serde::Deserialize), 1164 - serde(tag = "type", rename = "delete") 1165 - )] 1056 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1166 1057 pub struct Delete { 1167 1058 // Parent. 1168 1059 /// Content model. ··· 1182 1073 /// ^^^ 1183 1074 /// ``` 1184 1075 #[derive(Clone, Debug, Eq, PartialEq)] 1185 - #[cfg_attr( 1186 - feature = "serde", 1187 - derive(serde::Serialize, serde::Deserialize), 1188 - serde(tag = "type", rename = "yaml") 1189 - )] 1076 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1190 1077 pub struct Yaml { 1191 1078 // Void. 1192 1079 /// Content model. ··· 1206 1093 /// ^^^ 1207 1094 /// ``` 1208 1095 #[derive(Clone, Debug, Eq, PartialEq)] 1209 - #[cfg_attr( 1210 - feature = "serde", 1211 - derive(serde::Serialize, serde::Deserialize), 1212 - serde(tag = "type", rename = "toml") 1213 - )] 1096 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1214 1097 pub struct Toml { 1215 1098 // Void. 1216 1099 /// Content model. ··· 1226 1109 /// ^^^^^^^^^^^^^^^^^ 1227 1110 /// ``` 1228 1111 #[derive(Clone, Debug, Eq, PartialEq)] 1229 - #[cfg_attr( 1230 - feature = "serde", 1231 - derive(serde::Serialize, serde::Deserialize), 1232 - serde(tag = "type", rename = "mdxjsEsm") 1233 - )] 1112 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1234 1113 pub struct MdxjsEsm { 1235 1114 // Literal. 1236 1115 /// Content model. ··· 1249 1128 /// ^^^ 1250 1129 /// ``` 1251 1130 #[derive(Clone, Debug, Eq, PartialEq)] 1252 - #[cfg_attr( 1253 - feature = "serde", 1254 - derive(serde::Serialize, serde::Deserialize), 1255 - serde(tag = "type", rename = "mdxFlowExpression") 1256 - )] 1131 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1257 1132 pub struct MdxFlowExpression { 1258 1133 // Literal. 1259 1134 /// Content model. ··· 1272 1147 /// ^^^ 1273 1148 /// ``` 1274 1149 #[derive(Clone, Debug, Eq, PartialEq)] 1275 - #[cfg_attr( 1276 - feature = "serde", 1277 - derive(serde::Serialize, serde::Deserialize), 1278 - serde(tag = "type", rename = "mdxTextExpression") 1279 - )] 1150 + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 1280 1151 pub struct MdxTextExpression { 1281 1152 // Literal. 1282 1153 /// Content model. ··· 1298 1169 #[cfg_attr( 1299 1170 feature = "serde", 1300 1171 derive(serde::Serialize, serde::Deserialize), 1301 - serde(tag = "type", rename = "mdxJsxFlowElement") 1172 + serde(rename_all = "camelCase") 1302 1173 )] 1303 1174 pub struct MdxJsxFlowElement { 1304 1175 // Parent. ··· 1325 1196 #[cfg_attr( 1326 1197 feature = "serde", 1327 1198 derive(serde::Serialize, serde::Deserialize), 1328 - serde(tag = "type", rename = "mdxJsxTextElement") 1199 + serde(rename_all = "camelCase") 1329 1200 )] 1330 1201 pub struct MdxJsxTextElement { 1331 1202 // Parent. ··· 1841 1712 1842 1713 #[test] 1843 1714 fn block_quote() { 1844 - let mut node = Node::BlockQuote(BlockQuote { 1715 + let mut node = Node::Blockquote(Blockquote { 1845 1716 position: None, 1846 1717 children: vec![], 1847 1718 }); 1848 1719 1849 1720 assert_eq!( 1850 1721 format!("{:?}", node), 1851 - "BlockQuote { children: [], position: None }", 1722 + "Blockquote { children: [], position: None }", 1852 1723 "should support `Debug`" 1853 1724 ); 1854 1725 assert_eq!(node.to_string(), "", "should support `ToString`"); ··· 1863 1734 node.position_set(Some(Position::new(1, 1, 0, 1, 2, 1))); 1864 1735 assert_eq!( 1865 1736 format!("{:?}", node), 1866 - "BlockQuote { children: [], position: Some(1:1-1:2 (0-1)) }", 1737 + "Blockquote { children: [], position: Some(1:1-1:2 (0-1)) }", 1867 1738 "should support `position_set`" 1868 1739 ); 1869 1740 }
+2 -2
src/to_mdast.rs
··· 2 2 3 3 use crate::event::{Event, Kind, Name}; 4 4 use crate::mdast::{ 5 - AttributeContent, AttributeValue, AttributeValueExpression, BlockQuote, Break, Code, 5 + AttributeContent, AttributeValue, AttributeValueExpression, Blockquote, Break, Code, 6 6 Definition, Delete, Emphasis, FootnoteDefinition, FootnoteReference, Heading, Html, Image, 7 7 ImageReference, InlineCode, InlineMath, Link, LinkReference, List, ListItem, Math, 8 8 MdxFlowExpression, MdxJsxAttribute, MdxJsxFlowElement, MdxJsxTextElement, MdxTextExpression, ··· 470 470 471 471 /// Handle [`Enter`][Kind::Enter]:[`BlockQuote`][Name::BlockQuote]. 472 472 fn on_enter_block_quote(context: &mut CompileContext) { 473 - context.tail_push(Node::BlockQuote(BlockQuote { 473 + context.tail_push(Node::Blockquote(Blockquote { 474 474 children: vec![], 475 475 position: None, 476 476 }));
+2 -2
tests/block_quote.rs
··· 1 1 use markdown::{ 2 - mdast::{BlockQuote, Node, Paragraph, Root, Text}, 2 + mdast::{Blockquote, Node, Paragraph, Root, Text}, 3 3 message, to_html, to_html_with_options, to_mdast, 4 4 unist::Position, 5 5 Constructs, Options, ParseOptions, ··· 221 221 assert_eq!( 222 222 to_mdast("> a", &Default::default())?, 223 223 Node::Root(Root { 224 - children: vec![Node::BlockQuote(BlockQuote { 224 + children: vec![Node::Blockquote(Blockquote { 225 225 children: vec![Node::Paragraph(Paragraph { 226 226 children: vec![Node::Text(Text { 227 227 value: "a".into(),
+122
tests/serde.rs
··· 1 + use markdown::mdast::Node; 2 + use markdown::message::Message; 3 + 4 + #[allow(unused)] 5 + #[derive(Debug)] 6 + enum Error { 7 + Mdast(Message), 8 + Serde(serde_json::Error), 9 + } 10 + 11 + #[cfg_attr(feature = "serde", test)] 12 + fn serde() -> Result<(), Error> { 13 + let source = markdown::to_mdast( 14 + r#"--- 15 + title: Serde 16 + --- 17 + 18 + import Test from 'test'; 19 + import Inner from 'test'; 20 + import {Another, YetAnother} from 'another'; 21 + 22 + # <HelloMessage />, {username}! 23 + 24 + > Blockquote 25 + Add test constructs below! 26 + 27 + ## Test serialization and deserialization of mdast 28 + 29 + <Test id={id} name="test"> 30 + <Inner name="inner" id={id}> 31 + ## Inner 32 + [Link](./link.md) 33 + </Inner> 34 + </Test> 35 + 36 + <Another id={id} class="test" /> 37 + 38 + {test} this is text expression 39 + 40 + <YetAnother id={id} class="test" /> 41 + 42 + # Text 43 + 44 + ~~The world is flat.~~ We now know that the world is round. 45 + 46 + *Emphasis* 47 + 48 + *Strong Emphasis* 49 + 50 + $This is math$ 51 + 52 + Let's break\ 53 + yes! 54 + 55 + *** 56 + 57 + ## List 58 + 59 + * item1 60 + * item2 61 + * item3 62 + 63 + ## Code block 64 + 65 + ```shell 66 + cargo test --features json 67 + ``` 68 + 69 + ## Inline 70 + 71 + `Inline code` with backticks 72 + 73 + ## Image 74 + 75 + ![Image](http://url/a.png) 76 + 77 + ## Table 78 + 79 + | Syntax | Description | 80 + |-----------|-------------| 81 + | Header | Title | 82 + | Paragraph | Text | 83 + 84 + ## Task lists 85 + 86 + - [x] Write the press release 87 + - [ ] Update the website 88 + - [ ] Contact the media 89 + 90 + ## Footnotes 91 + 92 + Here's a simple footnote,[^1] and here's a longer one.[^bignote] 93 + 94 + [^1]: This is the first footnote. 95 + 96 + [^bignote]: Here's one with multiple paragraphs and code. 97 + 98 + Indent paragraphs to include them in the footnote. 99 + 100 + `{ my code }` 101 + 102 + Add as many paragraphs as you like. 103 + 104 + "#, 105 + &markdown::ParseOptions { 106 + constructs: markdown::Constructs { 107 + frontmatter: true, 108 + ..markdown::Constructs::mdx() 109 + }, 110 + ..markdown::ParseOptions::gfm() 111 + }, 112 + ) 113 + .map_err(Error::Mdast)?; 114 + 115 + let value: String = serde_json::to_string(&source).map_err(Error::Serde)?; 116 + 117 + let target: Node = serde_json::from_slice(value.as_bytes()).map_err(Error::Serde)?; 118 + 119 + pretty_assertions::assert_eq!(source, target); 120 + 121 + Ok(()) 122 + }