From 021af4e87c68d6738cd1e82ae836ae33eb285358 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 1 Jan 2006 23:22:10 +0100 Subject: [PATCH] Although aware ELinks doesn't need another sgml/doctype here is DocBook It was created a long time ago so (I think) it deserves to survive. It maps .sgml files to applicatino/docbook+xml and uses the highlighter. --- src/document/dom/renderer.c | 4 + src/document/renderer.c | 1 + src/dom/sgml/Makefile | 2 +- src/dom/sgml/docbook/.vimrc | 2 + src/dom/sgml/docbook/Makefile | 6 ++ src/dom/sgml/docbook/docbook.c | 37 ++++++++ src/dom/sgml/docbook/docbook.h | 30 +++++++ src/dom/sgml/docbook/info.c | 87 +++++++++++++++++++ src/dom/sgml/sgml.c | 2 + src/dom/sgml/sgml.h | 1 + src/mime/backend/default.c | 1 + src/session/download.c | 3 +- test/docbook/elinks.1.sgml | 150 +++++++++++++++++++++++++++++++++ 13 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 src/dom/sgml/docbook/.vimrc create mode 100644 src/dom/sgml/docbook/Makefile create mode 100644 src/dom/sgml/docbook/docbook.c create mode 100644 src/dom/sgml/docbook/docbook.h create mode 100644 src/dom/sgml/docbook/info.c create mode 100644 test/docbook/elinks.1.sgml diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 120fb443..1da9786a 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -687,9 +687,13 @@ render_dom_document(struct cache_entry *cached, struct document *document, document->bgcolor = document->options.default_bg; + /* FIXME: Refactor the doctype lookup. */ if (!strcasecmp("application/rss+xml", cached->content_type)) { doctype = SGML_DOCTYPE_RSS; + } else if (!strcasecmp("application/docbook+xml", cached->content_type)) { + 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)) { diff --git a/src/document/renderer.c b/src/document/renderer.c index 7edbc957..6c3a1d81 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -243,6 +243,7 @@ render_encoded_document(struct cache_entry *cached, struct document *document) if (cached->content_type && (!strcasecmp("text/html", cached->content_type) || !strcasecmp("application/xhtml+xml", cached->content_type) + || !strcasecmp("application/docbook+xml", cached->content_type) || !strcasecmp("application/rss+xml", cached->content_type) || !strcasecmp("application/xbel+xml", cached->content_type) || !strcasecmp("application/x-xbel", cached->content_type) diff --git a/src/dom/sgml/Makefile b/src/dom/sgml/Makefile index a899f393..193145e9 100644 --- a/src/dom/sgml/Makefile +++ b/src/dom/sgml/Makefile @@ -1,7 +1,7 @@ top_builddir=../../.. include $(top_builddir)/Makefile.config -SUBDIRS = html rss xbel +SUBDIRS = docbook html rss xbel OBJS = sgml.o parser.o scanner.o include $(top_srcdir)/Makefile.lib diff --git a/src/dom/sgml/docbook/.vimrc b/src/dom/sgml/docbook/.vimrc new file mode 100644 index 00000000..18f65e47 --- /dev/null +++ b/src/dom/sgml/docbook/.vimrc @@ -0,0 +1,2 @@ +:set runtimepath+=. +:runtime ../../../.vimrc diff --git a/src/dom/sgml/docbook/Makefile b/src/dom/sgml/docbook/Makefile new file mode 100644 index 00000000..47d0992e --- /dev/null +++ b/src/dom/sgml/docbook/Makefile @@ -0,0 +1,6 @@ +top_builddir=../../../.. +include $(top_builddir)/Makefile.config + +OBJS = docbook.o + +include $(top_srcdir)/Makefile.lib diff --git a/src/dom/sgml/docbook/docbook.c b/src/dom/sgml/docbook/docbook.c new file mode 100644 index 00000000..d4b96bdc --- /dev/null +++ b/src/dom/sgml/docbook/docbook.c @@ -0,0 +1,37 @@ +/* SGML node handling */ +/* $Id: docbook.c,v 1.1.2.24 2004/02/29 02:47:30 jonas Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "elinks.h" + +#include "dom/sgml/docbook/docbook.h" +#include "dom/sgml/sgml.h" + + +#define DOCBOOK_(node, name, id) \ + SGML_NODE_INFO(DOCBOOK, node, name, id) + +static struct sgml_node_info docbook_attributes[DOCBOOK_ATTRIBUTES] = { + SGML_NODE_HEAD(DOCBOOK, ATTRIBUTE), + +#include "dom/sgml/docbook/attribute.inc" +}; + +static struct sgml_node_info docbook_elements[DOCBOOK_ELEMENTS] = { + SGML_NODE_HEAD(DOCBOOK, ELEMENT), + +#include "dom/sgml/docbook/element.inc" +}; + + +struct sgml_info sgml_docbook_info = { + SGML_DOCTYPE_DOCBOOK, + docbook_attributes, + docbook_elements, +}; diff --git a/src/dom/sgml/docbook/docbook.h b/src/dom/sgml/docbook/docbook.h new file mode 100644 index 00000000..879b3427 --- /dev/null +++ b/src/dom/sgml/docbook/docbook.h @@ -0,0 +1,30 @@ +#ifndef EL__DOM_SGML_DOCBOOK_DOCBOOK_H +#define EL__DOM_SGML_DOCBOOK_DOCBOOK_H + +#include "dom/stack.h" +#include "dom/sgml/sgml.h" + +extern struct sgml_info sgml_docbook_info; + +#define DOCBOOK_(node, name, flags) \ + SGML_NODE_INFO_TYPE(DOCBOOK, node, name) + +enum docbook_element_type { + DOCBOOK_ELEMENT_UNKNOWN, + +#include "dom/sgml/docbook/element.inc" + + DOCBOOK_ELEMENTS, +}; + +enum docbook_attribute_type { + DOCBOOK_ATTRIBUTE_UNKNOWN, + +#include "dom/sgml/docbook/attribute.inc" + + DOCBOOK_ATTRIBUTES, +}; + +#undef DOCBOOK_ + +#endif diff --git a/src/dom/sgml/docbook/info.c b/src/dom/sgml/docbook/info.c new file mode 100644 index 00000000..b0302fcb --- /dev/null +++ b/src/dom/sgml/docbook/info.c @@ -0,0 +1,87 @@ +/* SGML node handling */ +/* $Id: docbook.c,v 1.1.2.24 2004/02/29 02:47:30 jonas Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "elinks.h" + +#include "document/dom/navigator.h" +#include "document/dom/node.h" +#include "document/sgml/docbook/info.h" +#include "document/sgml/parser.h" +#include "document/sgml/scanner.h" +#include "document/sgml/sgml.h" +#include "util/error.h" +#include "util/memory.h" +#include "util/string.h" + + +#define DOCBOOK_NODE_INFO(node, name, id) SGML_NODE_INFO(DOCBOOK, node, name, id) +#define DOCBOOK_NODE_INF2(node, name, str, id) SGML_NODE_INF2(DOCBOOK, node, name, str, id) + +static struct sgml_node_info docbook_attributes[DOCBOOK_ATTRIBUTES] = { + SGML_NODE_HEAD(DOCBOOK, ATTRIBUTE), + +#include "document/sgml/docbook/attribute.inc" +}; + +static struct sgml_node_info docbook_elements[DOCBOOK_ELEMENTS] = { + SGML_NODE_HEAD(DOCBOOK, ELEMENT), + +#include "document/sgml/docbook/element.inc" +}; + + +static struct dom_node * +add_docbook_element_end_node(struct dom_navigator *navigator, struct dom_node *node, void *data) +{ + struct sgml_parser *parser = navigator->data; + struct dom_node *parent; + struct scanner_token *token; + + assert(navigator && parser && node); + assert(dom_navigator_has_parents(navigator)); + + if (!(parser->flags & SGML_PARSER_ADD_ELEMENT_ENDS)) + return NULL; + + /* Are we the actual node being popped? */ + if (node != get_dom_navigator_top(navigator)->node) + return NULL; + + parent = get_dom_navigator_parent(navigator)->node; + token = get_scanner_token(&parser->scanner); + + assertm(token, "No token found in callback"); + assertm(token->type == SGML_TOKEN_ELEMENT_END, "Bad token found in callback"); + + if (!token->length) return NULL; + + return add_dom_element(parent, token->string, token->length); +} + + +struct sgml_info sgml_docbook_info = { + docbook_attributes, + docbook_elements, + { + /* */ NULL, + /* DOM_NODE_ELEMENT */ add_docbook_element_end_node, + /* DOM_NODE_ATTRIBUTE */ NULL, + /* DOM_NODE_TEXT */ NULL, + /* DOM_NODE_CDATA_SECTION */ NULL, + /* DOM_NODE_ENTITY_REFERENCE */ NULL, + /* DOM_NODE_ENTITY */ NULL, + /* DOM_NODE_PROC_INSTRUCTION */ NULL, + /* DOM_NODE_COMMENT */ NULL, + /* DOM_NODE_DOCUMENT */ NULL, + /* DOM_NODE_DOCUMENT_TYPE */ NULL, + /* DOM_NODE_DOCUMENT_FRAGMENT */ NULL, + /* DOM_NODE_NOTATION */ NULL, + } +}; diff --git a/src/dom/sgml/sgml.c b/src/dom/sgml/sgml.c index 49445321..145d894d 100644 --- a/src/dom/sgml/sgml.c +++ b/src/dom/sgml/sgml.c @@ -16,6 +16,7 @@ /* Backend includes: */ +#include "dom/sgml/docbook/docbook.h" #include "dom/sgml/html/html.h" #include "dom/sgml/rss/rss.h" #include "dom/sgml/xbel/xbel.h" @@ -31,6 +32,7 @@ sgml_info_strcmp(const void *key_, const void *node_) } struct sgml_info *sgml_info[SGML_DOCTYPES] = { + &sgml_docbook_info, &sgml_html_info, &sgml_rss_info, &sgml_xbel_info, diff --git a/src/dom/sgml/sgml.h b/src/dom/sgml/sgml.h index 0e059f60..f3c064e7 100644 --- a/src/dom/sgml/sgml.h +++ b/src/dom/sgml/sgml.h @@ -76,6 +76,7 @@ get_sgml_node_info(struct sgml_node_info list[], struct dom_node *node) } enum sgml_document_type { + SGML_DOCTYPE_DOCBOOK, SGML_DOCTYPE_HTML, SGML_DOCTYPE_RSS, SGML_DOCTYPE_XBEL, diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index a32803a8..466261da 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -100,6 +100,7 @@ static struct option_info default_mime_options[] = { #ifdef CONFIG_DOM INIT_OPT_MIME_EXTENSION("rss", "application/rss+xml"), INIT_OPT_MIME_EXTENSION("xbel", "application/xbel+xml"), + INIT_OPT_MIME_EXTENSION("sgml", "application/docbook+xml"), #endif NULL_OPTION_INFO, diff --git a/src/session/download.c b/src/session/download.c index 3e3ad241..a94f9543 100644 --- a/src/session/download.c +++ b/src/session/download.c @@ -1145,14 +1145,15 @@ struct { unsigned int plain:1; } static known_types[] = { { "text/html", 0 }, + { "text/plain", 1 }, { "application/xhtml+xml", 0 }, /* RFC 3236 */ #if CONFIG_DOM + { "application/docbook+xml", 1 }, { "application/rss+xml", 1 }, { "application/xbel+xml", 1 }, { "application/xbel", 1 }, { "application/x-xbel", 1 }, #endif - { "text/plain", 1 }, { NULL, 1 }, }; diff --git a/test/docbook/elinks.1.sgml b/test/docbook/elinks.1.sgml new file mode 100644 index 00000000..6ba0abb8 --- /dev/null +++ b/test/docbook/elinks.1.sgml @@ -0,0 +1,150 @@ + + + + + + + + elinks + 1 + + + + elinks + lynx-like alternative character mode WWW browser + + + + + elinks + options + url + + + + DESCRIPTION + + + ELinks is a text mode WWW browser, supporting colors, + table rendering, background downloading, menu driven + configuration interface, tabbed browsing and slim code. + + + + + Frames are supported. You can have different file formats associated + with external viewers. mailto: and telnet: are supported via external + clients. + + + + + ELinks can handle local (file://) or remote + (http://, ftp:// or + https:// if there's compiled-in SSL support) URLs. + It has also basic support for finger:. + + + + + OPTIONS + + + Most options can be set in the user interface or config file, so + usually you do not need to care about them. Note that this list is by + no means complete and it is not kept up-to-date. To get complete list + of commandline options, start ELinks with parameter + --help. + + +&config-cmdoptions; + + + ENVIRONMENT VARIABLES +&config-envvars; + + + FILES +&config-files; + + + PLATFORMS + + + ELinks is known to work on Linux, FreeBSD, OpenBSD, Solaris, IRIX, + HPUX, Digital Unix, AIX, OS/2, BeOS and RISC OS. Port for Win32 is in + state of beta testing. + + + + + BUGS + + + See the BUGS file coming with ELinks distribution + tarball for list of known bugs. + + + + + Please report any other bugs you find to the ELinks mailing list + + elinks-users@linuxfromscratch.org or + the bug system. + + + + + LICENSE + + + ELinks is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + + + + AUTHORS + + + Links was written by Mikulas Patocka + mikulas@artax.karlin.mff.cuni.cz. ELinks - which is + based on Links - was written by Petr Baudis + pasky@ucw.cz. See file AUTHORS in + the source tree for a list of people contributing to this project. + + + + + The homepage of ELinks can be found at http://elinks.or.cz/ + + + + + This manual page was written by Peter Gervai + grin@tolna.net, using excerpts from a (yet?) unknown + Links fan for the Debian GNU/Linux system (but may be used by others). + Contributions from Francis A. Holop. Extended, clarified and made more + up-to-date by Petr Baudis pasky@ucw.cz. Updated by Zas + zas@norz.org. The conversion to DocBook for ELinks 0.5 + and trimming was done by Jonas Fonseca fonseca@diku.dk. + + + + + SEE ALSO + + + elinkskeys(5), + elinks.conf(5), + links(1), + lynx(1), + w3m(1), + wget(1) + + + +