Skip to content

Commit

Permalink
Put ctil::horizontalBreakUpdate() back together again
Browse files Browse the repository at this point in the history
  • Loading branch information
rjwignar committed Oct 3, 2023
1 parent 9ff9a4b commit a36c6bd
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions ctil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,68 @@
#include "ctil.h"
namespace cdot
{
bool ctil::ends_with(std::string const & value, std::string const & ending)
bool ctil::ends_with(std::string const& value, std::string const& ending)
{
if (ending.size() > value.size()) return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}

void ctil::md_italics_content_update(std::string &input) {
void ctil::md_italics_content_update(std::string& input)
{
size_t found = input.find("*");

while (found != std::string::npos) {
while (found != std::string::npos)
{
size_t end = input.find("*", found + 1);

if (end != std::string::npos) {
std::string word_to_replace = "<i>" +input.substr(found + 1, end - found - 1) + "</i>";
if (end != std::string::npos)
{
std::string word_to_replace = "<i>" + input.substr(found + 1, end - found - 1) + "</i>";
input.replace(found, end - found + 1, word_to_replace);
found = input.find("*", end + 1);
} else {
}
else
{
break;
}
}

found = input.find("_");

while (found != std::string::npos) {
while (found != std::string::npos)
{
size_t end = input.find("_", found + 1);

if (end != std::string::npos) {
std::string word_to_replace = "<i>" +input.substr(found + 1, end - found - 1) + "</i>";
if (end != std::string::npos)
{
std::string word_to_replace = "<i>" + input.substr(found + 1, end - found - 1) + "</i>";
input.replace(found, end - found + 1, word_to_replace);
found = input.find("_", end + 1);
} else {
}
else
{
break;
}
}
}
void ctil::codeblockUpdate(std::string& input)
{
std::string codeBlockToken = "`";
size_t found = input.find(codeBlockToken);
void ctil::horizontalBreakUpdate(std::string& input)
{
std::string hBreak = "---";
std::string hBreakHTML = "<hr />";
// return string::npos or valid index
size_t found = input.find(hBreak);
size_t found = input.find(hBreak);
while (found != std::string::npos)
{
input.replace(found, hBreak.length(), hBreakHTML);

// check again for hBreak, return string::npos if not found
found = input.find(hBreak);
}
}
void ctil::codeblockUpdate(std::string& input)
{
std::string codeBlockToken = "`";
size_t found = input.find(codeBlockToken);

while (found != std::string::npos)
{
Expand Down Expand Up @@ -78,14 +95,6 @@ namespace cdot
else
break;
}
}
while (found != std::string::npos)
{
input.replace(found, hBreak.length(), hBreakHTML);

// check again for hBreak, return string::npos if not found
found = input.find(hBreak);
}
}
void ctil::generateHTML_txt(std::ifstream& infile, std::ofstream& outfile, std::string filename)
{
Expand Down Expand Up @@ -286,12 +295,12 @@ namespace cdot
horizontalBreakUpdate(bodyContent);
// generate HTML file
outfile << "<!doctype html>" << std::endl
<< "<html lang='en'>" << std::endl
<< "<head>" << std::endl
<< "<meta charset = 'utf-8'>" << std::endl
<< "<title>" << title << "</title>" << std::endl
<< "<meta name='viewport' content='width=device-width, initial-scale=1'>" << std::endl
<< "</head>" << std::endl;
<< "<html lang='en'>" << std::endl
<< "<head>" << std::endl
<< "<meta charset = 'utf-8'>" << std::endl
<< "<title>" << title << "</title>" << std::endl
<< "<meta name='viewport' content='width=device-width, initial-scale=1'>" << std::endl
<< "</head>" << std::endl;
if (titleParsed)
{
// check possible Italics content for title content
Expand All @@ -306,7 +315,7 @@ namespace cdot
outfile << "<body>" << std::endl;
outfile << bodyContent;
outfile << "</body> " << std::endl
<< "</html>" << std::endl;
<< "</html>" << std::endl;

}

Expand Down

0 comments on commit a36c6bd

Please sign in to comment.