Skip to main content
Inspiring
February 20, 2024
Question

Is there a way to run a report showing all cross-references I have in a project?

  • February 20, 2024
  • 3 replies
  • 231 views

I am using Rh 2022.3.93. Is there a way to run a report showing all cross-references I have in a project?

    This topic has been closed for replies.

    3 replies

    Peter Grainge
    Community Expert
    Community Expert
    February 21, 2024

    Thank you @WoutJacobs for that.

     

    RoboHelp uses cross references and hyperlinks. Am I reading you correctly that your script will find cross references but not hyperlinks? I ask as it might be important for someone finding this thread in the future.

    ________________________________________________________

    My site www.grainge.org includes many free Authoring and RoboHelp resources that may be of help.

     

     

    Use menu (bottom right) to mark as Best Answer or to Highlight particularly useful replies. Found the answer elsewhere? Share it here.
    Inspiring
    February 21, 2024

    Hi, that is correct.

    If you want a more fine-grained search however:

     

    # both hyperlinks and crossrefs have href attributes
    hyperlinks_and_crossrefs = soup.find_all('a', {'href': True})
    hyperlinks = []
    crossrefs = []
    
    for hyperlink_or_crossref in hyperlinks_and_crossrefs:
        
        # crossrefs have data-xref attribute
        if hyperlink_or_crossref.has_attr('data-xref'):
            crossrefs.append(hyperlink_or_crossref)
        # hyperlinks do not
        else:
            hyperlinks.append(hyperlink_or_crossref)
    
    
    

     

    Inspiring
    February 21, 2024

    If you know how to run a Python script (and install libraries) and only want to list the crossrefs:

     

    import os
    from bs4 import BeautifulSoup
    
    path_to_project = 'C:\\Users\\someone\\Documents\\GitHub\\Robohelp\\Projects\\Example_project\\contents'
    
    # Use the os.walk() function to traverse the directory and its subdirectories
    htm_files = []
    for root, dirs, files in os.walk(path_to_project):
        if '.rh' in dirs:
            dirs.remove('.rh')
        for file in files:
            if file.endswith('.htm'):
                # Get the absolute path of the .htm file
                absolute_path = os.path.abspath(os.path.join(root, file))
                htm_files.append(absolute_path)
    
    # perform action on each htm file
    for htm_file in htm_files:
        with open(htm_file, 'r', encoding='utf-8') as file:
            data = file.read()   
        soup = BeautifulSoup(data, 'html.parser')
    
        # find all crossrefs
        crossrefs = soup.find_all('a', {'data-xref': True})
    
        if crossrefs:
        	print('crossrefs in topic:', htm_file)
        	for crossref in crossrefs:
        		print(crossref['href'])
        	print('---')

     

    Community Expert
    February 20, 2024

    I don't think there's any built in way. If you have a friendly developer they can probably write a script to do it though.