|
PLearn 0.1
|
#include <HTMLUtils.h>
Static Public Member Functions | |
| static string | quote (string s) |
| static string | highlight_known_classes (string typestr) |
| static string | format_free_text (string text) |
| static string | make_http_hyperlinks (string text) |
| static string | generated_by () |
| static string | quote_format_and_highlight (string s) |
Definition at line 51 of file HTMLUtils.h.
| string PLearn::HTMLUtils::format_free_text | ( | string | text | ) | [static] |
Definition at line 90 of file HTMLUtils.cc.
References PLearn::removeblanks().
{
// sort of DWIM HTML formatting for free-text; cannot use split since it
// eats up consecutive delimiters
text = removeblanks(text);
size_t curpos = 0, curnl = text.find('\n');
bool ul_active = false;
bool start_paragraph = false;
string finallines;
#ifndef __INTEL_COMPILER
for ( ; curpos != string::npos ;
curpos = curnl+(curnl!=string::npos), curnl = text.find('\n', curpos) ) {
string curline = text.substr(curpos, curnl-curpos);
// step 1: check if the line starts with a '-': if so, start a new <UL>
// if not in one, or extend one if so
if (removeblanks(curline).substr(0,1) == "-" ||
removeblanks(curline).substr(0,1) == "*" )
{
curline = removeblanks(curline).substr(1);
if (! ul_active)
curline = "<ul><li>" + curline;
else
curline = "<li>" + curline;
start_paragraph = false;
ul_active = true;
}
// otherwise, a line that starts with some whitespace within a list
// just extends the previous <li> :: don't touch it
else if (ul_active && (curline == "" ||
curline.substr(0,1) == " " ||
curline.substr(0,1) == "\t")) {
/* do nothing */
}
// otherwise, normal processing
else {
// any line that is empty or starts with some whitespace gets its own <br>
if (removeblanks(curline) == "") {
// Don't start new paragraph right away; wait until we
// encounter some text that's neither a <ul> or a <pre>
start_paragraph = true;
curline = "";
}
else if (curline[0] == ' ' || curline[0] == '\t') {
start_paragraph = false;
curline = "<pre>" + curline + "</pre>";
}
// if we were processing a list, close it first
if (ul_active) {
curline = "</ul>" + curline;
ul_active = 0;
}
}
if (!curline.empty() && start_paragraph) {
finallines += "<p>";
start_paragraph = false;
}
finallines += curline + "\n";
}
// Close any pending open blocks
if (ul_active)
finallines += "</ul>\n";
// Finally join the lines
#endif
return make_http_hyperlinks(finallines);
}

| string PLearn::HTMLUtils::generated_by | ( | ) | [static] |
Definition at line 191 of file HTMLUtils.cc.
References PLearn::version_string().
Referenced by PLearn::HelpSystem::helpEpilogueHTML().
{
time_t curtime = time(NULL);
struct tm *broken_down_time = localtime(&curtime);
const int SIZE = 100;
char time_buffer[SIZE];
strftime(time_buffer,SIZE,"%Y/%m/%d %H:%M:%S",broken_down_time);
return string("<p> </p><address>Generated on " ) +
time_buffer + " by " + version_string() + "</address>";
}


| string PLearn::HTMLUtils::highlight_known_classes | ( | string | typestr | ) | [static] |
Definition at line 66 of file HTMLUtils.cc.
References PLearn::OptionBase::getCurrentOptionLevel(), PLearn::TypeFactory::getTypeMap(), i, PLearn::TypeFactory::instance(), n, PLearn::split(), and PLearn::tostring().
Referenced by PLearn::HelpSystem::helpOnOptionHTML().
{
#ifndef __INTEL_COMPILER
vector<string> tokens = split(typestr, " \t\n\r<>,.';:\"");
set<string> replaced; // Carry out replacements for a given token only once
const TypeMap& type_map = TypeFactory::instance().getTypeMap();
vector<string>::size_type n=tokens.size();
for (unsigned int i=0; i<n ; ++i) {
TypeMap::const_iterator it = type_map.find(tokens[i]);
if (it != type_map.end() && replaced.find(tokens[i]) == replaced.end()) {
replaced.insert(tokens[i]);
// ensure we only match whole words with the regular expression
const boost::regex e("\\<" + tokens[i] + "\\>");
const string repl_str("<a href=\"class_$&.html\\?level="
+ tostring(OptionBase::getCurrentOptionLevel())
+"\">$&</a>");
typestr = regex_replace(typestr, e, repl_str, boost::match_default | boost::format_default);
}
}
#endif
return typestr;
}


| string PLearn::HTMLUtils::make_http_hyperlinks | ( | string | text | ) | [static] |
Definition at line 164 of file HTMLUtils.cc.
References PLearn::OptionBase::getCurrentOptionLevel(), PLearn::join(), and PLearn::tostring().
{
#ifndef __INTEL_COMPILER
// Find elements of the form XYZ://x.y.z/a/b/c and make them into
// hyperlink. An issue is to determine when
static const char* recognized_protocols[] =
{ "http://", "https://", "ftp://", "mailto:" }; // for now...
static const vector<string> protocols_vector(
recognized_protocols,
recognized_protocols + sizeof(recognized_protocols) / sizeof(recognized_protocols[0]));
// Match everything that starts with the recognized protocol up to the
// following whitespace, excluding trailing punctuation if any.
// Make sure the URL is NOT enclosed in quotes
static const boost::regex e( string("(?!\")") + "(" +
"(?:" + join(protocols_vector, "|") + ")" +
"\\S+(?:\\w|/)" +
")" + "(?!\")" + "([[:punct:]]*\\s|$)");
const string repl_str("<a href=\"$1\?level="
+ tostring(OptionBase::getCurrentOptionLevel())
+"\">$1</a>$2");
text = regex_replace(text, e, repl_str, boost::match_default | boost::format_default);
#endif
return text;
}

| string PLearn::HTMLUtils::quote | ( | string | s | ) | [static] |
Definition at line 55 of file HTMLUtils.cc.
References PLearn::search_replace().
Referenced by PLearn::HelpSystem::helpOnClassHTML(), PLearn::HelpSystem::helpOnCommandHTML(), and PLearn::HelpSystem::helpOnOptionHTML().
{
#ifndef __INTEL_COMPILER
search_replace(s, "&", "&");
search_replace(s, "<", "<");
search_replace(s, ">", ">");
search_replace(s, "\"", """);
#endif
return s;
}


| static string PLearn::HTMLUtils::quote_format_and_highlight | ( | string | s | ) | [inline, static] |
Definition at line 58 of file HTMLUtils.h.
Referenced by PLearn::HelpSystem::helpClassesHTML(), PLearn::HelpSystem::helpClassParentsHTML(), PLearn::HelpSystem::helpDerivedClassesHTML(), PLearn::HelpSystem::helpOnClassHTML(), PLearn::HelpSystem::helpOnCommandHTML(), and PLearn::HelpSystem::helpOnOptionHTML().
{ return highlight_known_classes(format_free_text(quote(s))); }

1.7.4