fix: 산문 칸의 문단과 인라인 코드를 읽어서 그린다
Case 만 블록 파서를 타고 나머지 유형은 문자열을 그대로 내보내고 있었다.
그래서 두 가지가 깨졌다.
작성자가 백틱으로 적은 식별자가 백틱째 화면에 나왔다. 어떤 Reference 는
한 문서에 백틱이 32개였고, 그 원문이 홈 카드·탐색 카드·검색 결과까지
그대로 퍼졌다. 판단 기준은 `<p>{rule.body}</p>` 로, 적용할 때·예외·예시는
`<li>{item.text}</li>` 로 아무것도 거치지 않고 나가고 있었다.
빈 줄로 나눈 문단이 문단으로 보이지 않았다. 어제 넣은 PlainText 는 모든
줄바꿈을 <br> 로 만들었기 때문에 빈 줄도 <br><br> 로 나갔고, 문단 사이
여백이 없었다. Reference 7개 전부에 빈 줄이 9~16개 있다.
ProseText 로 바꾼다 — 빈 줄은 문단을 가르고, 문단 안 줄바꿈은 그 자리에
지키고, 백틱은 코드로 읽는다. 백틱 수가 홀수면 원문을 그대로 둔다:
작성자가 백틱 자체를 쓴 것일 수 있고, 반쯤 해석해 한쪽만 코드로 만드는
쪽이 더 나쁘다.
블록 파서(parseCaseContent)를 쓰지 않는 이유는 그쪽이 Case 전용 문법과
도식 참조까지 물고 있어 이 칸들에 없는 해석기를 끌고 오기 때문이다.
머리말 가드는 <br> 개수로 재고 있었다. 이제 기준이 문단이므로 문단 수와
문단 안 줄바꿈을 함께 확인하도록 고친다 — 가드가 낡은 것이지 화면이
틀린 것이 아니다.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ
This commit is contained in:
co-authored by
Claude Opus 5
parent
f846f51020
commit
9b7ad82fe3
@@ -86,13 +86,21 @@ describe("문서 머리말의 요약", () => {
|
||||
nextValidation: "",
|
||||
};
|
||||
|
||||
it("작성자가 나눈 문단을 지킨다", () => {
|
||||
it("빈 줄은 문단으로, 문단 안 줄바꿈은 줄바꿈으로 그린다", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<PublicDocumentHeader record={record} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
// 줄바꿈 셋(빈 줄 포함) → <br> 셋. 그대로 넣으면 0개가 되어 한 줄로 읽힌다.
|
||||
expect(container.querySelectorAll(".public-document-header > p br")).toHaveLength(3);
|
||||
/*
|
||||
요약은 "두 줄 + 빈 줄 + 한 줄" 이다. 예전에는 셋 다 <br> 로 나가서 문단 사이 여백이
|
||||
없었다. 지금은 빈 줄이 문단을 가르고, 문단 안의 줄바꿈만 <br> 로 남는다.
|
||||
*/
|
||||
const paragraphs = container.querySelectorAll(".public-document-header p");
|
||||
expect(paragraphs).toHaveLength(2);
|
||||
expect(container.querySelectorAll(".public-document-header p br")).toHaveLength(1);
|
||||
// 그대로 넣으면 문단 하나에 <br> 0개가 되어 전부 한 덩어리로 읽힌다.
|
||||
expect(paragraphs[0]).toHaveTextContent("둘 다 메모리에 있다.");
|
||||
expect(paragraphs[1]).toHaveTextContent("인스턴스를 늘리면 설계가 필요하다.");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ProseText } from "../../src/features/tech-log/presentation/shared/public-render/prose-text.tsx";
|
||||
|
||||
/**
|
||||
* 산문 칸이 오래 평문으로 나갔다. 빈 줄로 나눈 문단이 문단으로 보이지 않았고, 작성자가 백틱으로
|
||||
* 적은 식별자가 백틱째 화면에 나왔다 — 그 원문이 카드와 검색 결과까지 그대로 퍼졌다.
|
||||
*/
|
||||
describe("산문 칸", () => {
|
||||
it("빈 줄로 나눈 문단을 문단으로 그린다", () => {
|
||||
const { container } = render(<ProseText text={"첫 문단.\n\n둘째 문단."} />);
|
||||
const paragraphs = container.querySelectorAll("p");
|
||||
expect(paragraphs).toHaveLength(2);
|
||||
expect(paragraphs[0]).toHaveTextContent("첫 문단.");
|
||||
expect(paragraphs[1]).toHaveTextContent("둘째 문단.");
|
||||
});
|
||||
|
||||
it("빈 줄을 여러 개 띄워도 빈 문단을 만들지 않는다", () => {
|
||||
const { container } = render(<ProseText text={"가.\n\n\n\n나."} />);
|
||||
expect(container.querySelectorAll("p")).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("문단 안의 줄바꿈은 그 자리에 지킨다", () => {
|
||||
const { container } = render(<ProseText text={"첫 줄\n둘째 줄"} />);
|
||||
expect(container.querySelectorAll("p")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("br")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("백틱으로 감싼 조각을 코드로 읽는다", () => {
|
||||
const { container } = render(
|
||||
<ProseText text={"`로그인 상태가 만료되었다` 와 `Access Token` 은 다르다"} />,
|
||||
);
|
||||
const codes = [...container.querySelectorAll("code")].map((el) => el.textContent);
|
||||
expect(codes).toEqual(["로그인 상태가 만료되었다", "Access Token"]);
|
||||
// 백틱은 화면에 남지 않아야 한다 — 카드와 검색 결과까지 퍼지던 것이 이 문자다.
|
||||
expect(container.textContent).not.toContain("`");
|
||||
});
|
||||
|
||||
it("백틱 짝이 맞지 않으면 원문을 그대로 둔다", () => {
|
||||
const { container } = render(<ProseText text={"백틱 하나 ` 만 있다"} />);
|
||||
expect(container.querySelectorAll("code")).toHaveLength(0);
|
||||
expect(container.textContent).toContain("`");
|
||||
});
|
||||
|
||||
it("빈 문자열이면 아무것도 그리지 않는다", () => {
|
||||
const { container } = render(<ProseText text={" \n\n "} />);
|
||||
expect(container.querySelectorAll("p")).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user