#include "website.h"
#include
");
}
else if (prev_code_type && !code_type) {
html.add("
");
}
if (new_table_mode != table_mode) {
if (table_mode == 0) {
html.add("");
}
}
}
if (header_level > 6)
html.add("#######");
header_level = 0;
}
}
if (code_type == 0) {
int prev_em = level_asterisks + level_underscores;
if (c == '*' && !was_esc && !is_list_asterisk) {
consq_asterisks++;
should_process = false;
}
else if (consq_asterisks) {
level_asterisks = level_asterisks ? 0 : consq_asterisks;
consq_asterisks = 0;
}
if (c == '_' && !was_esc) {
if ((prev >= '0' && prev <= '9') || (prev >= 'A' && prev <= 'Z') || (prev >= 'a' && prev <= 'z'))
ignore_underscores = !level_underscores;
if (!ignore_underscores) {
consq_underscores++;
should_process = false;
}
}
else {
if (consq_underscores) {
level_underscores = level_underscores ? 0 : consq_underscores;
consq_underscores = 0;
}
ignore_underscores = false;
}
int diff_em = (level_asterisks + level_underscores) - prev_em;
if (diff_em < -2) diff_em = -2;
if (diff_em > 2) diff_em = 2;
const char *em_tags[] = { "", "", "", "", "" };
html.add(em_tags[diff_em + 2]);
if (c == '~' && !was_esc) {
consq_tildes++;
should_process = false;
}
else {
if (consq_tildes == 2) {
is_strikethrough = !is_strikethrough;
html.add(is_strikethrough ? "" : "");
}
consq_tildes = 0;
}
if (c == '|' && table_mode) {
if (table_col_idx)
html.add("
");
code_type = 1;
}
consq_backticks = 0;
}
if (code_type != 0) {
should_process = false;
if (c != '`' && !(prev_backticks > 0 && c == '\n')) {
for (int j = 0; j < consq_backticks; j++)
html.add("`");
if (NEEDS_ESCAPE(c))
write_escaped_byte(c, chbuf);
html.add(chbuf);
}
}
else if (!was_esc) {
if (c == '!' || c == '?' || c == '$') {
if (i < in_sz-1 && input[i+1] == '[')
should_process = false;
}
else if (c == '[') {
should_process = false;
if (prev == '!')
html.add(" link)
html.add_and_escape(&input[link], link_end - link);
}
if (link <= alt) {
html.add("\">");
if (prev != '!' && prev != '?' && prev != '$')
html.add_and_escape(&input[link], link_end - link);
}
else if (prev == '$') {
if (alt_end > alt) {
html.add("\" data-params=\"");
html.add_and_escape(&input[alt], alt_end - alt);
}
html.add("\">");
}
else if (prev == '?') {
if (input[alt] == '=' && alt_end - alt > 1) {
html.add("class=\"");
alt++;
}
else if (alt_contains_colon) {
html.add("style=\"");
}
html.add_and_escape(&input[alt], alt_end - alt);
html.add("\">");
html.add_and_escape(&input[link], link_end - link);
}
else {
if (prev == '!')
html.add("\" alt=\"");
else
html.add("\">");
if (alt_end > alt) {
html.add_and_escape(&input[alt], alt_end - alt);
}
if (prev == '!') {
if (input[alt] == '=' && alt_end - alt > 1) {
html.add("\" class=\"");
alt++;
html.add_and_escape(&input[alt], alt_end - alt);
}
else if (alt_contains_colon) {
html.add("\" style=\"");
html.add_and_escape(&input[alt], alt_end - alt);
}
html.add("\">");
}
}
if (prev == '$') {
html.add("");
uses_canvas_js = true;
}
else if (prev == '?') {
html.add("");
}
else if (prev != '!') {
html.add(md_params.disable_anchors ? "" : "");
}
i = j;
}
}
if (should_process) {
bool should_add_c = true;
if (!was_esc) {
should_add_c = c != '\\' && c != '\n';
}
if (should_add_c) {
if (NEEDS_ESCAPE(c))
write_escaped_byte(c, chbuf);
html.add(chbuf);
}
}
if (c == '\n') {
if (header_level > 0) {
while (tag_cursor > 0) {
int tag = tag_levels[tag_cursor];
const char *tag_str = closing_tag_strings[tag];
tag_cursor--;
bool is_block = code_level || quote_level;
html.add(tag_str, strlen(tag_str) - is_block);
if (tag >= 1 && tag <= 6)
break;
}
}
if (header_level == 1 && !title.size) {
title.size = i - title.offset;
}
else if (header_level == 2 && md_params.created_time) {
struct tm *date = localtime(&md_params.created_time);
int day_kind = 0;
int day_mod10 = date->tm_mday % 10;
if (day_mod10 < 4 && (date->tm_mday < 4 || date->tm_mday > 20))
day_kind = day_mod10;
const char *kinds[] = {"th", "st", "nd", "rd"};
char datebuf[128];
String date_str(datebuf, 128);
date_str.reformat(
"{d}{s} {s}, {d}",
date->tm_mday, kinds[day_kind], months[date->tm_mon], 1900 + date->tm_year
);
html.add(datebuf);
md_params.created_time = 0;
}
if (table_mode) {
while (tag_cursor > 0) {
int tag = tag_levels[tag_cursor];
const char *tag_str = closing_tag_strings[tag];
tag_cursor--;
if (tag == TAG_TR) {
html.add("
Editor
" "" "Preview
" "