diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 3949ddd53..75e6979b3 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -975,6 +975,31 @@ static struct dom_stack_context_info dom_rss_renderer_context_info = { }; +static void +get_doctype(struct dom_renderer *renderer, struct cache_entry *cached) +{ + if (!strcasecmp("application/rss+xml", cached->content_type)) { + renderer->doctype = SGML_DOCTYPE_RSS; + + } else if (!strcasecmp("application/docbook+xml", + cached->content_type)) { + renderer->doctype = SGML_DOCTYPE_DOCBOOK; + + } else if (!strcasecmp("application/xbel+xml", cached->content_type) + || !strcasecmp("application/x-xbel", cached->content_type) + || !strcasecmp("application/xbel", cached->content_type)) { + renderer->doctype = SGML_DOCTYPE_XBEL; + + } else { + assertm(!strcasecmp("text/html", cached->content_type) + || !strcasecmp("application/xhtml+xml", + cached->content_type), + "Couldn't resolve doctype '%s'", cached->content_type); + + renderer->doctype = SGML_DOCTYPE_HTML; + } +} + /* Shared multiplexor between renderers */ void render_dom_document(struct cache_entry *cached, struct document *document, @@ -1005,28 +1030,10 @@ render_dom_document(struct cache_entry *cached, struct document *document, else parser_type = SGML_PARSER_TREE; - /* FIXME: Refactor the doctype lookup. */ - if (!strcasecmp("application/rss+xml", cached->content_type)) { - renderer.doctype = SGML_DOCTYPE_RSS; - - } else if (!strcasecmp("application/docbook+xml", cached->content_type)) { - renderer.doctype = SGML_DOCTYPE_DOCBOOK; - - } else if (!strcasecmp("application/xbel+xml", cached->content_type) - || !strcasecmp("application/x-xbel", cached->content_type) - || !strcasecmp("application/xbel", cached->content_type)) { - renderer.doctype = SGML_DOCTYPE_XBEL; - - } else { - assertm(!strcasecmp("text/html", cached->content_type) - || !strcasecmp("application/xhtml+xml", cached->content_type), - "Couldn't resolve doctype '%s'", cached->content_type); - - renderer.doctype = SGML_DOCTYPE_HTML; - } + get_doctype(&renderer, cached); parser = init_sgml_parser(parser_type, renderer.doctype, &uri, 0); - if (!parser) return; + if (!parser) return; if (document->options.plain) { add_dom_stack_context(&parser->stack, &renderer,