Renders untrusted text as portable inline code without Markdown delimiter ambiguity.
(value: &str)
| 603 | |
| 604 | /// Renders untrusted text as portable inline code without Markdown delimiter ambiguity. |
| 605 | pub fn markdown_code(value: &str) -> String { |
| 606 | let delimiter = "`".repeat(value.split(|c| c != '`').map(str::len).max().unwrap_or(0) + 1); |
| 607 | let text: String = value |
| 608 | .chars() |
| 609 | .map(|c| { |
| 610 | if c.is_whitespace() { |
| 611 | ' ' |
| 612 | } else if c.is_control() { |
| 613 | '�' |
| 614 | } else { |
| 615 | c |
| 616 | } |
| 617 | }) |
| 618 | .collect(); |
| 619 | format!("{delimiter} {text} {delimiter}") |
| 620 | } |
| 621 | |
| 622 | /// Validates a bounded portable record identifier. |
| 623 | pub fn valid_id(kind: &str, value: &str) -> Result<()> { |