work on site abstract document system

This commit is contained in:
Allen Webster 2017-07-13 17:41:44 -04:00
parent 4c437ac138
commit 0ced4558ab
1 changed files with 86 additions and 24 deletions

View File

@ -41,7 +41,9 @@ enum{
Doc_Full_Elements, Doc_Full_Elements,
Doc_Table_Of_Contents, Doc_Table_Of_Contents,
Doc_Plain_Old_Text, Doc_Plain_Old_Text,
Doc_Version,
Doc_BeginStyle,
Doc_EndStyle,
// //
Doc_COUNT, Doc_COUNT,
}; };
@ -81,9 +83,9 @@ struct Document_Item{
} unit_elements; } unit_elements;
struct{ struct{
String text; String string;
} text; } string;
struct{ struct{
Enriched_Text *text; Enriched_Text *text;
} enriched_text; } enriched_text;
@ -438,9 +440,9 @@ add_plain_old_text(Abstract_Item *doc, String text){
Document_Item *item = fm_push_array(Document_Item, 1); Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item; *item = null_document_item;
item->type = Doc_Plain_Old_Text; item->type = Doc_Plain_Old_Text;
item->text.text = str_alloc(text.size); item->string.string = str_alloc(text.size);
copy(&item->text.text, text); copy(&item->string.string, text);
append_child(parent, item); append_child(parent, item);
} }
@ -456,6 +458,41 @@ add_enriched_text(Abstract_Item *doc, Enriched_Text *text){
append_child(parent, item); append_child(parent, item);
} }
internal void
add_version(Abstract_Item *doc){
Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_Version;
append_child(parent, item);
}
internal void
add_begin_style(Abstract_Item *doc, String text){
Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_BeginStyle;
item->string.string = str_alloc(text.size);
copy(&item->string.string, text);
append_child(parent, item);
}
internal void
add_end_style(Abstract_Item *doc){
Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
Document_Item *parent = doc->section_stack[doc->section_top];
Document_Item *item = fm_push_array(Document_Item, 1);
*item = null_document_item;
item->type = Doc_BeginStyle;
append_child(parent, item);
}
// HTML Document Generation // HTML Document Generation
#define HTML_BACK_COLOR "#FAFAFA" #define HTML_BACK_COLOR "#FAFAFA"
@ -714,6 +751,22 @@ output_plain_old_text(String *out, char *text, u32 length){
} }
} }
internal void
output_begin_style(String *out, char *name, u32 length){
String l = make_string(name, length);
if (match(l, "code")){
append(out, "<span style='"HTML_CODE_STYLE"'>");
}
else{
fprintf(stdout, "error: unrecognized style\n");
}
}
internal void
output_end_style(String *out){
append(out, "</span>");
}
internal void internal void
write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_system, Section_Counter *section_counter){ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_system, Section_Counter *section_counter){
String source = text->source; String source = text->source;
@ -733,7 +786,7 @@ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_
char ch = l.str[i]; char ch = l.str[i];
if (ch == '\\'){ if (ch == '\\'){
output_plain_old_text(out, l.str + start, i - start); output_plain_old_text(out, l.str + start, i - start);
i32 command_start = i + 1; i32 command_start = i + 1;
i32 command_end = command_start; i32 command_end = command_start;
for (; command_end < l.size; ++command_end){ for (; command_end < l.size; ++command_end){
@ -759,15 +812,15 @@ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_
if (!string_set_match(enriched_commands, enriched_commands_count, command_string, &match_index)){ if (!string_set_match(enriched_commands, enriched_commands_count, command_string, &match_index)){
match_index = -1; match_index = -1;
} }
switch (match_index){ switch (match_index){
case Cmd_BackSlash: append(out, "\\"); break; case Cmd_BackSlash: append(out, "\\"); break;
case Cmd_DoMetaParse: case Cmd_DoMetaParse:
{ {
fprintf(stdout, "Cmd_DoMetaParse: not implemented\n"); fprintf(stdout, "Cmd_DoMetaParse: not implemented\n");
}break; }break;
case Cmd_Version: append(out, VERSION); break; case Cmd_Version: append(out, VERSION); break;
case Cmd_BeginStyle: case Cmd_BeginStyle:
@ -775,16 +828,13 @@ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_
String body_text = {0}; String body_text = {0};
b32 has_body = extract_command_body(out, l, &i, &body_text, command_string, true); b32 has_body = extract_command_body(out, l, &i, &body_text, command_string, true);
if (has_body){ if (has_body){
if (match_sc(body_text, "code")){ output_begin_style(out, body_text.str, body_text.size);
append(out, "<span style='"HTML_CODE_STYLE"'>");
}
} }
}break; }break;
case Cmd_EndStyle: case Cmd_EndStyle:
{ {
append(out, "</span>"); output_end_style(out);
}break; }break;
// TODO(allen): upgrade this bs // TODO(allen): upgrade this bs
@ -920,7 +970,7 @@ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_
if (match_part_sc(body_text, "youtube:")){ if (match_part_sc(body_text, "youtube:")){
i32 pixel_width = HTML_WIDTH; i32 pixel_width = HTML_WIDTH;
i32 pixel_height = (i32)(pixel_width * 0.5625); i32 pixel_height = (i32)(pixel_width * 0.5625);
String youtube_str = substr_tail(body_text, sizeof("youtube:")-1); String youtube_str = substr_tail(body_text, sizeof("youtube:")-1);
append(out, "<iframe width='"); append(out, "<iframe width='");
@ -956,19 +1006,19 @@ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_
fprintf(stdout, "error: unmatched section end\n"); fprintf(stdout, "error: unmatched section end\n");
} }
}break; }break;
case Cmd_TableOfContents: case Cmd_TableOfContents:
{ {
fprintf(stdout, "Cmd_TableOfContents: not implemented\n"); fprintf(stdout, "Cmd_TableOfContents: not implemented\n");
}break; }break;
default: default:
{ {
append(out, "<span style='color:#F00'>! Doc generator error: unrecognized command !</span>"); append(out, "<span style='color:#F00'>! Doc generator error: unrecognized command !</span>");
fprintf(stdout, "error: unrecognized command %.*s\n", command_string.size, command_string.str); fprintf(stdout, "error: unrecognized command %.*s\n", command_string.size, command_string.str);
}break; }break;
} }
start = i; start = i;
} }
} }
@ -1685,8 +1735,8 @@ doc_item_html(String *out, Document_System *doc_system, Used_Links *used_links,
{ {
if (head){ if (head){
write_enriched_text_html(out, item->enriched_text write_enriched_text_html(out, item->enriched_text
.text, doc_system, section_counter); .text, doc_system, section_counter);
} }
}break; }break;
@ -1782,10 +1832,22 @@ doc_item_html(String *out, Document_System *doc_system, Used_Links *used_links,
append(out, "</ul>"); append(out, "</ul>");
} }
}break; }break;
case Doc_Plain_Old_Text: case Doc_Plain_Old_Text:
{ {
output_plain_old_text(out, item->text.text.str, item->text.text.size); output_plain_old_text(out, item->string.string.str, item->string.string.size);
}break;
case Doc_Version: append(out, VERSION); break;
case Doc_BeginStyle:
{
output_begin_style(out, item->string.string.str, item->string.string.size);
}break;
case Doc_EndStyle:
{
output_end_style(out);
}break; }break;
} }
} }