From 334a73686be944c3d5137b142bdcfa89b2312150 Mon Sep 17 00:00:00 2001 From: Ron Stone Date: Wed, 1 Nov 2023 11:44:09 +0000 Subject: [PATCH] Hide empty rows (r8, r7, r6, r5) Strip empty rows from HTML output tables. Max width 10 columns. |hide-empty-rows| must be present in corresponding rst file. This is a post-build clean-up step for tables with conditional content that renders as empty rows. Signed-off-by: Ron Stone Change-Id: Ia65cc0a945d0ed8955c2a5d9bb68649d2280d27d --- doc/source/shared/strings.txt | 7 ++++++ hide-empty-rows.sh | 40 +++++++++++++++++++++++++++++++++++ tox.ini | 3 +++ 3 files changed, 50 insertions(+) create mode 100755 hide-empty-rows.sh diff --git a/doc/source/shared/strings.txt b/doc/source/shared/strings.txt index b0a73cf63..85cde0108 100644 --- a/doc/source/shared/strings.txt +++ b/doc/source/shared/strings.txt @@ -67,3 +67,10 @@ .. |optional| replace:: **Optional step:** + +.. Flag to mark an output html file for post-build step to hide empty rows + in tables. This is mostly useful where some rows are conditionalized. + +.. |hide-empty-rows| raw:: html + + \ No newline at end of file diff --git a/hide-empty-rows.sh b/hide-empty-rows.sh new file mode 100755 index 000000000..ddd301a0a --- /dev/null +++ b/hide-empty-rows.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# strip empty rows from HTML output tables. Max width 10 columns. +# |hide-empty-rows| must be present in corresponding rst file. + +. $(pwd)/_utils.sh +if [[ -z ${utils_loaded+x} ]]; then echo "Could not load utilities"; exit 1; fi + +if [ "$#" -ne 1 ]; then + error "Usage: $0 " +elif [[ ! -e "$1" ]]; then + error "$0: Directory \"$1\" not found" +fi + +declare htmlPath=$1 +declare flag="post-build-hide-empty-table-rows" +declare td="\n*[\n\s]*\n*" +declare td_p=${td} + +message "Cleaning up empty table rows in flagged files" + +declare flagged_files=( $(grep -rl --include="*.html" "${flag}" ${htmlPath}) ) + +for _html in ${flagged_files[@]}; do + + confirmation "... $_html" + + sed -i -E -e ':a;N;$!ba;s/\n(<\/tr>)/\1/g' ${_html} + sed -i -E -e ':a;N;$!ba;s/\n(<\/td>+)(<\/tr>)/\1\2/g' ${_html} + + # sed has no non-greedy mode + for i in {1..10}; do + sed -i -E "s:^${td_p}::g" ${_html} + td_p="$td_p$td" + done + + # sed -i -E "s:^(+)():\1\2:g" ${_html} +done + +confirmation "... Done" \ No newline at end of file diff --git a/tox.ini b/tox.ini index 6c3aa1e3f..5d749b42c 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,7 @@ commands = git clean -dfx doc/source/fault-mgmt/ git restore doc/source/dist_cloud/kubernetes/* bash hw-updates.sh + bash hide-empty-rows.sh doc/build/html bash htmlChecks.sh doc/build/html [testenv:docs] @@ -39,6 +40,7 @@ commands = {[testenv:postbuild-docs]commands} # Note: The dev env for the docs team uses a version of tox that does not yet support allowlist_externals whitelist_externals = bash + hide-empty-rows.sh htmlChecks.sh get-remote-files.sh git @@ -53,6 +55,7 @@ commands = sphinx-build -a -E -W --keep-going -d doc/build/doctrees -t starlingx -t openstack -b singlehtml doc/source doc/build/singlepage {posargs} {[testenv:postbuild-docs]commands} whitelist_externals = bash + hide-empty-rows.sh htmlChecks.sh get-remote-files.sh git