73 if (boost::iends_with(fileName,
".h")
74 || boost::iends_with(fileName,
".C")
75 || boost::iends_with(fileName,
".cpp"))
77 else if (boost::iends_with(fileName,
".xml"))
79 else if (boost::iends_with(fileName,
".html"))
81 else if (boost::iends_with(fileName,
".java"))
83 else if (boost::iends_with(fileName,
".js"))
85 else if (boost::iends_with(fileName,
".css"))
93 std::size_t outputFileSize = (std::size_t)fs::file_size(fileName);
94 std::fstream file (fileName.c_str(), std::ios::in | std::ios::binary);
95 char* memblock =
new char [outputFileSize];
96 file.read(memblock, (std::streamsize)outputFileSize);
98 std::string data = std::string(memblock, outputFileSize);
107 auto result = std::make_unique<WText>();
108 result->setInline(
false);
117 if (cpp17::any_has_value(contentsData))
118 content = asString(contentsData).toUTF8();
120 std::string fileName =
121 asString(fileNameData).toUTF8();
123 std::string filePath;
124 if (cpp17::any_has_value(filePathData))
125 filePath = asString(filePathData).toUTF8();
131 if (content !=
"" && content.substr(0, 100).find(
"-*- C++ -*-")
132 != std::string::npos)
135 std::string outputFileName;
138 std::string inputFileName;
140 if (cpp17::any_has_value(filePathData))
141 inputFileName = filePath;
144 std::ofstream out(inputFileName.c_str(),
145 std::ios::out | std::ios::binary);
146 out.write(content.c_str(), (std::streamsize)content.length());
152 std::string sourceHighlightCommand =
"source-highlight ";
153 sourceHighlightCommand +=
"--src-lang=" + lang +
" ";
154 sourceHighlightCommand +=
"--out-format=xhtml ";
155 sourceHighlightCommand +=
"--input=" + inputFileName +
" ";
156 sourceHighlightCommand +=
"--output=" + outputFileName +
" ";
158 std::cerr << sourceHighlightCommand << std::endl;
159 bool sourceHighlightOk = system(sourceHighlightCommand.c_str()) == 0;
161 if (sourceHighlightOk)
167 unlink(outputFileName.c_str());
169 if (!cpp17::any_has_value(filePathData))
170 unlink(inputFileName.c_str());
176 if (!boost::iends_with(fileName,
".jar")
177 && !boost::iends_with(fileName,
".war")
178 && !boost::iends_with(fileName,
".class"))
181 std::unique_ptr<WWidget> result;
184 std::unique_ptr<WImage> image(std::make_unique<WImage>());
188 (
int)content.length());
190 result = std::move(image);
191 }
else if (lang !=
"") {
192 auto text = std::make_unique<WText>();
193 text->setTextFormat(TextFormat::UnsafeXHTML);
194 text->setText(content);
195 result = std::move(text);
197 auto text = std::make_unique<WText>();
198 text->setTextFormat(TextFormat::Plain);
199 text->setText(content);
200 result = std::move(text);
203 result->setInline(
false);
204 WApplication::instance()
205 ->doJavaScript(result->jsRef() +
".parentNode.scrollTop = 0;");