From 3e1bcdc70ea05662f776e7b821ae540669f3a5f7 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Tue, 24 May 2016 13:19:25 +0200 Subject: [PATCH] Fix dangling anchor check. --- Documentation/Books/Makefile | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Documentation/Books/Makefile b/Documentation/Books/Makefile index 09931fa579..7318dcbc89 100644 --- a/Documentation/Books/Makefile +++ b/Documentation/Books/Makefile @@ -93,8 +93,15 @@ book-check-markdown-leftovers: fi book-check-dangling-anchors: - @echo "##### checking for dangling anchors in $(NAME)" - @grep -R "a href.*#" books/$(NAME) | \ + @echo "##### checking for dangling anchors" + for htmlf in `find books/ -name \*.html `; do \ + fn=`basename $${htmlf}` ; \ + dir=`echo $$htmlf |sed "s;/$$fn;;"`; \ + mkdir -p /tmp/tags/$${dir}; \ + cat $${htmlf} |grep ' /tmp/tags/$${dir}/$${fn}; \ + done + + @grep -R "a href.*#" books/ | \ egrep -v "(styles/header\.js|/app\.js|class=\"navigation|https*://|href=\"#\")" | \ sed 's;\(.*\.html\):.*a href="\(.*\)#\(.*\)">.*.*;\1,\2,\3;' | grep -v " " > /tmp/anchorlist.txt @@ -110,18 +117,23 @@ book-check-dangling-anchors: FN="$${SFNP}/$${FN}"; \ fi; \ if test -n "$$ANCHOR"; then \ - if grep -q "id=\"$$ANCHOR\">" $$FN; then \ - /bin/true; \ - else \ - echo "$$i"; \ - NO=$$((NO + 1)); \ - fi; \ + if test ! -f /tmp/tags/$${FN}; then \ + echo "File referenced by $${i} doesn't exist."; \ + NO=$$((NO + 1)); \ + else if grep -q "^$$ANCHOR$$" /tmp/tags/$$FN; then \ + /bin/true; \ + else \ + echo "Anchor not found in $$i"; \ + NO=$$((NO + 1)); \ + fi; \ + fi; \ fi; \ done; \ if test "$${NO}" -gt 0; then \ echo "$${NO} Dangling anchors found!"; \ exit 1; \ fi + rm -rf /tmp/anchorlist.txt /tmp/tags build-book-symlinks: echo "##### generate backwards compatibility symlinks for $(NAME)" @@ -275,4 +287,5 @@ build-books: done make check-docublocks + make book-check-dangling-anchors echo '' > books/index.html