about summary refs log tree commit diff stats
path: root/res
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-13 21:16:12 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-25 02:46:21 +0100
commit6e98894199442e2213dc89e0c5fe970029f05b65 (patch)
tree57bf69a6fa825d72be1654482e8865b5e9b82829 /res
parentd41d4803b5ed15b7e8461394ee07ce5ab1de143a (diff)
downloadchawan-6e98894199442e2213dc89e0c5fe970029f05b65.tar.gz
Separate ANSI text decoding from main binary
Handling text/plain as ANSI colored text was problematic for two
reasons:

* You couldn't actually look at the real source of HTML pages or text
  files that used ANSI colors in the source.  In general, I only want
  ANSI colors when piping something into my pager, not when viewing any
  random file.
* More importantly, it introduced a separate rendering mode for
  plaintext documents, which resulted in the problem that only some
  buffers had DOMs.  This made it impossible to add functionality
  that would operate on the buffer's DOM, to e.g. implement w3m's
  MARK_URL.  Also, it locked us into the horribly inefficient line-based
  rendering model of entire documents.

Now we solve the problem in two separate parts:

* text/x-ansi is used automatically for documents received through
  stdin. A text/x-ansi handler ansi2html converts ANSI formatting to
  HTML.  text/x-ansi is also used for .ans, .asc file extensions.
* text/plain is a separate input mode in buffer, which places all text
  in a single <plaintext> tag.  Crucially, this does not invoke the HTML
  parser; that would eat NUL characters, which we should avoid.

One blind spot still remains: copiousoutput used to display ANSI colors,
and now it doesn't. To solve this, users can put the x-ansioutput
extension field to their mailcap entries, which behaves like
x-htmloutput except it first pipes the output into ansi2html.
Diffstat (limited to 'res')
-rw-r--r--res/mime.types1
-rw-r--r--res/ua.css6
2 files changed, 6 insertions, 1 deletions
diff --git a/res/mime.types b/res/mime.types
index fe3052a6..a52768d4 100644
--- a/res/mime.types
+++ b/res/mime.types
@@ -10,3 +10,4 @@ text/css		css
 image/png		png
 text/markdown		md
 text/gemini		gmi
+text/x-ansi		ans	asc
diff --git a/res/ua.css b/res/ua.css
index a85c5146..43cccc71 100644
--- a/res/ua.css
+++ b/res/ua.css
@@ -191,12 +191,16 @@ h1, h2, h3, h4, h5, h6 {
 	font-weight: bold;
 }
 
-pre, plaintext {
+pre {
 	margin-top: 1em;
 	margin-bottom: 1em;
 	white-space: pre;
 }
 
+plaintext {
+	white-space: pre;
+}
+
 p {
 	margin-top: 1em;
 	margin-bottom: 1em;