Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gitlab_cicd_practice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WebSystem
gitlab_cicd_practice
Commits
815edd1d
Commit
815edd1d
authored
1 month ago
by
장명현
Browse files
Options
Downloads
Patches
Plain Diff
파일 변환 코드(python) 및 pipeline 추가
parent
6b978716
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#11352
skipped
Stage: convert
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+20
-0
20 additions, 0 deletions
.gitlab-ci.yml
MDtoHTML.py
+67
-0
67 additions, 0 deletions
MDtoHTML.py
with
87 additions
and
0 deletions
.gitlab-ci.yml
0 → 100644
+
20
−
0
View file @
815edd1d
stages
:
-
convert
convert_modified_md
:
stage
:
convert
image
:
python:3.11
script
:
-
pip install markdown playwright
-
playwright install chromium
# 🔍 1. 수정된 .md 파일 찾기 (커밋 기준)
-
|
for file in $(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep '\.md$'); do
echo "변환 중: $file"
python MDtoPDF.py "$file"
done
artifacts
:
paths
:
-
"
*.pdf"
-
"
*.html"
when
:
manual
# 선택: 필요할 때만 실행
This diff is collapsed.
Click to expand it.
MDtoHTML.py
0 → 100644
+
67
−
0
View file @
815edd1d
### pip install markdown playwright
### playwright install chromium
import
os
import
sys
import
markdown
import
asyncio
from
playwright.async_api
import
async_playwright
# 0. Markdown 파일 이름 탐색
md_filename
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
"
sample.md
"
print
(
f
"
전달받은 파일:
{
md_filename
}
"
)
basename
,
_
=
os
.
path
.
splitext
(
md_filename
)
html_filename
=
f
"
{
basename
}
.html
"
pdf_filename
=
f
"
{
basename
}
.pdf
"
# 1. 기존 html, pdf 파일 삭제
for
f
in
[
html_filename
,
pdf_filename
]:
if
os
.
path
.
exists
(
f
):
os
.
remove
(
f
)
# 2. Markdown → HTML 변환
with
open
(
md_filename
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
md_file
:
md_content
=
md_file
.
read
()
html_content
=
markdown
.
markdown
(
md_content
,
extensions
=
[
"
fenced_code
"
,
"
codehilite
"
])
# 3. HTML 파일로 저장 (간단한 HTML 템플릿 포함)
full_html
=
f
"""
<!DOCTYPE html>
<html lang=
"
en
"
>
<head>
<meta charset=
"
UTF-8
"
>
<title>
{
basename
}
</title>
<link rel=
"
stylesheet
"
href=
"
https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css
"
>
<style>
body {{ font-family: sans-serif; max-width: 800px; margin: auto; padding: 2rem; }}
pre code {{ background: #f5f5f5; padding: 1rem; display: block; overflow-x: auto; }}
h1, h2, h3 {{ border-bottom: 1px solid #ddd; padding-bottom: 0.3em; }}
</style>
</head>
<body>
{
html_content
}
</body>
</html>
"""
# 4. HTML 저장
with
open
(
html_filename
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
html_file
:
html_file
.
write
(
full_html
)
print
(
f
"
HTML 변환 완료:
{
html_filename
}
"
)
# 5. 경로 추적 및 HTML → PDF 변환
async
def
html_to_pdf
(
input_html
,
output_pdf
):
abs_path
=
os
.
path
.
abspath
(
input_html
).
replace
(
"
\\
"
,
"
/
"
)
url
=
"
file:///
"
+
abs_path
async
with
async_playwright
()
as
p
:
browser
=
await
p
.
chromium
.
launch
()
page
=
await
browser
.
new_page
()
await
page
.
goto
(
url
)
await
page
.
pdf
(
path
=
output_pdf
,
format
=
"
A4
"
)
await
browser
.
close
()
print
(
f
"
PDF 저장 완료:
{
output_pdf
}
"
)
asyncio
.
run
(
html_to_pdf
(
html_filename
,
pdf_filename
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment