]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/postprocess_html.py
Fix trailing spaces and split long Python lines
[lilypond.git] / buildscripts / postprocess_html.py
index f4c4797f988a67e218bbc4a54b7942cb868f08a3..98d49612247f4e52784efc1ac8b75ea0be77b6e3 100644 (file)
@@ -94,10 +94,13 @@ def build_pages_dict (filelist):
 def source_links_replace (m, source_val):
     return 'href="' + os.path.join (source_val, m.group (1)) + '"'
 
-splitted_docs_re = re.compile ('(input/lsr/out-www/lilypond-snippets|Documentation/user/out-www/(lilypond|music-glossary|lilypond-program|lilypond-learning))/')
+splitted_docs_re = re.compile ('(input/lsr/out-www/lilypond-snippets|\
+Documentation/user/out-www/(lilypond|music-glossary|lilypond-program|\
+lilypond-learning))/')
 
 snippets_ref_re = re.compile (r'href="(\.\./)?lilypond-snippets')
-user_ref_re = re.compile (r'href="(?:\.\./)?lilypond(-internals|-learning|-program|(?!-snippets))')
+user_ref_re = re.compile ('href="(?:[.][.])?lilypond\
+(-internals|-learning|-program|(?!-snippets))')
 
 ## Windows does not support symlinks.
 # This function avoids creating symlinks for splitted HTML manuals
@@ -177,13 +180,27 @@ def find_translations (prefix, lang_ext):
         if lang_ext != e:
             if e in pages_dict[prefix]:
                 available.append (l)
-            elif lang_ext == '' and l.enabled and reduce (operator.and_, [not prefix.startswith (s) for s in non_copied_pages]):
+            elif lang_ext == '' and l.enabled and reduce (operator.and_,
+                                                          [not prefix.startswith (s)
+                                                           for s in non_copied_pages]):
                 # English version of missing translated pages will be written
                 missing.append (e)
     return available, missing
 
-online_links_re = re.compile ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html|.png)(#[^"\']*|)[\'"]''')
-offline_links_re = re.compile ('''href=[\'"]([^/][.]*[^.:\'"]*)(.html)(#[^"\']*|)[\'"]''')
+online_links_re = re.compile ('''(href|src)=['"]([^/][.]*[^.:'"]*)\
+([.]html|[.]png)(#[^"']*|)['"]''')
+offline_links_re = re.compile ('''href=['"]([^/][.]*[^.:'"]*)([.]html)(#[^"']*|)['"]''')
+big_page_name_re = re.compile ('''(.+?)-big-page''')
+
+def process_i18n_big_page_links (match, prefix, lang_ext):
+    big_page_name = big_page_name_re.match (match.group (1))
+    if big_page_name:
+        destination_path = os.path.normpath (os.path.join (os.path.dirname (prefix),
+                                                           big_page_name.group (0)))
+        if not lang_ext in pages_dict[destination_path]:
+            return match.group (0)
+    return 'href="' + match.group (1) + '.' + lang_ext \
+        + match.group (2) + match.group (3) + '"'
 
 def process_links (s, prefix, lang_ext, file_name, missing, target):
     page_flavors = {}
@@ -196,7 +213,7 @@ def process_links (s, prefix, lang_ext, file_name, missing, target):
     elif target == 'offline':
         # in LANG doc index: don't rewrite .html suffixes
         # as not all .LANG.html pages exist;
-        # the doc index should be translated and contain the right links
+        # the doc index should be translated and contain links with the right suffixes
         if prefix == 'Documentation/out-www/index':
             page_flavors[file_name] = [lang_ext, s]
         elif lang_ext == '':
@@ -205,9 +222,18 @@ def process_links (s, prefix, lang_ext, file_name, missing, target):
                 page_flavors[langdefs.lang_file_name (prefix, e, '.html')] = \
                     [e, offline_links_re.sub ('href="\\1.' + e + '\\2\\3"', s)]
         else:
-            page_flavors[file_name] = \
-                [lang_ext,
-                 offline_links_re.sub ('href="\\1.' + lang_ext + '\\2\\3"', s)]
+            # For saving bandwidth and disk space, we don't duplicate big pages
+            # in English, so we must process translated big pages links differently.
+            if 'big-page' in prefix:
+                page_flavors[file_name] = \
+                    [lang_ext,
+                     offline_links_re.sub \
+                         (lambda match: process_i18n_big_page_links (match, prefix, lang_ext),
+                          s)]
+            else:
+                page_flavors[file_name] = \
+                    [lang_ext,
+                     offline_links_re.sub ('href="\\1.' + lang_ext + '\\2\\3"', s)]
     return page_flavors
 
 def add_menu (page_flavors, prefix, available, target, translation):
@@ -230,7 +256,6 @@ def add_menu (page_flavors, prefix, available, target, translation):
         if language_menu:
             language_available = t (lang_available) % language_menu
             languages = LANGUAGES_TEMPLATE % vars ()
-        # put language menu before '</body>' and '</html>' tags
         page_flavors[k][1] = add_footer (page_flavors[k][1], languages)
     return page_flavors
 
@@ -294,7 +319,7 @@ def process_html_files (package_name = '',
             ### add footer
             if footer_tag_re.search (s) == None:
                 s = add_footer (s, footer_tag + footer)
-                
+
                 available, missing = find_translations (prefix, lang_ext)
                 page_flavors = process_links (s, prefix, lang_ext, file_name, missing, target)
                 # Add menu after stripping: must not have autoselection for language menu.