Copy link to clipboard
Copied
I am using Rh 2022.3.93. Is there a way to run a report showing all cross-references I have in a project?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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('---')
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)