#include "website.h" #define PROJECT_PREVIEW_LINE_LIMIT 20 static void render_code_article(String *html, const char *input, int in_sz) { html->add("
");
int start = 0;
bool was_spec = false;
char prev = 0;
for (int i = 0; i < in_sz; i++) {
char c = input[i];
if (c == '\n' || c == '\t') {
if (i > start) {
if (was_spec)
html->add(&input[start], i-start);
else
html->add_and_escape(&input[start], i-start);
start = i;
while (start < in_sz && (input[start] == '\n' || input[start] == '\t'))
start++;
}
if (c == '\n') {
if (prev == '\n') html->add_and_escape(&c, 1);
html->add("
");
}
else if (c == '\t') {
html->add(" ");
}
}
else if (NEEDS_ESCAPE(c)) {
if (!was_spec && i > start) {
html->add(&input[start], i-start);
start = i;
}
was_spec = true;
}
else {
if (was_spec && i > start) {
html->add_and_escape(&input[start], i-start);
start = i;
}
was_spec = false;
}
prev = c;
}
if (start < in_sz) {
if (was_spec)
html->add_and_escape(&input[start], in_sz-start);
else
html->add(&input[start], in_sz-start);
}
html->add("