diff --git a/.ci/create-changes-html.sh b/.ci/create-changes-html.sh index 2cca91d81c8..0e80d0d2814 100755 --- a/.ci/create-changes-html.sh +++ b/.ci/create-changes-html.sh @@ -1,11 +1,12 @@ #!/bin/sh if [ $# != 2 ]; then - echo >&2 "usage: $0 BASE_DOC_COMMIT DOC_REPO" - echo >&2 "creates CHANGES.html in the current directory" - echo >&2 "for the diffs of DOC_REPO against BASE_DOC_COMMIT" + echo >&2 "Usage: $0 DIFF_TEXT DOC_REPO" + echo >&2 "This script generates a CHANGES.html file in the current directory" + echo >&2 "and adds anchor targets in the documents within DOC_REPO" + echo >&2 "based on the diff hunks in the DIFF_TEXT file." exit 1 fi -BASE_DOC_COMMIT="$1" +DIFF_TEXT="$1" DOC_REPOSITORY="$2" # Create CHANGES.html @@ -52,11 +53,10 @@ diffParagraphs.forEach(paragraph => { EOF echo '' >> CHANGES.html echo '
' >> CHANGES.html -(cd $DOC_REPOSITORY && git diff $BASE_DOC_COMMIT -- "*.html") > diff.txt python3 - << EOF import os, re, html from itertools import chain -with open('diff.txt', 'r') as f: +with open('$DIFF_TEXT', 'r') as f: diff_text = f.read() diff_blocks = re.split(r'^(?=diff --git)', diff_text, flags=re.MULTILINE) out_blocks = [] @@ -83,12 +83,21 @@ for block in diff_blocks: hunk_lines = [] search_result = re.search(r'@@ -(\d+),(\d+) \+(\d+),(\d+)', line) if search_result: - line_number = int(search_result.group(3)) + line_number = int(search_result.group(3)) - 1 span = int(search_result.group(4)) for i in chain(range(line_number, line_number + span), range(line_number - 1, -1, -1)): - if content[i].startswith('<') and not content[i].startswith(''): + try: + ln = content[i] + except IndexError: + continue + for idx, char in enumerate(ln): + if not char.isspace(): + break + else: + idx = len(ln) + if ln.startswith('<', idx) and not ln.startswith('', idx): count += 1 - content[i] = f'' + content[i] + content[i] = ln[:idx] + f'' + ln[idx:] hunks.append(f'') break hunk_lines.append(line) @@ -107,4 +116,4 @@ EOF cat diff.html >> CHANGES.html echo '' >> CHANGES.html echo '