diff --git a/main.cpp b/main.cpp index 2c0a815..534109d 100644 --- a/main.cpp +++ b/main.cpp @@ -80,13 +80,13 @@ string32 parsePage(string32 pageContents) { string32 searchString = "{% "; int tofind (searchString.cs.size()); - int i (0); - while (i < page.len()) { + int index (0); + while (index < page.len()) { int havematched = 0; - for (;i split = string32(page, si+3, ei+1).split(" "); - page.cs.erase(page.cs.begin()+si, page.cs.begin()+ei+4); + std::vector split = string32(page, startIndex+tofind, endIndex+1).split(" "); + page.cs.erase(page.cs.begin()+startIndex, page.cs.begin()+endIndex+tofind+1); if (split[0] == "include") { string32 toInclude = readfile("source/_includes/" + std::string(split[1].asChar())); - page.cs.insert(page.cs.begin()+si, toInclude.cs.begin(), toInclude.cs.end()); + page.cs.insert(page.cs.begin()+startIndex, toInclude.cs.begin(), toInclude.cs.end()); } } return page; @@ -132,17 +132,48 @@ string32 parsePageMD(string32 mdContents) { std::vector sections = mdContents.split("\n\n"); for (string32 section : sections) { + char* asChar = section[0].toChar(); + char firstChar = *asChar; + delete asChar; + + string32 toAdd = ""; + if (section.substr(0, 3) == "---") { htmlContents += section + "\n\n"; continue; - } else if (section[0] == "#") { - htmlContents += "

" + section.substr(1) + "

"; + } else if (firstChar == '#') { + toAdd += "

" + section.substr(1) + "

"; + } else if (firstChar >= 0x30 && firstChar <= 0x39) { + // ToDo: Impement Numeric Lists + } else if (section.substr(0, 3) == "```") { + std::vector lines = section.split("\n"); + string32 language = lines[0].substr(3); + lines.erase(lines.begin()); + lines.pop_back(); + + // ToDo: Handle syntax highlighting. + + toAdd += ""; + for (auto line : lines) + toAdd += line + "
"; + toAdd += "
"; } else { - htmlContents += "

" + section + "

"; + toAdd += "

" + section + "

"; } - htmlContents.replaceAroundSelfAll("***", "** *"); - htmlContents.replaceAroundSelfAsymAll("**", "**", "", ""); - htmlContents.replaceAroundSelfAsymAll("*", "*", "", ""); + + // Single Code + toAdd.replaceAroundSelfAsymAll("`", "`", "", ""); + + // Underline + toAdd.replaceAroundSelfAsymAll("__", "__", "", ""); + + // Bold / Italic + toAdd.replaceAroundSelfAll("***", "** *"); // Bold and Italic + toAdd.replaceAroundSelfAsymAll("**", "**", "", ""); // Bold + toAdd.replaceAroundSelfAsymAll("*", "*", "", ""); // Italic + toAdd.replaceAroundSelfAsymAll("_", "_", "", ""); // Italic + + htmlContents += toAdd; } // Run it through normal pagePage @@ -157,6 +188,7 @@ int main() { for (const auto & file : fs::recursive_directory_iterator(path)) { if (file.path().stem().string()[0] == '_' || file.path().string()[7] == '_') continue; + if (file.is_regular_file()) { std::string ext = file.path().extension().string(); std::string writeExt = ext; @@ -165,11 +197,11 @@ int main() { if (writeExt == ".md") writeExt = ".html"; std::ofstream outfile("output" + path.substr(6, path.size() - ext.size() - 6) + writeExt); - if (ext == ".html") + if (ext == ".html") { outfile << parsePageHTML(readfile(file.path().c_str())); - else if (ext == ".md") + } else if (ext == ".md") { outfile << parsePageMD(readfile(file.path().c_str())); - else { + } else { char* data = read(file.path().c_str()); int length = *(int*)data; outfile.write(data+4, length);