Skip to content

Commit

Permalink
demo: include_md handle table
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaozero committed Dec 30, 2023
1 parent 26603f2 commit eae027a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
13 changes: 13 additions & 0 deletions demo_markdown/docs/upload/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ view! {
```

### Upload Props

| Name | Type | Default | Description |
| -------------- | -------------------------------- | -------------------- | ------------------------------------ |
| accept | `MaybeSignal<String>` | `Default::default()` | The accept type of upload. |
| multiple | `MaybeSignal<bool>` | `false` | Allow multiple files to be selected. |
| custom_request | `Option<Callback<FileList, ()>>` | `Default::default()` | Customize upload request. |
| children | `Children` | | Upload's content. |

### UploadDragger Props

| Name | Type | Default | Description |
| -------- | ---------- | ------- | ------------------------ |
| children | `Children` | | UploadDragger's content. |
68 changes: 64 additions & 4 deletions demo_markdown/src/markdown/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,77 @@ fn iter_nodes<'a>(node: &'a AstNode<'a>, demos: &mut Vec<String>) -> TokenStream
}
NodeValue::ThematicBreak => quote!("ThematicBreak todo!!!"),
NodeValue::FootnoteDefinition(_) => quote!("FootnoteDefinition todo!!!"),
NodeValue::Table(_) => quote!("Table todo!!!"),
NodeValue::TableRow(_) => quote!("TableRow todo!!!"),
NodeValue::TableCell => quote!("TableCell todo!!!"),
NodeValue::Table(_) => {
let header_index = {
let mut header_index = 0;
for (index, c) in node.children().enumerate() {
let row = &c.data.borrow().value;
let is_header = match *row {
NodeValue::TableRow(header) => header,
_ => panic!(),
};
if !is_header {
header_index = index;
break;
}
}
header_index
};
let header_children: Vec<TokenStream> = children.drain(0..header_index).collect();

quote!(
<Table single_column=true>
<thead>
#(#header_children)*
</thead>
<tbody>
#(#children)*
</tbody>
</Table>
)
}
NodeValue::TableRow(_) => {
quote!(
<tr>
#(#children)*
</tr>
)
}
NodeValue::TableCell => {
let row = &node.parent().unwrap().data.borrow().value;
let is_header = match *row {
NodeValue::TableRow(header) => header,
_ => panic!(),
};
if is_header {
quote!(
<th>
#(#children)*
</th>
)
} else {
quote!(
<td>
#(#children)*
</td>
)
}
}
NodeValue::Text(text) => {
let text = text.clone();
quote!(#text)
}
NodeValue::TaskItem(_) => quote!("TaskItem todo!!!"),
NodeValue::SoftBreak => quote!("\n"),
NodeValue::LineBreak => quote!(<br />),
NodeValue::Code(_) => quote!("Code todo!!!"),
NodeValue::Code(node_code) => {
let code = node_code.literal.clone();
quote!(
<Text code=true>
#code
</Text>
)
}
NodeValue::HtmlInline(_) => quote!("HtmlInline todo!!!"),
NodeValue::Emph => quote!("Emph todo!!!"),
NodeValue::Strong => quote!("Strong todo!!!"),
Expand Down

0 comments on commit eae027a

Please sign in to comment.