eric6/QScintilla/Exporters/ExporterHTML.py

changeset 7267
aedc309827c7
parent 7229
53054eb5b15a
child 7305
928858251f7a
--- a/eric6/QScintilla/Exporters/ExporterHTML.py	Wed Sep 25 18:25:43 2019 +0200
+++ b/eric6/QScintilla/Exporters/ExporterHTML.py	Wed Sep 25 18:37:35 2019 +0200
@@ -72,50 +72,54 @@
                 styleIsUsed[index] = True
         styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True
         
-        html = \
-            '''<!DOCTYPE html PUBLIC "-//W3C//DTD''' \
-            ''' XHTML 1.0 Transitional//EN"\n''' \
-            ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">''' \
-            '''\n''' \
-            '''<html xmlns="http://www.w3.org/1999/xhtml">\n''' \
+        html = (
+            '''<!DOCTYPE html PUBLIC "-//W3C//DTD'''
+            ''' XHTML 1.0 Transitional//EN"\n'''
+            ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'''
+            '''\n'''
+            '''<html xmlns="http://www.w3.org/1999/xhtml">\n'''
             '''<head>\n'''
+        )
         if titleFullPath:
             html += '''<title>{0}</title>\n'''.format(
                 self.editor.getFileName())
         else:
             html += '''<title>{0}</title>\n'''.format(
                 os.path.basename(self.editor.getFileName()))
-        html += '''<meta name="Generator" content="eric6" />\n''' \
-            '''<meta http-equiv="Content-Type" ''' \
+        html += (
+            '''<meta name="Generator" content="eric6" />\n'''
+            '''<meta http-equiv="Content-Type" '''
             '''content="text/html; charset=utf-8" />\n'''
+        )
         if folding:
-            html += \
-                '''<script language="JavaScript" type="text/javascript">\n''' \
-                '''<!--\n''' \
-                '''function symbol(id, sym) {\n''' \
-                '''  if (id.textContent == undefined) {\n''' \
-                '''    id.innerText = sym;\n''' \
-                '''  } else {\n''' \
-                '''    id.textContent = sym;\n''' \
-                '''  }\n''' \
-                '''}\n''' \
-                '''function toggle(id) {\n''' \
-                '''  var thislayer = document.getElementById('ln' + id);\n''' \
-                '''  id -= 1;\n''' \
-                '''  var togline = document.getElementById('hd' + id);\n''' \
-                '''  var togsym = document.getElementById('bt' + id);\n''' \
-                '''  if (thislayer.style.display == 'none') {\n''' \
-                '''    thislayer.style.display = 'block';\n''' \
-                '''    togline.style.textDecoration = 'none';\n''' \
-                '''    symbol(togsym, '- ');\n''' \
-                '''  } else {\n''' \
-                '''    thislayer.style.display = 'none';\n''' \
-                '''    togline.style.textDecoration = 'underline';\n''' \
-                '''    symbol(togsym, '+ ');\n''' \
-                '''  }\n''' \
-                '''}\n''' \
-                '''//-->\n''' \
+            html += (
+                '''<script language="JavaScript" type="text/javascript">\n'''
+                '''<!--\n'''
+                '''function symbol(id, sym) {\n'''
+                '''  if (id.textContent == undefined) {\n'''
+                '''    id.innerText = sym;\n'''
+                '''  } else {\n'''
+                '''    id.textContent = sym;\n'''
+                '''  }\n'''
+                '''}\n'''
+                '''function toggle(id) {\n'''
+                '''  var thislayer = document.getElementById('ln' + id);\n'''
+                '''  id -= 1;\n'''
+                '''  var togline = document.getElementById('hd' + id);\n'''
+                '''  var togsym = document.getElementById('bt' + id);\n'''
+                '''  if (thislayer.style.display == 'none') {\n'''
+                '''    thislayer.style.display = 'block';\n'''
+                '''    togline.style.textDecoration = 'none';\n'''
+                '''    symbol(togsym, '- ');\n'''
+                '''  } else {\n'''
+                '''    thislayer.style.display = 'none';\n'''
+                '''    togline.style.textDecoration = 'underline';\n'''
+                '''    symbol(togsym, '+ ');\n'''
+                '''  }\n'''
+                '''}\n'''
+                '''//-->\n'''
                 '''</script>\n'''
+            )
         
         lex = self.editor.getLexer()
         if lex:
@@ -127,11 +131,15 @@
         if lex:
             istyle = 0
             while istyle <= QsciScintilla.STYLE_MAX:
-                if (istyle <= QsciScintilla.STYLE_DEFAULT or
-                    istyle > QsciScintilla.STYLE_LASTPREDEFINED) and \
-                   styleIsUsed[istyle]:
-                    if lex.description(istyle) or \
-                       istyle == QsciScintilla.STYLE_DEFAULT:
+                if (
+                    (istyle <= QsciScintilla.STYLE_DEFAULT or
+                     istyle > QsciScintilla.STYLE_LASTPREDEFINED) and
+                    styleIsUsed[istyle]
+                ):
+                    if (
+                        lex.description(istyle) or
+                        istyle == QsciScintilla.STYLE_DEFAULT
+                    ):
                         font = lex.font(istyle)
                         colour = lex.color(istyle)
                         paper = lex.paper(istyle)
@@ -147,8 +155,10 @@
                             html += '''    font-family: '{0}';\n'''.format(
                                     font.family())
                         html += '''    color: {0};\n'''.format(colour.name())
-                        if istyle != QsciScintilla.STYLE_DEFAULT and \
-                           bgColour != paper.name():
+                        if (
+                            istyle != QsciScintilla.STYLE_DEFAULT and
+                            bgColour != paper.name()
+                        ):
                             html += '''    background: {0};\n'''.format(
                                     paper.name())
                             html += '''    text-decoration: inherit;\n'''
@@ -195,10 +205,13 @@
             html += '''<pre>'''
         
         if folding:
-            if self.editor.foldFlagsAt(line) & \
-               QsciScintilla.SC_FOLDLEVELHEADERFLAG:
-                html += '''<span id="hd{0:d}" onclick="toggle('{1:d}')">'''\
-                        .format(line, line + 1)
+            if (
+                self.editor.foldFlagsAt(line) &
+                    QsciScintilla.SC_FOLDLEVELHEADERFLAG
+            ):
+                html += (
+                    '''<span id="hd{0:d}" onclick="toggle('{1:d}')">'''
+                ).format(line, line + 1)
                 html += '''<span id="bt{0:d}">- </span>'''.format(line)
                 inFoldSpan = True
             else:
@@ -285,12 +298,14 @@
                     if newLevel > level:
                         html += '''<span id="ln{0:d}">'''.format(line)
                         levelStack.append(newLevel)
-                    if self.editor.foldFlagsAt(line) & \
-                       QsciScintilla.SC_FOLDLEVELHEADERFLAG:
-                        html += \
-                            '''<span id="hd{0:d}"''' \
-                            ''' onclick="toggle('{1:d}')">''' \
-                            .format(line, line + 1)
+                    if (
+                        self.editor.foldFlagsAt(line) &
+                            QsciScintilla.SC_FOLDLEVELHEADERFLAG
+                    ):
+                        html += (
+                            '''<span id="hd{0:d}"'''
+                            ''' onclick="toggle('{1:d}')">'''
+                        ).format(line, line + 1)
                         html += '''<span id="bt{0:d}">- </span>'''.format(line)
                         inFoldSpan = True
                     else:
@@ -299,8 +314,10 @@
                 else:
                     html += '\n'
                 
-                if styleIsUsed[styleCurrent] and \
-                   self.editor.byteAt(pos + 1) not in [b'\r', b'\n']:
+                if (
+                    styleIsUsed[styleCurrent] and
+                    self.editor.byteAt(pos + 1) not in [b'\r', b'\n']
+                ):
                     # We know it's the correct next style,
                     # but no (empty) span for an empty line
                     html += '''<span class="S{0:0d}">'''.format(styleCurrent)
@@ -385,14 +402,18 @@
             else:
                 extension = ""
             
-            if extension in \
-                Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \
-                    self.editor.getLanguage().lower() == "markdown":
+            if (
+                extension in Preferences.getEditor(
+                    "PreviewMarkdownFileNameExtensions") or
+                self.editor.getLanguage().lower() == "markdown"
+            ):
                 # export markdown to HTML
                 html = self.__generateFromMarkdown()
-            elif extension in \
-                Preferences.getEditor("PreviewRestFileNameExtensions") or \
-                    self.editor.getLanguage().lower() == "restructuredtext":
+            elif (
+                extension in Preferences.getEditor(
+                    "PreviewRestFileNameExtensions") or
+                self.editor.getLanguage().lower() == "restructuredtext"
+            ):
                 # export ReST to HTML
                 html = self.__generateFromReSTDocutils()
             else:
@@ -517,9 +538,11 @@
             extensions = ['fenced_code', 'extra']
         
         # version 2.0 supports only extension names, not instances
-        if markdown.version_info[0] > 2 or \
-                (markdown.version_info[0] == 2 and
-                 markdown.version_info[1] > 0):
+        if (
+            markdown.version_info[0] > 2 or
+            (markdown.version_info[0] == 2 and
+             markdown.version_info[1] > 0)
+        ):
             class _StrikeThroughExtension(markdown.Extension):
                 """
                 Class is placed here, because it depends on imported markdown,
@@ -554,16 +577,18 @@
                                      output_format=htmlFormat)
         
         if htmlFormat == "xhtml1":
-            head = \
-                '''<!DOCTYPE html PUBLIC "-//W3C//DTD''' \
-                ''' XHTML 1.0 Transitional//EN"\n''' \
-                ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional''' \
-                '''.dtd">\n''' \
+            head = (
+                '''<!DOCTYPE html PUBLIC "-//W3C//DTD'''
+                ''' XHTML 1.0 Transitional//EN"\n'''
+                ''' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional'''
+                '''.dtd">\n'''
                 '''<html xmlns="http://www.w3.org/1999/xhtml">\n'''
+            )
         elif htmlFormat == "html5":
-            head = \
-                '''<!DOCTYPE html>\n''' \
+            head = (
+                '''<!DOCTYPE html>\n'''
                 '''<html lang="EN">\n'''
+            )
         else:
             head = '<html lang="EN">\n'
         head += '''<head>\n'''
@@ -573,11 +598,13 @@
         else:
             head += '''<title>{0}</title>\n'''.format(
                 os.path.basename(self.editor.getFileName()))
-        head += '''<meta name="Generator" content="eric6" />\n''' \
-            '''<meta http-equiv="Content-Type" ''' \
-            '''content="text/html; charset=utf-8" />\n''' \
-            '''</head>\n''' \
+        head += (
+            '''<meta name="Generator" content="eric6" />\n'''
+            '''<meta http-equiv="Content-Type" '''
+            '''content="text/html; charset=utf-8" />\n'''
+            '''</head>\n'''
             '''<body>\n'''
+        )
         
         foot = '''\n</body>\n</html>\n'''
         

eric ide

mercurial