|
1 | 1 | use comrak::arena_tree::Node as ComrakNode;
|
2 | 2 | use comrak::nodes::{
|
3 |
| - Ast as ComrakAst, AstNode as ComrakAstNode, ListDelimType, ListType, NodeCode, NodeCodeBlock, |
4 |
| - NodeDescriptionItem, NodeFootnoteDefinition, NodeFootnoteReference, NodeHeading, NodeHtmlBlock, |
5 |
| - NodeLink, NodeList, NodeMath, NodeMultilineBlockQuote, NodeShortCode, NodeTable, |
6 |
| - NodeValue as ComrakNodeValue, NodeWikiLink, TableAlignment, |
| 3 | + AlertType, Ast as ComrakAst, AstNode as ComrakAstNode, ListDelimType, ListType, NodeAlert, |
| 4 | + NodeCode, NodeCodeBlock, NodeDescriptionItem, NodeFootnoteDefinition, NodeFootnoteReference, |
| 5 | + NodeHeading, NodeHtmlBlock, NodeLink, NodeList, NodeMath, NodeMultilineBlockQuote, |
| 6 | + NodeShortCode, NodeTable, NodeValue as ComrakNodeValue, NodeWikiLink, TableAlignment, |
7 | 7 | };
|
8 | 8 | use magnus::RArray;
|
9 | 9 | use magnus::{function, method, scan_args, Module, Object, RHash, RModule, Symbol, Value};
|
@@ -473,6 +473,47 @@ impl CommonmarkerNode {
|
473 | 473 | ComrakNodeValue::WikiLink(NodeWikiLink { url })
|
474 | 474 | }
|
475 | 475 |
|
| 476 | + "alert" => { |
| 477 | + let kwargs = scan_args::get_kwargs::< |
| 478 | + _, |
| 479 | + (Symbol,), |
| 480 | + (Option<String>, Option<bool>, Option<usize>, Option<usize>), |
| 481 | + (), |
| 482 | + >( |
| 483 | + args.keywords, |
| 484 | + &["type"], |
| 485 | + &["title", "multiline", "fence_length", "fence_offset"], |
| 486 | + )?; |
| 487 | + |
| 488 | + let (alert_name,) = kwargs.required; |
| 489 | + let (title, multiline, fence_length, fence_offset) = kwargs.optional; |
| 490 | + |
| 491 | + let alert_type = match alert_name.to_string().as_str() { |
| 492 | + "note" => AlertType::Note, |
| 493 | + "tip" => AlertType::Tip, |
| 494 | + "important" => AlertType::Important, |
| 495 | + "warning" => AlertType::Warning, |
| 496 | + _ => { |
| 497 | + return Err(magnus::Error::new( |
| 498 | + magnus::exception::arg_error(), |
| 499 | + "alert type must be `note`, `tip`, `important`, or `warning`", |
| 500 | + )); |
| 501 | + } |
| 502 | + }; |
| 503 | + |
| 504 | + ComrakNodeValue::Alert(NodeAlert { |
| 505 | + alert_type, |
| 506 | + // Overridden title. If None, then use the default title. |
| 507 | + title, |
| 508 | + // Originated from a multiline blockquote. |
| 509 | + multiline: multiline.unwrap_or(false), |
| 510 | + // The length of the fence (multiline only). |
| 511 | + fence_length: fence_length.unwrap_or(0), |
| 512 | + // The indentation level of the fence marker (multiline only) |
| 513 | + fence_offset: fence_offset.unwrap_or(0), |
| 514 | + }) |
| 515 | + } |
| 516 | + |
476 | 517 | _ => panic!("unknown node type {}", node_type),
|
477 | 518 | };
|
478 | 519 |
|
@@ -565,6 +606,7 @@ impl CommonmarkerNode {
|
565 | 606 | ComrakNodeValue::Subscript => Symbol::new("subscript"),
|
566 | 607 | ComrakNodeValue::SpoileredText => Symbol::new("spoilered_text"),
|
567 | 608 | ComrakNodeValue::EscapedTag(_) => Symbol::new("escaped_tag"),
|
| 609 | + ComrakNodeValue::Alert(..) => Symbol::new("alert"), |
568 | 610 | }
|
569 | 611 | }
|
570 | 612 |
|
|
0 commit comments