summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorGabor Kelemen <kelemeng@gnome.hu>2016-10-12 14:39:16 +0200
committerAndras Timar <andras.timar@collabora.com>2016-10-12 12:57:38 +0000
commit75f5e0c62da711669d59f572c217b66a3f791b23 (patch)
treeef3208d464935b01eeba3aa0d960f0ee6f9f748d /helpers
parentd0edb8833eae3f76869e8718c380e491f1d23419 (diff)
Script to check the validity of embed tags
This script looks up <embed ...> tags in helpcontent, checks whether the referenced file and id exist, and prints a warning if either one does not. Execute from the root directory of the helpcontent2 repository. No parameters are used. Change-Id: Ic20bcfb1db398067231141b9af69c45590e1d452 Reviewed-on: https://gerrit.libreoffice.org/29732 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'helpers')
-rwxr-xr-xhelpers/find-invalid-help-embeds.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/helpers/find-invalid-help-embeds.sh b/helpers/find-invalid-help-embeds.sh
new file mode 100755
index 0000000000..5c70fd5124
--- /dev/null
+++ b/helpers/find-invalid-help-embeds.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This script looks up <embed ...> tags in helpcontent, checks whether the
+# referenced file and id exist, and prints a warning if either one does not.
+# Execute from the root directory of the helpcontent2 repository.
+# No parameters are used.
+
+# Example output of this git grep:
+# source/text/sbasic/shared/03010000.xhp: <embed href="text/sbasic/shared/03010300.xhp#farbe"/>
+lines=$(git grep "embed href=" source/);
+
+while read nextline ; do
+ # source file is before the first :
+ sourcefile=${nextline%%:*};
+ # There may be more than one <embed ...> in one line, split it up,
+ # but first cut off everything before the first <embed
+ # and anything after the last >
+ processline="<embed${nextline#*<embed}";
+ processline="${processline%>*}>";
+ while [ -n "$processline" ] ; do
+ # Start processing the first xml tag
+ target=$(expr "$processline" : '\(<[^>]*>\)');
+ # Check if there is an <embed at the beginning
+ if [ $(expr "$target" : "<embed") -ne "0" ] ; then
+ # Get the embedded filename#section part
+ target=${target#*\"};
+ target=${target%\"*};
+ # target file is before the #
+ targetfile=${target%#*};
+ # target section is after the #
+ targetsection=${target#*#};
+ # does the target file exist?
+ if [ -f "source/$targetfile" ] ; then
+ # The target file exist, does the section inside the target file too?
+ grep -q "id=\"$targetsection\">" source/"$targetfile";
+ if [ "$?" -ne "0" ] ; then
+ echo "$sourcefile: In 'source/$targetfile' there is no section called '$targetsection'";
+ fi
+ else
+ # target file does not exist
+ echo "$sourcefile: Embedded target file 'source/$targetfile' does not exist!" ;
+ fi
+ fi
+ # Remove the first xml tag from the parts still to be processed
+ processline=${processline#<*>};
+ # There may be characters after this, i.e. "foo <embed ...>"
+ if [ -n "$processline" ] ; then
+ processline="<${processline#*<}";
+ fi
+ done
+done <<< "$lines"