Skip to content

Commit

Permalink
Merge pull request #2 from lbrealdev/pandoc-v1
Browse files Browse the repository at this point in the history
Pandoc v1
  • Loading branch information
lbrealdev authored Jun 17, 2024
2 parents 911b23e + 3203095 commit 01280dc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/md-to-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Pandoc - markdown to pdf
run-name: pandoc python converter
on:
workflow_dispatch:
inputs:
markdown-source-dir:
description: markdown input directory
required: true
type: string
upload-artifact:
description: upload or not
required: false
type: boolean

jobs:
md-to-pdf:
name: Pandoc - markdown to pdf
runs-on: ubuntu-latest
container:
image: pandoc/core:2.9
options: --cpus 1

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pypandoc
run: |
apk add python3 texmf-dist texlive
python3 --version
python3 -m pip install pypandoc
- name: Python converter
run: |
python3 converter.py ${{ inputs.markdown-source-dir }}
#- name: Run pandoc
# run: |
# pandoc README.md -o README.pdf

- name: Upload artifacts
if: inputs.upload-artifact
uses: actions/upload-artifact@v4
with:
name: pdf
path: test/_output


29 changes: 0 additions & 29 deletions .github/workflows/md2pdf.yml

This file was deleted.

26 changes: 14 additions & 12 deletions converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from pathlib import Path
# import pypandoc
import pypandoc


if len(sys.argv) < 2:
Expand Down Expand Up @@ -30,20 +30,22 @@
relative_path = markdown_file.relative_to(SOURCE_PATH_TO_MD)
pdf_output_path = DESTINATION_PATH_TO_PDF / relative_path.with_suffix(".pdf")

pdf_output_path.parent.mkdir(parents=True, exist_ok=True)
#pdf_output_path.touch(exist_ok=True)

source_md_files.append(markdown_file)
output_pdf_files.append(pdf_output_path)

try:
# pypandoc.convert_file(
# str(markdown_file),
# 'pdf',
# outputfile=str(pdf_file),
# extra_args=['--pdf-engine=pdflatex']
# )
pdf_output_path.parent.mkdir(parents=True, exist_ok=True)
pdf_output_path.touch(exist_ok=True)

source_md_files.append(markdown_file)
output_pdf_files.append(pdf_output_path)
pypandoc.convert_file(
str(markdown_file),
'pdf',
outputfile=str(pdf_output_path),
extra_args=['--pdf-engine=pdflatex']
)
except Exception as e:
print(f"Error converting {markdown_file}: {e}")
sys.exit(1)

print("Source markdown files:")
for input_md in source_md_files:
Expand Down

0 comments on commit 01280dc

Please sign in to comment.