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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Execute shell scripts embedded within text.
//!
//! # Example
//!
//! Let's say you have a blog page in HTML that you want to keep updated with
//! the total number of posts and links to all posts. Let's call that page
//! `archive.html`, as seen below.
//!
//! ```html
//! <!-- archive.html -->
//! <h1>My Blog Archive</h1>
//! <p>Contains !((ls pages/*.html | wc -l))! post(s).</p>
//! <ul>
//! !((
//! for PAGE in $(ls pages/*.html)
//! do
//! PAGENAME="$(basename $PAGE .html)"
//! echo "<li><a href=\"$PAGE\">${PAGENAME//'-'/' '}</a></li>"
//! done
//! ))!
//! </ul>
//! ```
//!
//! This file can be processed from the command line using this project's
//! binary:
//!
//! corre -i archive.html -o www/archive.html
//!
//! You can also use the `run_embedded_scripts(text, opening_tag, closing_tag)`
//! function provided by this project's library:
//!
//! ```rust
//! // Load `archive.html` into the `String` `input_text`
//! let output_text = corre::run_embedded_scripts(input_text, "!((", "))!")?;
//! // Save the `String` `output_text` to the file `www/archive.html`
//! ```
//!
//! Both will produce the modified text:
//!
//! ```html
//! <!-- www/archive.html -->
//! <h1>My Blog Archive</h1>
//! <p>Contains 3 post(s)</p>
//! <ul>
//! <li><a href="pages/Hydroelectric-Dams.html">Hydroelectric Dams</a></li>
//! <li><a href="pages/The-Finnish-Genitive-Case.html">The Finnish Genitive Case</a></li>
//! <li><a href="pages/Vultee-XP54-Swoose-Goose.html">Vultee XP54 Swoose Goose</a></li>
//! </ul>
//! ```
use Regex;
use ;
/// Intersperses the given string with backslashes and returns it.
/// Returns the regex pattern used to match shell commands that are between the
/// given opening and closing tags.
/// Executes the given script in the shell and returns the STDOUT.
/// Runs all scripts that are embedded within the given text. Scripts are
/// identified using the given opening and closing tags. Returns the original
/// text, in which the shell scripts have been replaced with their STDOUT.