Last active
March 17, 2025 23:02
-
-
Save jhradilek/3757ab7c380e4ddfdaef7dc6e3b68dbd to your computer and use it in GitHub Desktop.
Look up DITA 1.3 elements in the documentation online
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ditahelp.sh - look up DITA 1.3 elements in the documentation online | |
# Copyright (C) 2024 Jaromir Hradilek <[email protected]> | |
# This program is free software: you can redistribute it and/or modify it | |
# under the terms of the GNU General Public License as published by the | |
# Free Software Foundation, version 3 of the License. | |
# | |
# This program is distributed in the hope that it will be useful, but | |
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTA- | |
# BILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
# License for more details. | |
# | |
# You should have received a copy of the GNU General Public License along | |
# with this program. If not, see <http://www.gnu.org/licenses/>. | |
# CLI Usage: | |
# | |
# ditahelp.sh ELEMENT_NAME | |
# | |
# Configure Vim to look up keywords under the cursor with 'K': | |
# | |
# au FileType dita* set keywordprg=ditahelp.sh | |
# Set the URL to the DITA 1.3 element reference page: | |
declare -r docs='https://docs.oasis-open.org/dita/dita/v1.3/errata02/os/complete/part3-all-inclusive/langRef/quick-reference/all-elements-a-to-z.html' | |
# Determine the link to the supplied element definition: | |
declare -r link=$(curl -sv "$docs" 2>/dev/null | xmllint --html --xpath "string(//a[normalize-space()=\"$1\"]/@href)" - 2>/dev/null) | |
# Terminate the script if no element definition is found: | |
if [[ -z "$link" ]]; then | |
echo "${0##*/}: No documentation for element '$1'" >&2 | |
exit | |
fi | |
# Open the element definition in a web browser: | |
firefox "${docs%/*}/$link" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment