diff --git a/Spec-template.docx b/Spec-template.docx index feaf0abee3803203dc4b0160dde7ff088e79d8bc..cf93ab990246578bfb08e998b64100570df19995 100644 Binary files a/Spec-template.docx and b/Spec-template.docx differ diff --git a/generateChangemarks/pandocFilter.py b/generateChangemarks/pandocFilter.py index 41b6ca57a29cd69e397036c6cafdf168119044b0..fdc00c9f899e325498f1fbf8cbbbefc48499598a 100644 --- a/generateChangemarks/pandocFilter.py +++ b/generateChangemarks/pandocFilter.py @@ -101,7 +101,7 @@ def replaceTableCaptions(progress:Progress, mdLines:list[str]) -> list[str]: def replaceFigureCaptions(progress:Progress, mdLines:list[str]) -> list[str]: - """ Replace table captions with a pandoc table caption. + """ Replace figure captions with a pandoc figure caption. """ _taskID = progress.add_task('[blue]Replacing figure captions', start=False, total=0) # progress.update() @@ -127,6 +127,25 @@ def replaceFigureCaptions(progress:Progress, mdLines:list[str]) -> list[str]: return _lines +def replaceLineBreaks(progress: Progress, mdLines: list[str]) -> list[str]: + """ Replace <br /> linebreaks by pandoc escaped_line_breaks extension \(newline). + """ + _taskID = progress.add_task('[blue]Replacing linebreaks', start=False, total=0) + # progress.update() + linebreaksregex = re.compile('<br />') + + _lines: list[str] = [] + for line in mdLines: + matches = re.findall(linebreaksregex, line) + if matches: + # Replace the linebreak with "\(newline)" + _lines.append(re.sub(r'<br />', f'\\\n', line)) + else: + _lines.append(line) + + progress.stop_task(_taskID) + return _lines + def process(document:str, outDirectory:str) -> None: with Progress(TextColumn('{task.description}'), TimeElapsedColumn()) as progress: @@ -134,6 +153,7 @@ def process(document:str, outDirectory:str) -> None: mdLines = correctTOC(progress, mdLines) mdLines = replaceTableCaptions(progress, mdLines) mdLines = replaceFigureCaptions(progress, mdLines) + mdLines = replaceLineBreaks(progress, mdLines) writeMDFile(progress, mdLines, document, outDirectory) def main(args=None): diff --git a/publish_spec.sh b/publish_spec.sh index 46c7d50324ecfdf98a32c29571ba1704bebaff77..c89d8c55b0be158a08b72a0814deb9db964557c5 100755 --- a/publish_spec.sh +++ b/publish_spec.sh @@ -34,7 +34,7 @@ for i in *.md ; do echo "\n------ Preparaing spec --------" docker run --rm -v $(pwd):/tmp/ -u $(id -u):$(id -g) "$TOOLS_DOCKER_IMAGE" pandocFilter -o "/tmp/" "/tmp/$i" echo "\n------ Publishing spec --------" - docker run --rm -v $(pwd):/data -u $(id -u):$(id -g) "$DOCKER_IMAGE" "/data/$i" -f markdown -t docx --reference-doc "/data/${3}" -o "${4}_${2}.docx" + docker run --rm -v $(pwd):/data -u $(id -u):$(id -g) "$DOCKER_IMAGE" "/data/$i" -f markdown+escaped_line_breaks -t docx --reference-doc "/data/${3}" -o "${4}_${2}.docx" fi done