Skip to main content

faker_rust/default/
markdown.rs

1//! Markdown generator - generates markdown-formatted text
2
3use crate::config::FakerConfig;
4
5/// Generate a random markdown header
6pub fn headers() -> String {
7    let config = FakerConfig::current();
8    let level = config.rand_range(1, 7);
9    let prefix = "#".repeat(level as usize);
10    format!("{} Header", prefix)
11}
12
13/// Generate a random markdown emphasis
14pub fn emphasis() -> String {
15    let emphasis_types = vec![
16        "*italic*",
17        "**bold**",
18        "***bold italic***",
19        "~~strikethrough~~",
20        "`code`",
21    ];
22    crate::base::sample(&emphasis_types).to_string()
23}
24
25/// Generate a random markdown table row
26pub fn table_row() -> String {
27    "| Cell 1 | Cell 2 | Cell 3 |".to_string()
28}
29
30/// Generate a random inline code
31pub fn inline_code() -> String {
32    let code_snippets = vec![
33        "`foo()`", "`bar = 1`", "`println!`", "`cargo build`", "`git commit`",
34    ];
35    crate::base::sample(&code_snippets).to_string()
36}
37
38/// Generate a random block code
39pub fn block_code() -> String {
40    "```rust\nfn main() {\n    println!(\"Hello, world!\");\n}\n```".to_string()
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_headers() {
49        assert!(!headers().is_empty());
50    }
51
52    #[test]
53    fn test_emphasis() {
54        assert!(!emphasis().is_empty());
55    }
56
57    #[test]
58    fn test_table_row() {
59        assert!(!table_row().is_empty());
60    }
61
62    #[test]
63    fn test_inline_code() {
64        assert!(!inline_code().is_empty());
65    }
66
67    #[test]
68    fn test_block_code() {
69        assert!(!block_code().is_empty());
70    }
71}