diff --git a/src/bali-phy/help.cc b/src/bali-phy/help.cc index 3de6c298d..f8e19fa30 100644 --- a/src/bali-phy/help.cc +++ b/src/bali-phy/help.cc @@ -30,6 +30,28 @@ using po::variables_map; namespace fs = std::filesystem; +string do_quotes(const string& line) +{ + return std::regex_replace(line,std::regex("([^\\\\]|^)`([^`]*)`"),string("$1")+black(highlight_bg("$2")).c_str()); +} + +string do_double_emph(string line) +{ + line = std::regex_replace(line,std::regex("([^\\\\]|^)__([^_ ][^_]*)__"),string("$1")+bold("$2").c_str()); + return std::regex_replace(line,std::regex("([^\\\\]|^)\\*\\*([^* ][^*]*)\\*\\*"),string("$1")+bold("$2").c_str()); +} + +string do_single_emph(string line) +{ + line = std::regex_replace(line,std::regex("([^\\\\]|^)\\*([^* ][^*]*)\\*"),string("$1")+underline("$2").c_str()); + return std::regex_replace(line,std::regex("([^\\\\]|^)_([^_ ][^_]*)_"),string("$1")+underline("$2").c_str()); +} + +string do_unescape(const string& line) +{ + return std::regex_replace(line,std::regex("\\\\([`_*])"),"$1"); +} + string get_topic_from_string(const string& s) { string s2 = s; @@ -270,7 +292,12 @@ string get_help_for_rule(const Rule& rule) if (auto description = rule.get_optional("description")) { help< get_lines(const std::string& line); std::string indent_and_wrap(int indent_first_line, int indent_other_lines, int width, const std::string& text); std::string indent_and_wrap(int indent, int width, const std::string& text); +std::string indent_and_wrap_par(int indent, int width, const std::string& text); +std::string indent_and_wrap_pars(int indent, int width, const std::string& text); + std::string indent(int indent, const std::string& text); std::string bold(const std::string& line); diff --git a/src/util/text.cc b/src/util/text.cc index 00c74aac6..7d2d07a88 100644 --- a/src/util/text.cc +++ b/src/util/text.cc @@ -72,7 +72,7 @@ vector wrap_lines(const string& line, int width) if (line[loc] == ' ' or line[loc] == '\t') break; - // 3. If that doesn't work, split at the first space of tab past the edge of the page. + // 3. If that doesn't work, split at the first space or tab past the edge of the page. if (loc < pos) loc = line.find_first_of(" \t", pos + width); @@ -130,6 +130,32 @@ string indent_and_wrap(int indent, int width, const string& text) return join(lines,'\n'); } +string indent_and_wrap_par(int indent, int width, const string& text) +{ + if (text.empty()) return text; + + auto lines = wrap_lines(text, width - indent); + + for(auto& line: lines) + line = string(indent,' ') + line; + + return join(lines,'\n'); +} + +string indent_and_wrap_pars(int indent, int width, const string& text) +{ + if (text.empty()) return text; + + auto paragraphs = get_lines(text); + + vector paragraphs_out; + for(auto& paragraph: paragraphs) + if (not paragraph.empty()) + paragraphs_out.push_back( indent_and_wrap_par(indent, width, paragraph) ); + + return join(paragraphs_out,"\n\n"); +} + string indent(int indent, const string& text) { return indent_and_wrap(indent, 100000, text);