Skip to content

Commit

Permalink
Separate paragraphs with a blank link in help descriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bredelings committed Dec 31, 2024
1 parent 913f257 commit d4f5963
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
51 changes: 28 additions & 23 deletions src/bali-phy/help.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -270,7 +292,12 @@ string get_help_for_rule(const Rule& rule)
if (auto description = rule.get_optional<string>("description"))
{
help<<header("Description");
help<<indent_and_wrap(3, terminal_width(), *description)<<std::endl<<std::endl;
auto text = indent_and_wrap_pars(3, terminal_width(), *description);
// text = do_quotes(text);
// text = do_double_emph(text);
// text = do_single_emph(text);
// text = do_unescape(text);
help<<text<<std::endl<<std::endl;
}

if (auto examples = rule.get_child_optional("examples"))
Expand Down Expand Up @@ -303,28 +330,6 @@ string get_help_for_rule(const Rule& rule)
return help.str();
}

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 pseudo_markdown(const string& text)
{
std::ostringstream marked;
Expand Down
3 changes: 3 additions & 0 deletions src/util/include/util/text.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ std::vector<std::string> 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);
Expand Down
28 changes: 27 additions & 1 deletion src/util/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ vector<string> 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);

Expand Down Expand Up @@ -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<string> 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);
Expand Down

0 comments on commit d4f5963

Please sign in to comment.