Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Participant ,
Feb 20, 2024 Feb 20, 2024

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

163
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2024 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2024 Feb 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('---')

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2024 Feb 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.

 

 

Help others by clicking Correct Answer if the question is answered. Found the answer elsewhere? Share it here. "Upvote" is for useful posts.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2024 Feb 21, 2024
LATEST

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)


 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
RoboHelp Documentation
Download Adobe RoboHelp