work on site abstract document system
parent
4c437ac138
commit
0ced4558ab
|
@ -41,7 +41,9 @@ enum{
|
|||
Doc_Full_Elements,
|
||||
Doc_Table_Of_Contents,
|
||||
Doc_Plain_Old_Text,
|
||||
|
||||
Doc_Version,
|
||||
Doc_BeginStyle,
|
||||
Doc_EndStyle,
|
||||
//
|
||||
Doc_COUNT,
|
||||
};
|
||||
|
@ -81,8 +83,8 @@ struct Document_Item{
|
|||
} unit_elements;
|
||||
|
||||
struct{
|
||||
String text;
|
||||
} text;
|
||||
String string;
|
||||
} string;
|
||||
|
||||
struct{
|
||||
Enriched_Text *text;
|
||||
|
@ -438,8 +440,8 @@ add_plain_old_text(Abstract_Item *doc, String text){
|
|||
Document_Item *item = fm_push_array(Document_Item, 1);
|
||||
*item = null_document_item;
|
||||
item->type = Doc_Plain_Old_Text;
|
||||
item->text.text = str_alloc(text.size);
|
||||
copy(&item->text.text, text);
|
||||
item->string.string = str_alloc(text.size);
|
||||
copy(&item->string.string, text);
|
||||
|
||||
append_child(parent, item);
|
||||
}
|
||||
|
@ -456,6 +458,41 @@ add_enriched_text(Abstract_Item *doc, Enriched_Text *text){
|
|||
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
|
||||
|
||||
#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
|
||||
write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_system, Section_Counter *section_counter){
|
||||
String source = text->source;
|
||||
|
@ -775,16 +828,13 @@ write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_
|
|||
String body_text = {0};
|
||||
b32 has_body = extract_command_body(out, l, &i, &body_text, command_string, true);
|
||||
if (has_body){
|
||||
if (match_sc(body_text, "code")){
|
||||
append(out, "<span style='"HTML_CODE_STYLE"'>");
|
||||
}
|
||||
output_begin_style(out, body_text.str, body_text.size);
|
||||
}
|
||||
}break;
|
||||
|
||||
case Cmd_EndStyle:
|
||||
{
|
||||
append(out, "</span>");
|
||||
|
||||
output_end_style(out);
|
||||
}break;
|
||||
|
||||
// TODO(allen): upgrade this bs
|
||||
|
@ -1785,7 +1835,19 @@ doc_item_html(String *out, Document_System *doc_system, Used_Links *used_links,
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue