Commit bb5de7bf authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Support to convert all svg figures to png for pandoc conversion

parent 53205db2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ Build pythonForPandocFilter docker image:
        - generateChangemarks/changemarks.py
        - generateChangemarks/addTrackedChanges.py
        - generateChangemarks/generateTOC.py
        - generateChangemarks/svg2png.py

Build Pandoc docker image:
  stage: build
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ FROM python:3.9-slim-bullseye

ADD . /generateChangemarks/
RUN apt-get update -y && \
    apt-get install -y libcairo2 && \
    rm -rf /var/lib/apt/lists/* &&\
    pip install -e generateChangemarks/ &&\
	pip install -r generateChangemarks/requirements.txt
+1 −1
Original line number Diff line number Diff line
FROM pandoc/core:3-ubuntu
FROM pandoc/core:3.4.0-ubuntu

RUN apt-get update -y && \
    apt-get install -y npm &&\
+21 −0
Original line number Diff line number Diff line
@@ -127,6 +127,26 @@ def replaceFigureCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
	return _lines


def replaceFiguresPathSvgToPng(progress: Progress, mdLines: list[str]) -> list[str]:
	"""	Replace figure extensions from svg to png.
	"""
	_taskID = progress.add_task('[blue]Replacing figure captions', total=0)
	# progress.update()
	figurePathRegex = re.compile('media\/.*\.svg')

	_lines: list[str] = []
	for line in mdLines:
		matches = re.findall(figurePathRegex, line)
		if matches:
			# Replace figure path to png
			_lines.append(re.sub(r'\.svg', f'.png', line))
		else:
			_lines.append(line)

	progress.stop_task(_taskID)
	return _lines


def replaceLineBreaks(progress: Progress, mdLines: list[str]) -> list[str]:
	"""	Replace <br /> linebreaks by pandoc escaped_line_breaks extension \(newline).
	"""
@@ -162,6 +182,7 @@ def process(document:str, outDirectory:str) -> None:
		mdLines = correctTOC(progress, mdLines)
		mdLines = replaceTableCaptions(progress, mdLines)
		mdLines = replaceFigureCaptions(progress, mdLines)
		mdLines = replaceFiguresPathSvgToPng(progress, mdLines)
		mdLines = replaceLineBreaks(progress, mdLines)
		writeMDFile(progress, mdLines, document, outDirectory)

+2 −1
Original line number Diff line number Diff line
@@ -16,3 +16,4 @@ rich==13.4.2
    # via oneM2M-markdown-to-pandoc-filter (setup.py)
requests==2.31.0
unidiff==0.7.5
cairosvg==2.7.1
 No newline at end of file
Loading