*/
#include <iomanip>
+#include <map>
#include <set>
#include <sstream>
#include <string>
using namespace std;
-
namespace I2n
{
+// Forward declarations:
+bool handle_attr_href(string &link);
+
namespace
{
*/
typedef pair<string,bool> Token;
+/**
+* @brief AttributeHandler is the function pointer type used to map attributes
+* and their respective content handlers.
*/
+typedef bool (*AttributeHandler)(string &);
+
+// Normal tags that do not accept any attributes.
+const set<string> ALLOWED_NORMAL = boost::assign::list_of("h1")("h2")("h3")
+ ("h4")("h5")("h6")("p")("i")("ul")("li")("tr")("th")("td")("table");
+
+// Void tags, these may have the self-closing notation as suffix and do not
+// expect an end tag.
+const set<string> ALLOWED_VOID = boost::assign::list_of("br");
+
+// Tags that may accept attributes. This container also maps all accepted
+// ones to their function handler.
+// (Attributes are not obligatory.)
+const map<string, const map< string, AttributeHandler> > ALLOWED_WITH_ATTR
+ = boost::assign::map_list_of< string, const map<string, AttributeHandler> >
+ ("a", boost::assign::map_list_of
+ ("href", &handle_attr_href)
+ );
-const set<string> ALLOWED_TAGS = boost::assign::list_of("h1")("h2")("h3")("h4")
- ("h5")("h6")("a")("p")
- ("br")("i")("ul")("li")
- ("tr")("th")("td")
- ("table");
-const string AHREF = "<a href=";
const string REDIRECT_PREFIX = "/arnie?form=redirect&url=";
const string TARGET_BLANK = "target=\"_blank\"";
const pcrecpp::RE SAFE_URL("^(http(s?):\\/\\/)(([a-zA-Z0-9\\.\\-\\_]+(\\.[a-zA-"