[...]
Post by Eric WongPost by Rene KitaEric, just in case you are still interested I also have a patch to force
folding in <pre> tags.
Thanks, I am still interested in the <pre> folding patch as well.
Patch is below.
Post by Eric WongI didn't find an improvement from using
Do-not-override-cols-option-value.patch on my <pre>-heavy sites
I read this as: The patch worked, but the result was not satisfying
because of the many <pre>s, right? Thanks for testing.
Your welcome.
I don't expect those patches to be available in Debian in the near
future. You might check out my fork at [0], those patches are currently
staged in branch 'next' for some beta testing.
[0]: https://sr.ht/~rkta/w3m
----->8------
From 6e93a36c274dd2a3b9541730aa59023915660c2f Mon Sep 17 00:00:00 2001
From: Rene Kita <***@rkta.de>
Date: Sun, 1 Sep 2024 12:23:17 +0200
Subject: [PATCH] Enable folding in pre tags
Some bug trackers are really annoying to read, because they place
comments in <pre> elements. They usually provide some CSS to make it
readable.
As we do not speak CSS, add a command to reload the page folding those
long lines. This is a one-time operation. Additionally add an option to
make this behaviour permanent.
---
doc-de/README.func | 1 +
doc/README.func | 1 +
file.c | 7 +++++--
fm.h | 1 +
main.c | 11 +++++++++++
proto.h | 1 +
rc.c | 3 +++
7 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/doc-de/README.func b/doc-de/README.func
index cb175db4..7adabfba 100644
--- a/doc-de/README.func
+++ b/doc-de/README.func
@@ -31,6 +31,7 @@ EXEC_SHELL Führe Shell-Befehl aus und zeige Ausgabe an
EXIT Sofort beenden
EXTERN Verwende externen Browser zur Anzeige
EXTERN_LINK Verwende externen Browser zur Anzeige des Linkziels
+FOLD_PRE Erzwinge Umbruch von langen Zeilen in <pre>-Elementen
FRAME Wechsle zwischen Kennung und Umsetzung von HTML-Frames
GOTO Öffne angegebenes Dokument in neuem Puffer
GOTO_HOME Zurück zur Startseite (die Variablen HTTP_HOME oder WWW_HOME spezifiziert wurden)
diff --git a/doc/README.func b/doc/README.func
index 55523a4b..65ca1f84 100644
--- a/doc/README.func
+++ b/doc/README.func
@@ -31,6 +31,7 @@ EXEC_SHELL Execute shell command and display output
EXIT Quit without confirmation
EXTERN Display using an external browser
EXTERN_LINK Display target using an external browser
+FOLD_PRE Fold long lines in <pre> elements
FRAME Toggle rendering HTML frames
GOTO Open specified document in a new buffer
GOTO_HOME Return to the homepage (specified HTTP_HOME or WWW_HOME variable)
diff --git a/file.c b/file.c
index fb0a75ef..74927de9 100644
--- a/file.c
+++ b/file.c
@@ -30,6 +30,7 @@
#define MAX_INPUT_SIZE 80 /* TODO - max should be screen line length */
+extern int fold_pre;
static int frame_source = 0;
static int need_number = 0;
@@ -2604,7 +2605,7 @@ check_breakpoint(struct readbuffer *obuf, int pre_mode, char *ch)
int tlen, len = obuf->line->length;
append_tags(obuf);
- if (pre_mode)
+ if (pre_mode && !fold_pre)
return;
tlen = obuf->line->length - len;
if (tlen > 0
@@ -6695,7 +6696,8 @@ HTMLlineproc0(char *line, struct html_feed_environ *h_env, int internal)
proc_mchar(obuf, 1, delta, &str, mode);
}
if (obuf->flag & (RB_SPECIAL & ~RB_PRE_INT))
- continue;
+ if (!fold_pre)
+ continue;
}
else {
if (!IS_SPACE(*str))
@@ -6923,6 +6925,7 @@ loadHTMLBuffer(URLFile *f, Buffer *newBuf)
if (src)
newBuf->sourcefile = tmp->ptr;
}
+ fold_pre |= FoldPre;
loadHTMLstream(f, newBuf, src, newBuf->bufferprop & BP_FRAME);
diff --git a/fm.h b/fm.h
index a2ca9ead..5353589e 100644
--- a/fm.h
+++ b/fm.h
@@ -1058,6 +1058,7 @@ global int ignore_null_img_alt init(TRUE);
#define DISPLAY_INS_DEL_FONTIFY 2
global int displayInsDel init(DISPLAY_INS_DEL_NORMAL);
global int FoldTextarea init(FALSE);
+global int FoldPre init(FALSE);
global int FoldLine init(FALSE);
#define DEFAULT_URL_EMPTY 0
#define DEFAULT_URL_CURRENT 1
diff --git a/main.c b/main.c
index 144c21b7..4c0b8613 100644
--- a/main.c
+++ b/main.c
@@ -129,6 +129,7 @@ static int searchKeyNum(void);
int enable_inline_image;
extern int opt_cols;
+int fold_pre;
static void
fversion(FILE * f)
@@ -4963,6 +4964,14 @@ DEFUN(vwSrc, SOURCE VIEW, "Toggle between HTML shown or processed")
displayBuffer(Currentbuf, B_NORMAL);
}
+DEFUN(foldPre, FOLD_PRE, "Fold long lines in <pre> elements")
+{
+ fold_pre = 1;
+ Currentbuf->need_reshape = TRUE;
+ displayBuffer(Currentbuf, B_FORCE_REDRAW);
+ fold_pre = FoldPre;
+}
+
/* reload */
DEFUN(reload, RELOAD, "Load current document anew")
{
@@ -4990,6 +4999,7 @@ DEFUN(reload, RELOAD, "Load current document anew")
disp_err_message("Can't reload stdin", TRUE);
return;
}
+ fold_pre = FoldPre;
copyBuffer(&sbuf, Currentbuf);
if (Currentbuf->bufferprop & BP_FRAME &&
(fbuf = Currentbuf->linkBuffer[LB_N_FRAME])) {
@@ -5086,6 +5096,7 @@ DEFUN(reload, RELOAD, "Load current document anew")
restorePosition(Currentbuf, &sbuf);
}
displayBuffer(Currentbuf, B_FORCE_REDRAW);
+ fold_pre = FoldPre;
}
/* reshape */
diff --git a/proto.h b/proto.h
index ed0d2369..ef8216e0 100644
--- a/proto.h
+++ b/proto.h
@@ -99,6 +99,7 @@ extern void peekURL(void);
extern void peekIMG(void);
extern void curURL(void);
extern void vwSrc(void);
+extern void foldPre(void);
extern void reload(void);
extern void reshape(void);
extern void chkURL(void);
diff --git a/rc.c b/rc.c
index 2fcacb56..151771dd 100644
--- a/rc.c
+++ b/rc.c
@@ -98,6 +98,7 @@ static int OptionEncode = FALSE;
#define CMT_DISP_BORDERS N_("Display table borders, ignore value of BORDER")
#define CMT_DISABLE_CENTER N_("Disable center alignment")
#define CMT_FOLD_TEXTAREA N_("Fold lines in TEXTAREA")
+#define CMT_FOLD_PRE N_("Fold lines in PRE")
#define CMT_DISP_INS_DEL N_("Display INS, DEL, S and STRIKE element")
#define CMT_COLOR N_("Display with color")
#define CMT_HINTENSITY_COLOR N_("Use high-intensity colors")
@@ -436,6 +437,8 @@ struct param_ptr params1[] = {
CMT_DISABLE_CENTER, NULL},
{"fold_textarea", P_CHARINT, PI_ONOFF, (void *)&FoldTextarea,
CMT_FOLD_TEXTAREA, NULL},
+ {"fold_pre", P_CHARINT, PI_ONOFF, (void *)&FoldPre,
+ CMT_FOLD_PRE, NULL},
{"display_ins_del", P_INT, PI_SEL_C, (void *)&displayInsDel,
CMT_DISP_INS_DEL, displayinsdel},
{"ignore_null_img_alt", P_INT, PI_ONOFF, (void *)&ignore_null_img_alt,
--
2.46.0