Skip to content

Commit

Permalink
Add meta header to HTML docs to force utf-8
Browse files Browse the repository at this point in the history
When using Firefox 45.0.2 on Debian linux, I noticed that
Gröbner appears correctly on
  http://www.math.uiuc.edu/Macaulay2/doc/Macaulay2-1.8.2/share/doc/Macaulay2/Macaulay2Doc/html/_gb.html
but garbled on
  file:///usr/share/doc/Macaulay2/Macaulay2Doc/html/_gb.html
Changing Firefox's "Text encoding" setting from "Western" to
"Unicode" fixes the matter, so it appears to be using the
wrong character encoding.

All of M2's HTML documentation declares itself as XHTML and
tries to declare its character encoding as utf-8 in the
<?xml...> tag.  This apparently works if the XHTML is parsed
as XHTML.  However, many XHTML documents are not parsed as XHTML;
for instance, as of April 2016, the web server for M2's
online documentation includes the HTTP header
  Content-Type: text/html; charset=utf-8
and this MIME type apparently forces many browsers to read
the docs as HTML:
  https://www.w3.org/International/articles/serving-xhtml/index#mime

For HTML, it is recommended:
  https://www.w3.org/International/questions/qa-html-encoding-declarations#quickanswer
to always set the character encoding using a <meta...> tag
or an HTTP header.  Because (I think) of the above problems
with XHTML being interpreted as HTML, the same is recommended
for XHTML documents:
  https://www.w3.org/TR/xhtml1/#C_9

The problem here is that the local M2 documentation has neither
an HTTP header nor a <meta...> tag to set the character
encoding, and on my system Firefox is guessing wrong.
This change adds the tag
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
inside the <head> of each HTML document, right after </title>,
to force the UTF-8 character encoding everywhere.
  • Loading branch information
bapike committed Apr 21, 2016
1 parent 8a05b0a commit 13f0840
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions M2/Macaulay2/m2/html.m2
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ links := tag -> (
LINK { "href" => toURL doccss, "rel" => "stylesheet", "type" => "text/css" }
)

-- Also set the character encoding with a meta http-equiv statement. (Sometimes XHTML
-- is parsed as HTML, and then the HTTP header or a meta tag is used to determine the
-- character encoding. Locally-stored documentation does not have an HTTP header.)
defaultCharSet := () -> META { "http-equiv" => "Content-Type", "content" => "text/html; charset=utf-8" }

BUTTON := (s,alt) -> (
s = toURL s;
if alt === null
Expand Down Expand Up @@ -408,7 +413,7 @@ makeMasterIndex := (keylist,verbose) -> (
title := DocumentTag.FormattedKey topDocumentTag | " : Index";
if verbose then stderr << "--making '" << title << "' in " << fn << endl;
r := HTML {
HEAD splice { TITLE title, links() },
HEAD splice { TITLE title, defaultCharSet(), links() },
BODY nonnull {
DIV { topNodeButton, " | ", tocButton, {* " | ", directoryButton, *} " | ", homeButton },
HR{},
Expand All @@ -430,7 +435,7 @@ maketableOfContents := (verbose) -> (
if verbose then stderr << "--making " << title << "' in " << fn << endl;
fn
<< html HTML {
HEAD splice { TITLE title, links() },
HEAD splice { TITLE title, defaultCharSet(), links() },
BODY {
DIV { topNodeButton, " | ", masterIndexButton, {* " | ", directoryButton, *} " | ", homeButton },
HR{},
Expand Down Expand Up @@ -991,6 +996,7 @@ installPackage Package := opts -> pkg -> (
<< html HTML {
HEAD splice {
TITLE {fkey, commentize headline fkey}, -- I hope this works...
defaultCharSet(),
links tag
},
BODY {
Expand Down Expand Up @@ -1177,6 +1183,7 @@ makePackageIndex List := path -> (
fn << html HTML {
HEAD splice {
TITLE {key, commentize headline key},
defaultCharSet(),
links()
},
BODY {
Expand Down Expand Up @@ -1284,7 +1291,8 @@ showHtml = show Hypertext := x -> (
fn := temporaryFileName() | ".html";
fn << html HTML {
HEAD {
TITLE "Macaulay2 Output"
TITLE "Macaulay2 Output",
defaultCharSet()
},
BODY {
x
Expand Down

0 comments on commit 13f0840

Please sign in to comment.