mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[htmlcxx] Added htmlcxx parser for source code displaying
It is compilable only together with spidermonkey, and only with meson for now.
This commit is contained in:
parent
fe040ee50a
commit
1fa5504570
@ -100,6 +100,9 @@
|
|||||||
/* Define if you want: zlib support */
|
/* Define if you want: zlib support */
|
||||||
#mesondefine CONFIG_GZIP
|
#mesondefine CONFIG_GZIP
|
||||||
|
|
||||||
|
/* Define if you want: htmlcxx support */
|
||||||
|
#mesondefine CONFIG_HTMLCXX
|
||||||
|
|
||||||
/* Define if you want: HTML highlighting support */
|
/* Define if you want: HTML highlighting support */
|
||||||
#mesondefine CONFIG_HTML_HIGHLIGHT
|
#mesondefine CONFIG_HTML_HIGHLIGHT
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ conf_data.set('CONFIG_LIBEV', get_option('libev'))
|
|||||||
conf_data.set('CONFIG_LIBEVENT', get_option('libevent'))
|
conf_data.set('CONFIG_LIBEVENT', get_option('libevent'))
|
||||||
conf_data.set('CONFIG_X', get_option('x'))
|
conf_data.set('CONFIG_X', get_option('x'))
|
||||||
conf_data.set('CONFIG_LIBDOM', get_option('libdom'))
|
conf_data.set('CONFIG_LIBDOM', get_option('libdom'))
|
||||||
|
conf_data.set('CONFIG_HTMLCXX', get_option('htmlcxx'))
|
||||||
|
|
||||||
#CONFIG_BOOKMARKS=true
|
#CONFIG_BOOKMARKS=true
|
||||||
#CONFIG_XBEL_BOOKMARKS=true
|
#CONFIG_XBEL_BOOKMARKS=true
|
||||||
@ -156,7 +157,7 @@ conf_data.set10('HAVE_SYS_TIME_H', 1)
|
|||||||
|
|
||||||
compiler = meson.get_compiler('c')
|
compiler = meson.get_compiler('c')
|
||||||
|
|
||||||
if conf_data.get('CONFIG_ECMASCRIPT')
|
if conf_data.get('CONFIG_ECMASCRIPT') or conf_data.get('CONFIG_HTMLCXX')
|
||||||
extracflags = ['-xc++', '-fpermissive']
|
extracflags = ['-xc++', '-fpermissive']
|
||||||
else
|
else
|
||||||
extracflags = []
|
extracflags = []
|
||||||
@ -295,6 +296,11 @@ if conf_data.get('CONFIG_LIBDOM')
|
|||||||
deps += domdeps
|
deps += domdeps
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if conf_data.get('CONFIG_HTMLCXX')
|
||||||
|
htmlcxxdeps = dependency('htmlcxx')
|
||||||
|
deps += htmlcxxdeps
|
||||||
|
endif
|
||||||
|
|
||||||
if conf_data.get('CONFIG_SCRIPTING_PYTHON')
|
if conf_data.get('CONFIG_SCRIPTING_PYTHON')
|
||||||
python3deps = dependency('python3-embed')
|
python3deps = dependency('python3-embed')
|
||||||
deps += python3deps
|
deps += python3deps
|
||||||
|
@ -61,3 +61,4 @@ option('libev', type: 'boolean', value: false, description: 'compile with libev
|
|||||||
option('libevent', type: 'boolean', value: false, description: 'compile with libevent. Note that libev has precedence')
|
option('libevent', type: 'boolean', value: false, description: 'compile with libevent. Note that libev has precedence')
|
||||||
option('x', type: 'boolean', value: false, description: 'use the X Window System')
|
option('x', type: 'boolean', value: false, description: 'use the X Window System')
|
||||||
option('libdom', type: 'boolean', value: false, description: 'libdom')
|
option('libdom', type: 'boolean', value: false, description: 'libdom')
|
||||||
|
option('htmlcxx', type: 'boolean', value: false, description: 'htmlcxx')
|
||||||
|
1
src/document/htmlcxx/meson.build
Normal file
1
src/document/htmlcxx/meson.build
Normal file
@ -0,0 +1 @@
|
|||||||
|
srcs += files('renderer.c')
|
86
src/document/htmlcxx/renderer.c
Normal file
86
src/document/htmlcxx/renderer.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/* Plain text document renderer */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "bookmarks/bookmarks.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "config/options.h"
|
||||||
|
#include "document/docdata.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/format.h"
|
||||||
|
#include "document/options.h"
|
||||||
|
#include "document/htmlcxx/renderer.h"
|
||||||
|
#include "document/plain/renderer.h"
|
||||||
|
#include "document/renderer.h"
|
||||||
|
#include "globhist/globhist.h"
|
||||||
|
#include "intl/charsets.h"
|
||||||
|
#include "protocol/protocol.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
|
#include "terminal/color.h"
|
||||||
|
#include "terminal/draw.h"
|
||||||
|
#include "util/color.h"
|
||||||
|
#include "util/error.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
|
#include <htmlcxx/html/ParserDom.h>
|
||||||
|
using namespace htmlcxx;
|
||||||
|
|
||||||
|
struct source_renderer {
|
||||||
|
struct string tmp_buffer;
|
||||||
|
struct string *source;
|
||||||
|
char *enc;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
walk_tree(struct string *buf, tree<HTML::Node> const &dom)
|
||||||
|
{
|
||||||
|
tree<HTML::Node>::iterator it = dom.begin();
|
||||||
|
add_to_string(buf, it->text().c_str());
|
||||||
|
|
||||||
|
for (tree<HTML::Node>::sibling_iterator childIt = dom.begin(it); childIt != dom.end(it); ++childIt)
|
||||||
|
{
|
||||||
|
walk_tree(buf, childIt);
|
||||||
|
}
|
||||||
|
add_to_string(buf, it->closingText().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
htmlcxx_main(struct source_renderer *renderer)
|
||||||
|
{
|
||||||
|
std::string html = renderer->source->source;
|
||||||
|
HTML::ParserDom parser;
|
||||||
|
tree<HTML::Node> dom = parser.parseTree(html);
|
||||||
|
walk_tree(&renderer->tmp_buffer, dom);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
render_source_document_cxx(struct cache_entry *cached, struct document *document,
|
||||||
|
struct string *buffer)
|
||||||
|
{
|
||||||
|
struct source_renderer renderer;
|
||||||
|
char *head = empty_string_or_(cached->head);
|
||||||
|
|
||||||
|
(void)get_convert_table(head, document->options.cp,
|
||||||
|
document->options.assume_cp,
|
||||||
|
&document->cp,
|
||||||
|
&document->cp_status,
|
||||||
|
document->options.hard_assume);
|
||||||
|
|
||||||
|
init_string(&renderer.tmp_buffer);
|
||||||
|
renderer.source = buffer;
|
||||||
|
renderer.enc = get_cp_mime_name(document->cp);
|
||||||
|
htmlcxx_main(&renderer);
|
||||||
|
render_plain_document(cached, document, &renderer.tmp_buffer);
|
||||||
|
done_string(&renderer.tmp_buffer);
|
||||||
|
}
|
18
src/document/htmlcxx/renderer.h
Normal file
18
src/document/htmlcxx/renderer.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef EL__DOCUMENT_HTMLCXX_RENDERER_H
|
||||||
|
#define EL__DOCUMENT_HTMLCXX_RENDERER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct cache_entry;
|
||||||
|
struct document;
|
||||||
|
struct string;
|
||||||
|
|
||||||
|
void render_source_document_cxx(struct cache_entry *cached, struct document *document, struct string *buffer);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -7,6 +7,9 @@ endif
|
|||||||
if conf_data.get('CONFIG_LIBDOM')
|
if conf_data.get('CONFIG_LIBDOM')
|
||||||
subdir('libdom')
|
subdir('libdom')
|
||||||
endif
|
endif
|
||||||
|
if conf_data.get('CONFIG_HTMLCXX')
|
||||||
|
subdir('htmlcxx')
|
||||||
|
endif
|
||||||
subdir('html')
|
subdir('html')
|
||||||
subdir('plain')
|
subdir('plain')
|
||||||
srcs += files('docdata.c', 'document.c', 'format.c', 'forms.c', 'options.c', 'refresh.c', 'renderer.c')
|
srcs += files('docdata.c', 'document.c', 'format.c', 'forms.c', 'options.c', 'refresh.c', 'renderer.c')
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "document/dom/renderer.h"
|
#include "document/dom/renderer.h"
|
||||||
#include "document/html/frames.h"
|
#include "document/html/frames.h"
|
||||||
#include "document/html/renderer.h"
|
#include "document/html/renderer.h"
|
||||||
|
#include "document/htmlcxx/renderer.h"
|
||||||
#include "document/libdom/renderer.h"
|
#include "document/libdom/renderer.h"
|
||||||
#include "document/plain/renderer.h"
|
#include "document/plain/renderer.h"
|
||||||
#include "document/renderer.h"
|
#include "document/renderer.h"
|
||||||
@ -256,6 +257,14 @@ render_encoded_document(struct cache_entry *cached, struct document *document)
|
|||||||
render_source_document(cached, document, &buffer);
|
render_source_document(cached, document, &buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_HTMLCXX
|
||||||
|
if (document->options.plain && cached->content_type
|
||||||
|
&& (!c_strcasecmp("text/html", cached->content_type)
|
||||||
|
|| !c_strcasecmp("application/xhtml+xml", cached->content_type))) {
|
||||||
|
render_source_document_cxx(cached, document, &buffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
if (document->options.plain) {
|
if (document->options.plain) {
|
||||||
#ifdef CONFIG_DOM
|
#ifdef CONFIG_DOM
|
||||||
|
Loading…
Reference in New Issue
Block a user