diff --git a/src/classic.c b/src/classic.c index 553976b..2826c8a 100644 --- a/src/classic.c +++ b/src/classic.c @@ -49,7 +49,7 @@ void classic_stylesheet(FILE* out, const char* top) { fprintf(out, " padding: 8px;\n"); fprintf(out, "}\n"); fprintf(out, "\n"); - fprintf(out, "#content {\n"); + fprintf(out, "#content, #footer {\n"); fprintf(out, " padding: 8px;\n"); fprintf(out, "}\n"); fprintf(out, "\n"); @@ -298,11 +298,25 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body child = body->first_child; while(child != NULL) { - default_body(out, top, child, 6); + default_body(out, top, child, 0, 6); child = child->next; } + fprintf(out, " \n"); + fprintf(out, "
\n"); fprintf(out, " \n"); fprintf(out, " \n"); diff --git a/src/default.c b/src/default.c index 2750f85..618f43b 100644 --- a/src/default.c +++ b/src/default.c @@ -18,7 +18,7 @@ static void print(FILE* out, const char* txt, int indent) { } } -static void accept_attr(char* text, xl_node_t* element, ...) { +static void accept_attr(const char* top, char* text, int spec, xl_node_t* element, ...) { xl_attribute_t* attr = element->first_attribute; text[0] = 0; @@ -33,7 +33,17 @@ static void accept_attr(char* text, xl_node_t* element, ...) { if(attr->value == NULL) { sprintf(text + strlen(text), " %s", attr->key); } else { - sprintf(text + strlen(text), " %s=\"%s\"", attr->key, attr->value); + char* t; + + if(spec && (strcmp(attr->key, "href") == 0 || strcmp(attr->key, "src") == 0)) { + t = u_path(top, attr->value); + } else { + t = u_strdup(attr->value); + } + + sprintf(text + strlen(text), " %s=\"%s\"", attr->key, t); + + free(t); } } va_end(va); @@ -55,7 +65,7 @@ void default_head(FILE* out, const char* top, xl_node_t* element, int indent) { if(strcmp(element->name, "link") == 0) { char text[2048]; - accept_attr(text, element, "rel", "href", NULL); + accept_attr(top, text, 0, element, "rel", "href", NULL); sprintf(tag, "<%s%s>", element->name, text); } @@ -80,7 +90,7 @@ void default_head(FILE* out, const char* top, xl_node_t* element, int indent) { print(out, end, indent); } -void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { +void default_body(FILE* out, const char* top, xl_node_t* element, int spec, int indent) { xl_node_t* child; char tag[2048]; /* enough for most cases... :) */ char end[128]; @@ -104,7 +114,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { author[0] = 0; - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); if(strcmp(element->name, "fixme") == 0) { say = "Fixme"; @@ -153,27 +163,27 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { strcmp(element->name, "h4") == 0 || /**/ strcmp(element->name, "h5") == 0 || /**/ strcmp(element->name, "h6") == 0) { - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "%s>", element->name); } else if(strcmp(element->name, "ul") == 0 || /**/ strcmp(element->name, "ol") == 0) { - accept_attr(text, element, "id", "class", "spacing", NULL); + accept_attr(top, text, 0, element, "id", "class", "spacing", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "%s>", element->name); } else if(strcmp(element->name, "a") == 0) { - accept_attr(text, element, "id", "class", "href", "title", "rel", NULL); + accept_attr(top, text, 0, element, "id", "class", "href", "title", "rel", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "%s>", element->name); } else if(strcmp(element->name, "td") == 0 || /**/ strcmp(element->name, "th") == 0) { - accept_attr(text, element, "id", "class", "rowspan", "colspan", NULL); + accept_attr(top, text, 0, element, "id", "class", "rowspan", "colspan", NULL); sprintf(tag, "<%s%s>", element->name, text); @@ -184,7 +194,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { char* h; int ws, hs; - accept_attr(text, element, "src", "alt", "title", "height", "width", "id", "class", NULL); + accept_attr(top, text, 0, element, "src", "alt", "title", "height", "width", "id", "class", NULL); w = xl_get_attribute(element, "width"); h = xl_get_attribute(element, "height"); @@ -202,20 +212,20 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { sprintf(tag, "<%s%s border=\"0\">", element->name, text); } else if(strcmp(element->name, "script") == 0) { - accept_attr(text, element, "src", "type", NULL); + accept_attr(top, text, 0, element, "src", "type", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "%s>", element->name); } else if(strcmp(element->name, "table") == 0) { - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); sprintf(tag, "<%s%s class=\"grid\" width=\"100%%\" cellpadding=\"3\" cellspacing=\"2\" border=\"1\">", element->name, text); sprintf(end, "%s>", element->name); } else if(strcmp(element->name, "hr") == 0 || /**/ strcmp(element->name, "br") == 0) { - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); sprintf(tag, "<%s%text>", element->name, text); } @@ -225,7 +235,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { child = element->first_child; while(child != NULL) { if(child->type == XL_NODE_NODE && child->name != NULL) { - default_body(out, top, child, indent + 1 + add); + default_body(out, top, child, spec, indent + 1 + add); } else if(child->type == XL_NODE_TEXT && child->text != NULL) { print(out, child->text, indent + 1 + add); } diff --git a/src/seed.c b/src/seed.c index b681858..3119d49 100644 --- a/src/seed.c +++ b/src/seed.c @@ -54,6 +54,7 @@ int action_seed(int argc, char** argv) { fprintf(f, " NOTE!\n"); fprintf(f, " - Relative path in this config is relative to site/content\n"); fprintf(f, " - If relative path starts from ./ or ../, it's relative to URL when accessed\n"); + fprintf(f, " - This rule applies to footer's src/href too\n"); fprintf(f, "-->\n"); fprintf(f, "