VirtualBox

Changeset 86895 in vbox


Ignore:
Timestamp:
Nov 16, 2020 4:46:13 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Hijacking qHelp's keyword functionality for context senstive help navigation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/htmlhelp-qthelp.py

    r86707 r86895  
    1212import codecs
    1313import logging
     14from HTMLParser import HTMLParser
    1415
    1516__copyright__ = \
     
    2930# number of opened and not yet closed section tags of toc section
    3031open_section_tags = 0
     32
     33html_files = []
     34
     35class html_parser(HTMLParser):
     36  def __init__(self):
     37    HTMLParser.__init__(self)
     38    self.a_tag=[]
     39
     40  def handle_starttag(self, tag, attributes):
     41    if tag != 'div' and tag != 'a':
     42        return
     43    if tag == 'a':
     44        for a in attributes:
     45            if a[0] == 'name':
     46                self.a_tag.append(a[1])
     47
     48# use html_parser stuff to collect <a name tags
     49def create_keywords_section(folder):
     50    keywords_section_lines = ['<keywords>']
     51    for html_file_name in html_files:
     52        full_html_path = os.path.join(folder, html_file_name)
     53        file_content = open(full_html_path, 'r').read()
     54        parser = html_parser()
     55        parser.feed(file_content)
     56        for k in parser.a_tag:
     57            line = '<keyword name="' + k + '" id="' + k + '" ref="' + html_file_name + '#' + k + '"/>'
     58            keywords_section_lines.append(line);
     59    keywords_section_lines.append('</keywords>')
     60    return keywords_section_lines
    3161
    3262# find the png files under /images folder and create a part of the
     
    4979# open htmlhelp.hhp files and read the list of html files from there
    5080def create_html_list(folder):
     81    global html_files
    5182    file_name = 'htmlhelp.hhp'
    52     html_files_list = []
     83    html_file_lines = []
    5384    if not file_name in os.listdir(folder):
    5485        logging.error('Could not find the file "%s" in "%s"', file_name, folder)
    55         return html_files_list
     86        return html_file_lines
    5687    full_path = os.path.join(folder, 'htmlhelp.hhp')
    5788    file = open(full_path, "r")
     
    6798            continue
    6899        if '.html' in line:
    69             html_files_list.append('<file>' + line.strip('\n') + '</file>')
    70     return html_files_list
     100            html_file_lines.append('<file>' + line.strip('\n') + '</file>')
     101            html_files.append(line.strip('\n'))
     102    return html_file_lines
    71103
    72104
     
    142174    return result
    143175
    144 # parse toc.hhc file. assuming all the relevant informations
     176# parse toc.hhc file. assuming all the relevant information
    145177# is stored in tags and attributes. data "whatever is outside of
    146178# <... > pairs is filtered out. we also assume < ..> are not nested
    147179# and each < matches to a >
    148 def parse_toc(folder):
     180def create_toc(folder):
    149181    toc_file = 'toc.hhc'
    150182    content = [x[2] for x in os.walk(folder)]
     
    224256                     '<virtualFolder>doc</virtualFolder>', \
    225257                     '<filterSection>']
    226     out_xml_lines += parse_toc(helphtmlfolder) + create_files_section(helphtmlfolder)
     258    out_xml_lines += create_toc(helphtmlfolder) + create_files_section(helphtmlfolder)
     259    out_xml_lines += create_keywords_section(helphtmlfolder)
    227260    out_xml_lines += ['</filterSection>', '</QtHelpProject>']
    228261
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette