diff --git a/docs/bash_helper_functions b/docs/bash_helper_functions
index c204a69f4..ed6dd2a8a 100755
--- a/docs/bash_helper_functions
+++ b/docs/bash_helper_functions
@@ -32,7 +32,10 @@ git_logs_as_xml()
# What paths to include in the logs
local paths="../dlib ../examples ../tools ../python_examples"
- (echo ""; git log --stat=80 --date=iso-strict --pretty=format:"%n%n%an%n%ad%n%s%n%n" $logrange $paths | tail -n+2 ; echo; echo '' ; echo "" ) > $outfile
+ (echo ""; git log --stat=80 --date=iso-strict --pretty=format:"%n%n%an%n%ad%nGIT_COMMIT_MESSAGE_BEGIN%sGIT_COMMIT_MESSAGE_END%n%n" $logrange $paths | tail -n+2 ; echo; echo '' ; echo "" ) > $outfile
+
+ # sanitize git commit messages
+ sed -e '/GIT_COMMIT_MESSAGE_BEGIN.*GIT_COMMIT_MESSAGE_END/ { s/\</g; s/>/\>/g; s/GIT_COMMIT_MESSAGE_BEGIN//g; s/GIT_COMMIT_MESSAGE_END/<\/msg>/g; }' -i $outfile
# trim whitespace at start and end of tags.
sed -e ':a' -e 'N' -e '$!ba' -e "s/[ \n]*/ /g" -e "s/[ \n]*<\/files_changed>/<\/files_changed>/g" -i $outfile