4 // "discount" markdown library is a C library and hence requires to be wrapped in
10 // utility functions for Biaweb that don't fit into any class and can be used by
15 std::string convert_to_markdown (std::string str) {
16 // discount is a C library and it doesn't work well with C++ streams
17 // and there seems no way to get the output of any of these functions
18 // into an std::string.
19 // the only option seems to be to write the output of the markdown()
20 // function to a temporary working file and then read it back into C++
21 // with the normal std::ifstream and feed it into the std::string
22 // till a cleaner solution can be found.
24 doc = mkd_string (str.c_str(), str.size(), 0);
25 FILE *f = fopen (".biaweb.tmp", "w");
28 std::ifstream ftmp (".biaweb.tmp");
29 std::string tmpl ( (std::istreambuf_iterator<char> (ftmp)),
30 (std::istreambuf_iterator<char> ())
34 remove (".biaweb.tmp");
38 // convert a document title to a file title - strip out the non-alpha
40 std::string convert_title (std::string title)
43 for (char c : title) {
47 output.append (1, '_');
52 // escape HTML special characters
53 std::string escape_html (std::string source)
55 std::string replace_buf;
56 replace_buf.reserve (source.size());
61 case '&' : replace_buf.append ("&"); break;
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 default : replace_buf.append (1, p);