Skip to content

Commit dc2e52b

Browse files
committed
Merge feat/blog-truncate-hr: truncate 선행 구분선 건너뛰기 [skip-notion]
2 parents 18160be + 00eeac9 commit dc2e52b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

scripts/notion_to_md.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,14 @@ def _insert_truncate_marker(body):
685685
if "<!--truncate-->" in body:
686686
return body
687687
lines = body.split("\n")
688+
689+
def _skippable(line):
690+
stripped = line.strip()
691+
# 빈 줄·제목·구분선은 excerpt의 첫 콘텐츠로 취급하지 않는다
692+
return stripped == "" or bool(re.match(r"#{1,6}\s", line)) or re.fullmatch(r"-{3,}", stripped)
693+
688694
i = 0
689-
while i < len(lines) and (lines[i].strip() == "" or re.match(r"#{1,6}\s", lines[i])):
695+
while i < len(lines) and _skippable(lines[i]):
690696
i += 1
691697
if i >= len(lines):
692698
return body

scripts/tests/test_notion_to_md.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,13 @@ def test_image_as_first_content_block(self):
814814
assert "![image](/img/x.png)" in excerpt
815815
assert "본문 텍스트." not in excerpt
816816

817+
def test_leading_divider_skipped(self):
818+
# 제목 바로 뒤 구분선(---)은 콘텐츠로 취급하지 않고, 그 뒤 첫 문단이 excerpt에 포함
819+
body = "### **개요**\n\n---\n\n개발 과정에서 달마다 글을 작성하기로 했다.\n\n다음 문단.\n"
820+
excerpt, rest = self._split(body)
821+
assert "개발 과정에서 달마다 글을 작성하기로 했다." in excerpt
822+
assert "다음 문단." not in excerpt
823+
817824
def test_divider_not_treated_as_boundary(self):
818825
# section-break 구분선이 첫 문단보다 뒤에 있으면 excerpt는 첫 문단까지만
819826
body = "### 개요\n\n첫 문단.\n\n---\n\n### 다음 섹션\n내용\n"

0 commit comments

Comments
 (0)