From f351fbcf6ae6f278f038f4969a36ce0833a15cbe Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 7 Mar 2021 22:07:34 +0100 Subject: [PATCH] [dump] Experiment with pre_format_hook in dump. Refs #103 --- src/scripting/smjs/hooks.c | 2 +- src/session/session.c | 2 +- src/session/session.h | 4 ++++ src/viewer/dump/dump.c | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/scripting/smjs/hooks.c b/src/scripting/smjs/hooks.c index ec8fc718..efedc8ce 100644 --- a/src/scripting/smjs/hooks.c +++ b/src/scripting/smjs/hooks.c @@ -80,7 +80,7 @@ script_hook_pre_format_html(va_list ap, void *data) smjs_ses = ses; - if (have_location(ses)) { + if (ses && have_location(ses)) { struct view_state *vs = &cur_loc(ses)->vs; view_state_object = smjs_get_view_state_object(vs); diff --git a/src/session/session.c b/src/session/session.c index 5b060e6b..e482ae37 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -553,7 +553,7 @@ add_questions_entry(void (*callback)(struct session *, void *), void *data) } #ifdef CONFIG_SCRIPTING -static void +void maybe_pre_format_html(struct cache_entry *cached, struct session *ses) { struct fragment *fragment; diff --git a/src/session/session.h b/src/session/session.h index accec013..d6ff4529 100644 --- a/src/session/session.h +++ b/src/session/session.h @@ -319,6 +319,10 @@ int eat_kbd_repeat_count(struct session *ses); * highlighting and status bar. */ int set_kbd_repeat_count(struct session *ses, int new_count); +#ifdef CONFIG_SCRIPTING +void maybe_pre_format_html(struct cache_entry *cached, struct session *ses); +#endif + #ifdef __cplusplus } #endif diff --git a/src/viewer/dump/dump.c b/src/viewer/dump/dump.c index 57918d9b..feb19e99 100644 --- a/src/viewer/dump/dump.c +++ b/src/viewer/dump/dump.c @@ -35,6 +35,7 @@ #include "protocol/protocol.h" #include "protocol/uri.h" #include "session/download.h" +#include "session/session.h" #include "terminal/color.h" #include "terminal/hardio.h" #include "terminal/terminal.h" @@ -410,6 +411,10 @@ dump_formatted(int fd, struct download *download, struct cache_entry *cached) o.links_numbering = get_opt_bool("document.dump.numbering", NULL); o.dump = 1; +#ifdef CONFIG_SCRIPTING + maybe_pre_format_html(cached, NULL); +#endif + init_vs(&vs, cached->uri, -1); render_document(&vs, &formatted, &o);