-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdvanced.cpp
More file actions
114 lines (99 loc) · 4.28 KB
/
Advanced.cpp
File metadata and controls
114 lines (99 loc) · 4.28 KB
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
114
// This was generated by ShitHub Slopilot
#ifndef LIPSUM_BUILD_STATIC
# define LIPSUM_IMPLEMENTATION
#endif
#include "lipsum.hpp"
// A small helper to replace all occurrences of a token in a string.
static std::string
ReplaceAll(std::string s, const std::string& from, const std::string& to)
{
if (from.empty())
return s;
size_t pos = 0;
while ((pos = s.find(from, pos)) != std::string::npos)
{
s.replace(pos, from.length(), to);
pos += to.length();
}
return s;
}
int main()
{
std::cout << "THIS WAS GENERATED BY A CLANKER!!\n";
// Use the object-oriented generator and some free functions.
lpsm::Generator gen;
// Build a template Markdown document with tokens to fill.
std::string mdTemplate =
"# {TITLE}\n\n"
"## About\n\n"
"{ABOUT}\n\n"
"## Highlights\n\n"
"{HIGHLIGHTS}\n\n"
"## Quick Example\n\n"
"```cpp\n"
"// This is a tiny snippet; it's intentionally silly\n"
"auto awesome = \"{WORD}\";\n"
"std::cout << \"Behold: \" << awesome << std::endl;\n"
"```\n\n"
"## Related Link\n\n"
"{MDLINK}\n\n"
"## Gallery\n\n"
"{GALLERY}\n";
// Fill tokens using the library:
std::string title = gen.sentence_fragment(); // short title
// Capitalize first letter just in case
if (!title.empty())
title[0] = std::toupper(title[0]);
// About: a short Markdown paragraph (use Markdown generator to add some
// formatting)
std::string about = gen.md_paragraph(1, true); // starts with Lorem ipsum
// Highlights: a markdown list (unordered)
std::string highlights = lpsm::GenerateMarkdownList(false,
lpsm::ArgVec2(3, 6),
lpsm::ArgVec2(1, 2),
lpsm::ArgVec2(3, 5),
false);
// A single random word used in the code block
std::string word = lpsm::GenerateWord();
// A markdown link (uses example.com by default)
std::string mdLink = lpsm::GenerateMarkdownLink(lpsm::ArgVec2(3, 6),
lpsm::ArgVec2(1, 2),
lpsm::ArgVec2(2, 4),
false);
// Gallery: several short paragraphs
std::string gallery = lpsm::GenerateParagraphs(3,
lpsm::ArgVec2(4, 8),
lpsm::ArgVec2(1, 2),
lpsm::ArgVec2(2, 4),
false); // don't force Lorem
// as first paragraph
// Do a few playful replacements in the gallery to mimic captions
std::string caption =
std::string("> Caption: ") +
lpsm::GenerateSentence(lpsm::ArgVec2(2, 4), lpsm::ArgVec2(1, 1)) +
"\n\n";
gallery = caption + gallery;
// Now replace tokens in template
std::string md = mdTemplate;
md = ReplaceAll(md, "{TITLE}", title);
md = ReplaceAll(md, "{ABOUT}", about);
md = ReplaceAll(md, "{HIGHLIGHTS}", highlights);
md = ReplaceAll(md, "{WORD}", word);
md = ReplaceAll(md, "{MDLINK}", mdLink);
md = ReplaceAll(md, "{GALLERY}", gallery);
// Print the generated Markdown document
std::cout << "----- Generated Markdown -----\n\n";
std::cout << md << "\n";
// Show some simple statistics
int sentences = lpsm::CountSentences(md);
int words = lpsm::CountWords(md);
std::cout << "----- Stats -----\n";
std::cout << "Sentences (periods counted outside parentheses): "
<< sentences << "\n";
std::cout << "Words (simple whitespace split): " << words << "\n";
// Demonstrate HTMLify (deprecated) just to show it exists: wrap paragraphs
// into <p> tags.
// std::cout << "\n----- HTMLified (deprecated HTMLify) -----\n\n";
// std::cout << lpsm::HTMLify(md) << "\n";
return 0;
}