5 // "discount" markdown library is a C library and hence requires to be wrapped in
11 // utility functions for Biaweb that don't fit into any class and can be used by
16 std::string convert_to_markdown (std::string str) {
17 // discount is a C library and it doesn't work well with C++ streams
18 // and there seems no way to get the output of any of these functions
19 // into an std::string.
20 // the only option seems to be to write the output of the markdown()
21 // function to a temporary working file and then read it back into C++
22 // with the normal std::ifstream and feed it into the std::string
23 // till a cleaner solution can be found.
25 doc = mkd_string (str.c_str(), str.size(), 0);
26 FILE *f = fopen (".biaweb.tmp", "w");
29 std::ifstream ftmp (".biaweb.tmp");
30 std::string tmpl ( (std::istreambuf_iterator<char> (ftmp)),
31 (std::istreambuf_iterator<char> ())
35 remove (".biaweb.tmp");
39 // convert a document title to a file title - strip out the non-alpha
41 std::string convert_title (std::string title)
44 for (char c : title) {
48 output.append (1, '_');
53 // escape HTML special characters
54 std::string escape_html (std::string source)
56 std::string replace_buf;
57 replace_buf.reserve (source.size());
62 case '&' : replace_buf.append ("&"); break;
63 case '<' : replace_buf.append ("<"); break;
64 case '>' : replace_buf.append (">"); break;
65 case '\"': replace_buf.append ("""); break;
66 case '\'': replace_buf.append ("'"); break;
67 default : replace_buf.append (1, p);