1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright © 2024 PDF Composer (pdf_composer). All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
use Regex;
use Value;
use BTreeMap;
/// This function merges the YAML data from a `BTreeMap<String, Value>` into a given Markdown content string.
///
/// # Arguments
///
/// * `yaml_btreemap` - A `BTreeMap<String, Value>` containing the YAML data to be merged into the Markdown content.
/// * `markdown_content` - A string slice (`&str`) representing the Markdown content into which the YAML data should be merged.
///
/// # Returns
///
/// A `String` containing the Markdown content with the YAML data merged into it.
///
/// # Remarks
///
/// The function performs the following steps:
///
/// 1. Creates a new `BTreeMap<String, String>` called `new_btreemap` to store the string values from the `yaml_btreemap`.
/// 2. Iterates over the key-value pairs in `yaml_btreemap` and inserts the string values into `new_btreemap`.
/// 3. Defines a regular expression pattern (`r"\{\{(\w+)\}\}"`) to match placeholders in the Markdown content.
/// 4. Uses the `regex` crate's `replace_all` function to replace the placeholders in the Markdown content with the corresponding values from `new_btreemap`.
/// 5. If a matching value is found in `new_btreemap`, it replaces the placeholder with the value.
/// 6. If no matching value is found, it leaves the original placeholder unchanged.
/// 7. Returns the resulting string with the YAML data merged into the Markdown content.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeMap;
/// use serde_yml::Value;
///
/// // Define YAML data as a BTreeMap
/// let mut yaml_data = BTreeMap::new();
/// yaml_data.insert("name".to_string(), serde_yml::Value::String("Richard".to_string()));
/// yaml_data.insert("age".to_string(), serde_yml::Value::String("23".to_string()));
///
/// // Define Markdown content with placeholders
/// let markdown_content = "Name: {{name}}\nAge: {{age}}";
///
/// // Merge YAML data into Markdown content
/// let merged_content = merge_markdown_yaml(yaml_data, markdown_content);
///
/// // Check if merging was successful
/// assert_eq!(merged_content, "Name: Richard\nAge: 23");
/// ```