diff --git a/.gitignore b/.gitignore index d6fdae5..e8f8b67 100644 --- a/.gitignore +++ b/.gitignore @@ -193,4 +193,5 @@ $RECYCLE.BIN/ !.yarn/versions *.node -.vscode \ No newline at end of file +.vscode +.idea \ No newline at end of file diff --git a/__test__/__snapshots__/index.spec.ts.snap b/__test__/__snapshots__/index.spec.ts.snap index 7aed824..3d18846 100644 --- a/__test__/__snapshots__/index.spec.ts.snap +++ b/__test__/__snapshots__/index.spec.ts.snap @@ -438,6 +438,12 @@ exports[`compile > should render container type correctly 1`] = `
This is a block
of type danger
This is a block
of type details
+ Helpful advice for doing things better or more easily. +
+Use dummy
instead of demo
Use this code:-
+console.log(69);
+
+ This is a block
of type details
[!TIP] this is a tip
+ let (self_container_type, remaining_data) = + parse_github_alerts_container_meta(&text.value); + if !is_valid_container_type(&self_container_type) { + index += 1; + continue; + } + // in this case, container_type as container_title + container_type = self_container_type.clone(); + container_title = self_container_type.clone(); + container_title.make_ascii_uppercase(); + + container_content_start = true; + container_content_start_index = index; + + // reform paragraph tag + let mut paragraph_children = first_element.children.clone(); + if !remaining_data.is_empty() { + paragraph_children[0] = hast::Node::Text(hast::Text { + value: remaining_data, + position: None, + }) + } else { + paragraph_children.remove(0); + } + // reform blockquote tag + let mut children = element.children.clone(); + + if paragraph_children.is_empty() { + children.remove(1); + } else { + children[1] = + wrap_node_with_paragraph(&element.properties.clone(), ¶graph_children) + } + + container_content = children; + + container_content_end = true; + container_content_end_index = index; + } + } } } } @@ -247,17 +367,22 @@ fn traverse_children(root: &mut hast::Root) { } pub fn mdx_plugin_container(root: &mut hast::Node) { - // Traverse children, get all p tags, check if they start with ::: + // 1. Traverse children, get all p tags, check if they start with ::: // If it is, it is regarded as container syntax, and the content from the beginning of ::: to the end of a certain ::: is regarded as a container - // The element of this container is a div element, className is "rspress-container" + // 2. Traverse children, get all blockquote tags, check if they next child's first element is p tags and if start with [! and end of ] + // If it is, it is regarded as container syntax, and the content from the beginning of blockquote to the end of a certain blockquote is regarded as a container + // The element of this container is a div element, className is "rspress-directive" // for example: // :::tip // this is a tip // ::: + // or + // > [!tip] + // > this is a tip // Will be transformed to: - //This is a tip
//