parameters: (pages_dict,
                         package_name='',
                         package_version='',
                         target='offline')
docstring: Add header, footer, syntax highlighting toggle, and tweak links
      to a number of HTML files.
  
      Arguments:
       pages_dict:               dict of filename => translations
       package_name=NAME         set package_name to NAME
       package_version=VERSION   set package version to VERSION
       targets=offline|online    set page processing depending on the target
            offline is for reading HTML pages locally
            online is for hosting the HTML pages on a website with content
              negotiation
docstring_summary: Add header, footer, syntax highlighting toggle, and tweak links
      to a number of HTML files.
docstring_tokens: Add header footer syntax highlighting toggle and tweak links to a number of HTML files .
function: def process_html_files(pages_dict,
                         package_name='',
                         package_version='',
                         target='offline'):
      """Add header, footer, syntax highlighting toggle, and tweak links
      to a number of HTML files.
  
      Arguments:
       pages_dict:               dict of filename => translations
       package_name=NAME         set package_name to NAME
       package_version=VERSION   set package version to VERSION
       targets=offline|online    set page processing depending on the target
            offline is for reading HTML pages locally
            online is for hosting the HTML pages on a website with content
              negotiation
      """
      versiontup = package_version.split('.')
      branch_str = _doc('stable-branch')
      if int(versiontup[1]) % 2:
          branch_str = _doc('development-branch')
  
      en_dict = {
          'package_name': package_name,
          'package_version': package_version,
          'branch_str': branch_str,
          'help_us_url': 'https://lilypond.org/help-us.html',
          'bug_lilypond_url': 'https://lists.gnu.org/mailman/listinfo/bug-lilypond',
          'footer_name_version':  _doc ('This page is for %(package_name)s-'
                                        '%(package_version)s (%(branch_str)s).'),
          'footer_report_links': _doc ('We welcome your aid; please '
                                       '<a href="%(help_us_url)s">help us</a> by '
                                       'reporting errors to our '
                                       '<a href="%(bug_lilypond_url)s">bug list</a>.'),
      }
  
      # language => (dict of str => str)
      subst = {
          '': en_dict,
      }
      for l in langdefs.translation:
          e = langdefs.LANGDICT[l].webext
          if e:
              subst[e] = {
                  name: langdefs.translation[l](en_dict[name])
                  for name in en_dict}
  
      # Do deeper string formatting as early as possible,
      # so only one '%' formatting pass is needed later
      for e in subst:
          for k in ['footer_name_version', 'footer_report_links']:
              subst[e][k] = subst[e][k] % subst[e]
  
      for prefix, ext_list in list(pages_dict.items()):
          for lang_ext in ext_list:
              file_name = langdefs.lang_file_name(prefix, lang_ext, '.html')
              dest_time = 0
  
              content = open(file_name, 'r', encoding='utf-8').read()
              content = content.replace('%', '%%')
  
              # add sidebar information
              content = content.replace('<!-- Sidebar Version Tag  -->', sidebar_version)
  
              available = find_translations(pages_dict, prefix, lang_ext)
              page_flavors = process_links(pages_dict,
                                           content, prefix, lang_ext, file_name, target)
              # Add menu after stripping: must not have autoselection for language menu.
              page_flavors = add_menu(
                  page_flavors, prefix, available, target, langdefs.translation)
  
              for k in page_flavors:
                  page_flavors[k][1] = page_flavors[k][1] % subst[page_flavors[k][0]]
  
                  # Must write to tmp file to avoid touching hardlinked files.
                  out_f = open(k + ".tmp", 'w', encoding='utf-8')
                  out_f.write(page_flavors[k][1])
                  out_f.close()
                  os.rename(k + ".tmp", k)
  
          # if the page is translated, a .en.html symlink is necessary for content negotiation
          if target == 'online' and ext_list != [''] and not os.path.lexists(prefix + '.en.html'):
              os.symlink(os.path.basename(prefix) + '.html', prefix + '.en.html')
function_tokens: def process_html_files ( pages_dict , package_name = '' , package_version = '' , target = 'offline' ) : versiontup = package_version . split ( '.' ) branch_str = _doc ( 'stable-branch' ) if int ( versiontup [ 1 ] ) % 2 : branch_str = _doc ( 'development-branch' ) en_dict = { 'package_name' : package_name , 'package_version' : package_version , 'branch_str' : branch_str , 'help_us_url' : 'https://lilypond.org/help-us.html' , 'bug_lilypond_url' : 'https://lists.gnu.org/mailman/listinfo/bug-lilypond' , 'footer_name_version' : _doc ( 'This page is for %(package_name)s-' '%(package_version)s (%(branch_str)s).' ) , 'footer_report_links' : _doc ( 'We welcome your aid; please ' '<a href="%(help_us_url)s">help us</a> by ' 'reporting errors to our ' '<a href="%(bug_lilypond_url)s">bug list</a>.' ) , } # language => (dict of str => str) subst = { '' : en_dict , } for l in langdefs . translation : e = langdefs . LANGDICT [ l ] . webext if e : subst [ e ] = { name : langdefs . translation [ l ] ( en_dict [ name ] ) for name in en_dict } # Do deeper string formatting as early as possible, # so only one '%' formatting pass is needed later for e in subst : for k in [ 'footer_name_version' , 'footer_report_links' ] : subst [ e ] [ k ] = subst [ e ] [ k ] % subst [ e ] for prefix , ext_list in list ( pages_dict . items ( ) ) : for lang_ext in ext_list : file_name = langdefs . lang_file_name ( prefix , lang_ext , '.html' ) dest_time = 0 content = open ( file_name , 'r' , encoding = 'utf-8' ) . read ( ) content = content . replace ( '%' , '%%' ) # add sidebar information content = content . replace ( '<!-- Sidebar Version Tag  -->' , sidebar_version ) available = find_translations ( pages_dict , prefix , lang_ext ) page_flavors = process_links ( pages_dict , content , prefix , lang_ext , file_name , target ) # Add menu after stripping: must not have autoselection for language menu. page_flavors = add_menu ( page_flavors , prefix , available , target , langdefs . translation ) for k in page_flavors : page_flavors [ k ] [ 1 ] = page_flavors [ k ] [ 1 ] % subst [ page_flavors [ k ] [ 0 ] ] # Must write to tmp file to avoid touching hardlinked files. out_f = open ( k + ".tmp" , 'w' , encoding = 'utf-8' ) out_f . write ( page_flavors [ k ] [ 1 ] ) out_f . close ( ) os . rename ( k + ".tmp" , k ) # if the page is translated, a .en.html symlink is necessary for content negotiation if target == 'online' and ext_list != [ '' ] and not os . path . lexists ( prefix + '.en.html' ) : os . symlink ( os . path . basename ( prefix ) + '.html' , prefix + '.en.html' )