@@ -6,7 +6,7 @@ window.addEventListener('load', function load(event) {
66// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIURI
77function makeURI ( aURL , aOriginCharset , aBaseURI ) {
88 var ioService = Components . classes [ "@mozilla.org/network/io-service;1" ]
9- . getService ( Components . interfaces . nsIIOService ) ;
9+ . getService ( Components . interfaces . nsIIOService ) ;
1010 return ioService . newURI ( aURL , aOriginCharset , aBaseURI ) ;
1111}
1212
@@ -31,25 +31,25 @@ function parseHTML(doc, html, allowStyle, baseURI, isXML) {
3131 // User the newer nsIParserUtils on versions that support it.
3232 if ( PARSER_UTILS in Components . classes ) {
3333 let parser = Components . classes [ PARSER_UTILS ]
34- . getService ( Ci . nsIParserUtils ) ;
34+ . getService ( Ci . nsIParserUtils ) ;
3535 if ( "parseFragment" in parser )
3636 return parser . parseFragment ( html , allowStyle ? parser . SanitizerAllowStyle : 0 ,
37- ! ! isXML , baseURI , doc . documentElement ) ;
37+ ! ! isXML , baseURI , doc . documentElement ) ;
3838 }
3939
4040 return Components . classes [ "@mozilla.org/feed-unescapehtml;1" ]
41- . getService ( Components . interfaces . nsIScriptableUnescapeHTML )
42- . parseFragment ( html , ! ! isXML , baseURI , doc . documentElement ) ;
41+ . getService ( Components . interfaces . nsIScriptableUnescapeHTML )
42+ . parseFragment ( html , ! ! isXML , baseURI , doc . documentElement ) ;
4343}
4444
4545function BrowserSetForcedCharacterSet ( aCharset ) {
46- var wnd = ( gContextMenu ? document . commandDispatcher . focusedWindow : window ) ;
47- if ( ( window === wnd ) || ( wnd === null ) ) wnd = window . content ;
48- const Ci = Components . interfaces ;
49- var webNav = wnd . QueryInterface ( Ci . nsIInterfaceRequestor ) . getInterface ( Ci . nsIWebNavigation ) ;
50- var docShell = webNav . QueryInterface ( Ci . nsIDocShell ) ;
51- docShell . QueryInterface ( Ci . nsIDocCharset ) . charset = aCharset ;
52- webNav . reload ( nsIWebNavigation . LOAD_FLAGS_CHARSET_CHANGE ) ;
46+ var wnd = ( gContextMenu ? document . commandDispatcher . focusedWindow : window ) ;
47+ if ( ( window === wnd ) || ( wnd === null ) ) wnd = window . content ;
48+ const Ci = Components . interfaces ;
49+ var webNav = wnd . QueryInterface ( Ci . nsIInterfaceRequestor ) . getInterface ( Ci . nsIWebNavigation ) ;
50+ var docShell = webNav . QueryInterface ( Ci . nsIDocShell ) ;
51+ docShell . QueryInterface ( Ci . nsIDocCharset ) . charset = aCharset ;
52+ webNav . reload ( nsIWebNavigation . LOAD_FLAGS_CHARSET_CHANGE ) ;
5353}
5454
5555if ( ! MarkdownViewer ) {
@@ -71,16 +71,15 @@ if (!MarkdownViewer) {
7171 document . contentType !== "text/html" ) {
7272
7373 // Change the charset
74- if ( document . characterSet . toLowerCase ( ) !== 'utf-8' ) {
75- BrowserSetForcedCharacterSet ( 'utf-8' ) ;
76- return ;
77- }
78-
79- // Parse the content Markdown => HTML
80- var md = markdownit ( {
81- html : true ,
82- linkify : true ,
83- // Shameless copypasta https://github.com/markdown-it/markdown-it#syntax-highlighting
74+ if ( document . characterSet . toLowerCase ( ) !== 'utf-8' ) {
75+ BrowserSetForcedCharacterSet ( 'utf-8' ) ;
76+ }
77+
78+ // Parse the content Markdown => HTML
79+ var md = markdownit ( {
80+ html : true ,
81+ linkify : true ,
82+ // Shameless copypasta https://github.com/markdown-it/markdown-it#syntax-highlighting
8483 highlight : function ( str , lang ) {
8584 if ( lang && hljs . getLanguage ( lang ) ) {
8685 try {
@@ -97,7 +96,7 @@ if (!MarkdownViewer) {
9796 } ) ;
9897
9998 var textContent = document . documentElement . textContent ,
100- fragment = parseHTML ( document , '<div class="container">' + md . render ( textContent ) + '</div>' , false , makeURI ( document . location . href ) ) ;
99+ fragment = parseHTML ( document , '<div class="container">' + md . render ( textContent ) + '</div>' , false , makeURI ( document . location . href ) ) ;
101100
102101 // Empty the body
103102 while ( document . body . firstChild ) {
@@ -118,10 +117,10 @@ if (!MarkdownViewer) {
118117 document . head . appendChild ( hljsStyle ) ;
119118
120119 // Adding this is considered a good practice for mobiles
121- var meta = document . createElement ( 'meta' ) ;
122- meta . name = 'viewport' ;
123- meta . content = 'width=device-width, initial-scale=1' ;
124- document . head . appendChild ( meta ) ;
120+ const viewport = document . createElement ( 'meta' ) ;
121+ viewport . name = 'viewport' ;
122+ viewport . content = 'width=device-width, initial-scale=1' ;
123+ document . head . appendChild ( viewport ) ;
125124
126125 // Add the content
127126 document . body . appendChild ( fragment ) ;
0 commit comments