From 9b7ad82fe30ae9e6545e5225b00f8eeb77ca325c Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Mon, 31 Aug 2026 08:06:03 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=82=B0=EB=AC=B8=20=EC=B9=B8=EC=9D=98?= =?UTF-8?q?=20=EB=AC=B8=EB=8B=A8=EA=B3=BC=20=EC=9D=B8=EB=9D=BC=EC=9D=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=9D=BD=EC=96=B4=EC=84=9C=20?= =?UTF-8?q?=EA=B7=B8=EB=A6=B0=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Case 만 블록 파서를 타고 나머지 유형은 문자열을 그대로 내보내고 있었다. 그래서 두 가지가 깨졌다. 작성자가 백틱으로 적은 식별자가 백틱째 화면에 나왔다. 어떤 Reference 는 한 문서에 백틱이 32개였고, 그 원문이 홈 카드·탐색 카드·검색 결과까지 그대로 퍼졌다. 판단 기준은 `

{rule.body}

` 로, 적용할 때·예외·예시는 `
  • {item.text}
  • ` 로 아무것도 거치지 않고 나가고 있었다. 빈 줄로 나눈 문단이 문단으로 보이지 않았다. 어제 넣은 PlainText 는 모든 줄바꿈을
    로 만들었기 때문에 빈 줄도

    로 나갔고, 문단 사이 여백이 없었다. Reference 7개 전부에 빈 줄이 9~16개 있다. ProseText 로 바꾼다 — 빈 줄은 문단을 가르고, 문단 안 줄바꿈은 그 자리에 지키고, 백틱은 코드로 읽는다. 백틱 수가 홀수면 원문을 그대로 둔다: 작성자가 백틱 자체를 쓴 것일 수 있고, 반쯤 해석해 한쪽만 코드로 만드는 쪽이 더 나쁘다. 블록 파서(parseCaseContent)를 쓰지 않는 이유는 그쪽이 Case 전용 문법과 도식 참조까지 물고 있어 이 칸들에 없는 해석기를 끌고 오기 때문이다. 머리말 가드는
    개수로 재고 있었다. 이제 기준이 문단이므로 문단 수와 문단 안 줄바꿈을 함께 확인하도록 고친다 — 가드가 낡은 것이지 화면이 틀린 것이 아니다. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ --- .../components/public-document-header.tsx | 4 +- .../public/pages/project-decisions-page.tsx | 12 ++-- .../shared/public-render/prose-text.tsx | 70 +++++++++++++++++++ .../public-render/public-record-renderer.tsx | 40 +++++------ .../tech-log/presentation/styles/globals.css | 16 +++++ tests/component/inline-line-breaks.test.tsx | 14 +++- tests/component/prose-text.test.tsx | 52 ++++++++++++++ 7 files changed, 177 insertions(+), 31 deletions(-) create mode 100644 src/features/tech-log/presentation/shared/public-render/prose-text.tsx create mode 100644 tests/component/prose-text.test.tsx diff --git a/src/features/tech-log/presentation/public/components/public-document-header.tsx b/src/features/tech-log/presentation/public/components/public-document-header.tsx index b26eecf..e82fe43 100644 --- a/src/features/tech-log/presentation/public/components/public-document-header.tsx +++ b/src/features/tech-log/presentation/public/components/public-document-header.tsx @@ -2,7 +2,7 @@ import { Link } from "react-router-dom"; import type { PublicRecord } from "../../../application/ports/public-content-queries.ts"; import type { components } from "../../../contracts/studio/generated.ts"; -import { PlainText } from "../../shared/public-render/inline-renderer.tsx"; +import { ProseText } from "../../shared/public-render/prose-text.tsx"; const kindLabels = { CASE: "Case", @@ -35,7 +35,7 @@ export function PublicDocumentHeader({ record }: { record: PublicRecord }) {

    {record.title}

    {/* 요약은 여러 문단일 수 있다 — 그대로 넣으면 줄바꿈이 사라져 한 덩어리로 읽힌다. */} -

    </p> + <ProseText text={record.summary} /> <dl> <div> <dt>유형</dt> diff --git a/src/features/tech-log/presentation/public/pages/project-decisions-page.tsx b/src/features/tech-log/presentation/public/pages/project-decisions-page.tsx index 704953b..bc25216 100644 --- a/src/features/tech-log/presentation/public/pages/project-decisions-page.tsx +++ b/src/features/tech-log/presentation/public/pages/project-decisions-page.tsx @@ -4,7 +4,7 @@ import { RegisteredNotFoundRoute, useRouteInput, } from "../../../../../presentation/routes/route-input.tsx"; -import { PlainText } from "../../shared/public-render/inline-renderer.tsx"; +import { ProseText } from "../../shared/public-render/prose-text.tsx"; import { ProjectPageHeader } from "../components/project-page-header.tsx"; import { usePublicContent } from "../use-public-content.tsx"; @@ -32,7 +32,7 @@ export function ProjectDecisionsPage() { {/* 작성자가 나눠 쓴 줄은 그대로 나눠 보여야 한다. 이 칸들은 Markdown 을 거치지 않고 텍스트 노드로 들어가므로, HTML 이 줄바꿈을 공백으로 접어 여러 문단이 한 줄로 - 이어져 보였다. `PlainText` 가 그 자리를 지킨다. + 이어져 보였다. `ProseText` 가 그 자리를 지킨다. */} <header> <div> @@ -43,23 +43,23 @@ export function ProjectDecisionsPage() { </div> <h2>{decision.title}</h2> {decision.summary ? ( - <p><PlainText text={decision.summary} /></p> + <ProseText text={decision.summary} /> ) : null} </header> <section> <h3>결정</h3> - <p><PlainText text={decision.statement} /></p> + <ProseText text={decision.statement} /> </section> <section> <h3>판단 이유</h3> - <p><PlainText text={decision.rationale} /></p> + <ProseText text={decision.rationale} /> </section> <section> <h3>영향</h3> {decision.consequences.length ? ( <ul> {decision.consequences.map((item) => ( - <li key={item}><PlainText text={item} /></li> + <li key={item}><ProseText text={item} /></li> ))} </ul> ) : ( diff --git a/src/features/tech-log/presentation/shared/public-render/prose-text.tsx b/src/features/tech-log/presentation/shared/public-render/prose-text.tsx new file mode 100644 index 0000000..534e22f --- /dev/null +++ b/src/features/tech-log/presentation/shared/public-render/prose-text.tsx @@ -0,0 +1,70 @@ +import { Fragment, type ReactNode } from "react"; + +/** + * 작성자가 직접 쓴 산문 칸. 요약·판단 기준 본문·해결 내용처럼 Markdown 블록 파서를 거치지 + * 않고 문자열 그대로 오는 자리에 쓴다. + * + * <p>이 칸들은 오래 평문으로 나갔다. 그래서 두 가지가 깨져 있었다. 빈 줄로 나눈 문단이 문단으로 + * 보이지 않았고(줄바꿈 두 개가 그냥 이어졌다), 작성자가 백틱으로 적은 식별자가 백틱째 화면에 + * 나왔다 — 어떤 Reference 는 한 문서에 백틱이 32개 있었고 그 원문이 카드와 검색 결과까지 + * 그대로 퍼졌다. + * + * <p>블록 파서(`parseCaseContent`)를 쓰지 않는 이유는 그쪽이 Case 전용 문법(`:::evidence`, + * 도식 참조)까지 물고 있어 이 칸들에는 없는 해석기를 끌고 오기 때문이다. 여기 필요한 것은 + * 문단과 인라인 코드 둘뿐이다. + */ + +/** + * 백틱으로 감싼 조각을 코드로 읽는다. + * + * <p>백틱 수가 홀수면 짝이 맞지 않는다 — 작성자가 코드를 의도한 것이 아니라 백틱 자체를 쓴 + * 것일 수 있으므로 원문을 그대로 둔다. 반쯤 해석해서 한쪽만 코드로 만드는 쪽이 더 나쁘다. + */ +function renderInlineCode(text: string, keyPrefix: string): ReactNode[] { + const parts = text.split("`"); + if (parts.length % 2 === 0) return [text]; + return parts.map((part, index) => + index % 2 === 1 ? ( + <code key={`${keyPrefix}-c${index}`}>{part}</code> + ) : ( + <Fragment key={`${keyPrefix}-t${index}`}>{part}</Fragment> + ), + ); +} + +/** 문단 안의 줄바꿈. 작성자가 엔터로 나눠 쓴 줄을 그 자리에 지킨다. */ +function renderLines(paragraph: string, keyPrefix: string): ReactNode[] { + const lines = paragraph.split("\n"); + return lines.flatMap((line, index) => { + const rendered = renderInlineCode(line, `${keyPrefix}-${index}`); + if (index === 0) return rendered; + return [<br key={`${keyPrefix}-br${index}`} />, ...rendered]; + }); +} + +export function ProseText({ + text, + className, +}: { + text: string; + /** 문단마다 붙는다. 한 문단만 있던 시절 바깥 `<p>` 가 갖고 있던 클래스가 여기로 온다. */ + className?: string; +}) { + // 빈 줄이 몇 개든 문단 하나의 경계다. 세 줄을 띄웠다고 빈 문단이 생기지는 않는다. + const paragraphs = text + .split(/\n{2,}/u) + .map((paragraph) => paragraph.trim()) + .filter((paragraph) => paragraph !== ""); + + if (paragraphs.length === 0) return null; + + return ( + <> + {paragraphs.map((paragraph, index) => ( + <p key={index} className={className}> + {renderLines(paragraph, String(index))} + </p> + ))} + </> + ); +} diff --git a/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx b/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx index eb93961..950cb20 100644 --- a/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx +++ b/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx @@ -2,7 +2,7 @@ import { Link } from "react-router-dom"; import type { components } from "../../../contracts/studio/generated.ts"; import { inlinePlainText } from "../../../domain/content-format/inline-plain-text.ts"; -import { PlainText } from "./inline-renderer.tsx"; +import { ProseText } from "./prose-text.tsx"; import type { ResolveEvidenceAsset, ResolvePublishedLabel, @@ -95,7 +95,7 @@ function ModelDocumentHeader({ ) : null} </nav> <h1>{model.title}</h1> - <p><PlainText text={model.summary} /></p> + <ProseText text={model.summary} /> <dl> <div> <dt>유형</dt> @@ -177,27 +177,27 @@ function CaseDocument({ </nav> <h1>{model.title}</h1> - <p className="case-summary"><PlainText text={model.summary} /></p> + <ProseText text={model.summary} className="case-summary" /> <section className="case-snapshot" aria-label="문제와 결론"> <div> <p className="snapshot-label">문제</p> - <p><PlainText text={model.problem} /></p> + <ProseText text={model.problem} /> </div> <div> <p className="snapshot-label snapshot-label--answer">결론</p> - <p><PlainText text={model.conclusion} /></p> + <ProseText text={model.conclusion} /> </div> </section> <dl className="case-meta"> <div> <dt>검증 환경</dt> - <dd><PlainText text={model.environment} /></dd> + <dd><ProseText text={model.environment} /></dd> </div> <div> <dt>검증 데이터</dt> - <dd><PlainText text={model.reproduction.replace(/^Dataset:\s*/, "")} /></dd> + <dd><ProseText text={model.reproduction.replace(/^Dataset:\s*/, "")} /></dd> </div> <div> <dt>기록</dt> @@ -272,13 +272,13 @@ function ConceptDocument({ </nav> <h1>{model.title}</h1> - <p className="case-summary"><PlainText text={model.summary} /></p> + <ProseText text={model.summary} className="case-summary" /> <dl className="case-meta"> {model.basisVersion ? ( <div> <dt>기준</dt> - <dd><PlainText text={model.basisVersion} /></dd> + <dd><ProseText text={model.basisVersion} /></dd> </div> ) : null} <div> @@ -330,7 +330,7 @@ function ReferenceDocument({ <section className="reference-purpose" aria-labelledby="purpose-title"> <p className="section-kicker">Purpose</p> <h2 id="purpose-title">이 기준을 쓰는 이유</h2> - <p><PlainText text={model.purpose} /></p> + <ProseText text={model.purpose} /> </section> <article className="public-document-body reference-body"> <section aria-labelledby="rules-title"> @@ -343,7 +343,7 @@ function ReferenceDocument({ <span>{String(index + 1).padStart(2, "0")}</span> <div> <h3>{rule.title}</h3> - <p>{rule.body}</p> + <ProseText text={rule.body} /> </div> </li> ))} @@ -354,7 +354,7 @@ function ReferenceDocument({ <ul> {[...model.applyWhen] .sort((left, right) => left.order - right.order) - .map((item) => <li key={item.id}>{item.text}</li>)} + .map((item) => <li key={item.id}><ProseText text={item.text} /></li>)} </ul> </section> <section aria-labelledby="exceptions-title"> @@ -362,7 +362,7 @@ function ReferenceDocument({ <ul> {[...model.exceptions] .sort((left, right) => left.order - right.order) - .map((item) => <li key={item.id}>{item.text}</li>)} + .map((item) => <li key={item.id}><ProseText text={item.text} /></li>)} </ul> </section> <section aria-labelledby="examples-title"> @@ -370,7 +370,7 @@ function ReferenceDocument({ <ul> {[...model.examples] .sort((left, right) => left.order - right.order) - .map((item) => <li key={item.id}>{item.text}</li>)} + .map((item) => <li key={item.id}><ProseText text={item.text} /></li>)} </ul> <p className="verified-at"> 마지막 검증 {displayDate(model.verifiedOn)} @@ -394,7 +394,7 @@ function OrderedItems({ <ul> {[...items] .sort((left, right) => left.order - right.order) - .map((item) => <li key={item.id}>{item.text}</li>)} + .map((item) => <li key={item.id}><ProseText text={item.text} /></li>)} </ul> ); } @@ -466,7 +466,7 @@ function QuestionDocument({ .map((option) => ( <li key={option.id}> <h3>{option.title}</h3> - <p>{option.description}</p> + <ProseText text={option.description} /> </li> ))} </ol> @@ -477,7 +477,7 @@ function QuestionDocument({ > <p className="section-kicker">Next</p> <h2 id="next-validation-title">다음 검증</h2> - <p><PlainText text={model.nextValidation} /></p> + <ProseText text={model.nextValidation} /> </section> </article> <PublicDocumentRelations relations={publicRelations(model.relations)} /> @@ -524,16 +524,16 @@ function ProjectDecisionDocument({ </div> <h2>{model.title}</h2> {model.summary ? ( - <p><PlainText text={model.summary} /></p> + <ProseText text={model.summary} /> ) : null} </header> <section> <h3>결정</h3> - <p><PlainText text={model.statement} /></p> + <ProseText text={model.statement} /> </section> <section> <h3>판단 이유</h3> - <p><PlainText text={model.rationale} /></p> + <ProseText text={model.rationale} /> </section> <section> <h3>영향</h3> diff --git a/src/features/tech-log/presentation/styles/globals.css b/src/features/tech-log/presentation/styles/globals.css index b2dea66..67ec74e 100644 --- a/src/features/tech-log/presentation/styles/globals.css +++ b/src/features/tech-log/presentation/styles/globals.css @@ -2467,6 +2467,22 @@ dialog::backdrop { .reference-rules li > span { color: var(--faint); font-family: "IBM Plex Mono", monospace; font-size: 10px; } .reference-rules p, .question-options p { margin: 5px 0 0; } + +/* + 문단 사이. 작성자가 빈 줄로 나눈 것이 문단으로 보여야 한다 — 나누기만 하고 여백이 없으면 + 갈라 놓은 의미가 없다. 목록 항목 안에서는 항목 자체의 여백이 이미 있으므로 위아래 끝을 턴다. +*/ +.public-document-body p + p, +.reference-rules p + p, +.question-options p + p { margin-top: 1.05em; } +.public-document-body li > p:first-child, +.reference-rules li p:first-of-type { margin-top: 0; } +.public-document-body li > p:last-child { margin-bottom: 0; } + +/* 작성자가 백틱으로 적은 식별자. 본문 흐름을 끊지 않게 옅은 바탕만 준다. */ +.public-document-body code, +.reference-rules code, +.question-options code { padding: 1px 5px; border-radius: 4px; background: var(--line); font-family: "IBM Plex Mono", monospace; font-size: 0.88em; } .verified-at { color: var(--faint) !important; font-size: 12px !important; } .question-status { width: fit-content; margin: -34px 0 50px; padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font-size: 11px; font-weight: 650; } .question-status--open, diff --git a/tests/component/inline-line-breaks.test.tsx b/tests/component/inline-line-breaks.test.tsx index 7406895..0b40838 100644 --- a/tests/component/inline-line-breaks.test.tsx +++ b/tests/component/inline-line-breaks.test.tsx @@ -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("인스턴스를 늘리면 설계가 필요하다."); }); }); diff --git a/tests/component/prose-text.test.tsx b/tests/component/prose-text.test.tsx new file mode 100644 index 0000000..60c39c5 --- /dev/null +++ b/tests/component/prose-text.test.tsx @@ -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); + }); +});