feat(project): add font options and selected goal text formatting
Restore the board header add button to the task side panel while keeping footer quick entry. Add safe, persisted goal text formatting and self-hosted Project font preferences with shared help updates and regression coverage.
This commit is contained in:
@@ -6,8 +6,10 @@ DB 없이 단위 테스트 가능한 순수 함수만 둔다(malaysia.store 패
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
from html import escape
|
||||
from html.parser import HTMLParser
|
||||
from typing import Any
|
||||
|
||||
@@ -475,11 +477,83 @@ def validate_goal_color(color: Any) -> str:
|
||||
|
||||
def validate_goal_text(body: Any) -> str:
|
||||
v = str(body or "").replace("\r\n", "\n").strip()
|
||||
if v.startswith(GOAL_RICH_PREFIX):
|
||||
runs = goal_text_runs(v, strict=True)
|
||||
if not "".join(r["text"] for r in runs).strip():
|
||||
return ""
|
||||
return GOAL_RICH_PREFIX + json.dumps(runs, ensure_ascii=False, separators=(",", ":"))
|
||||
if len(v) > GOAL_TEXT_MAX:
|
||||
raise ValueError(f"칸 하나에 {GOAL_TEXT_MAX}자까지 쓸 수 있습니다.")
|
||||
return v
|
||||
|
||||
|
||||
# 기존 TEXT 칸에 버전이 있는 텍스트 조각을 저장한다. 예전 평문은 그대로 유지한다.
|
||||
GOAL_RICH_PREFIX = "pj-rich:v1:"
|
||||
|
||||
|
||||
def goal_text_runs(body: Any, *, strict: bool = False) -> list[dict[str, Any]]:
|
||||
value = str(body or "")
|
||||
if not value.startswith(GOAL_RICH_PREFIX):
|
||||
return [{"text": value}]
|
||||
try:
|
||||
raw = json.loads(value[len(GOAL_RICH_PREFIX):])
|
||||
if not isinstance(raw, list) or len(raw) > GOAL_TEXT_MAX:
|
||||
raise ValueError("서식 데이터가 올바르지 않습니다.")
|
||||
runs = []
|
||||
for item in raw:
|
||||
if not isinstance(item, dict) or not isinstance(item.get("text"), str):
|
||||
raise ValueError("서식 데이터가 올바르지 않습니다.")
|
||||
run: dict[str, Any] = {"text": item["text"]}
|
||||
if isinstance(item.get("bold"), bool):
|
||||
run["bold"] = item["bold"]
|
||||
if re.fullmatch(r"#[0-9a-fA-F]{6}", str(item.get("color", ""))):
|
||||
run["color"] = item["color"].lower()
|
||||
size = item.get("size")
|
||||
if isinstance(size, int) and not isinstance(size, bool) and 10 <= size <= 32:
|
||||
run["size"] = size
|
||||
if run["text"]:
|
||||
runs.append(run)
|
||||
if sum(len(r["text"]) for r in runs) > GOAL_TEXT_MAX:
|
||||
raise ValueError(f"칸 하나에 {GOAL_TEXT_MAX}자까지 쓸 수 있습니다.")
|
||||
return runs
|
||||
except (ValueError, TypeError) as err:
|
||||
if strict:
|
||||
raise ValueError("칸의 서식 데이터가 올바르지 않습니다.") from err
|
||||
return [{"text": value}]
|
||||
|
||||
|
||||
def goal_text_plain(body: Any) -> str:
|
||||
return "".join(r["text"] for r in goal_text_runs(body))
|
||||
|
||||
|
||||
def goal_text_html(body: Any) -> str:
|
||||
"""허용한 글자 서식만 HTML로 만든다. 사용자 텍스트는 항상 escape한다."""
|
||||
out = []
|
||||
for run in goal_text_runs(body):
|
||||
style = []
|
||||
if "bold" in run:
|
||||
style.append("font-weight:" + ("700" if run["bold"] else "400"))
|
||||
if "color" in run:
|
||||
style.append("color:" + run["color"])
|
||||
if "size" in run:
|
||||
style.append(f'font-size:{run["size"]}px')
|
||||
text = escape(run["text"])
|
||||
out.append(f'<span style="{";".join(style)}">{text}</span>' if style else text)
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def merge_goal_texts(bodies: list[str]) -> str:
|
||||
values = [v for v in bodies if goal_text_plain(v).strip()]
|
||||
if not any(v.startswith(GOAL_RICH_PREFIX) for v in values):
|
||||
return validate_goal_text("\n".join(values))
|
||||
runs = []
|
||||
for value in values:
|
||||
if runs:
|
||||
runs.append({"text": "\n"})
|
||||
runs.extend(goal_text_runs(value))
|
||||
return validate_goal_text(GOAL_RICH_PREFIX + json.dumps(runs, ensure_ascii=False))
|
||||
|
||||
|
||||
# ── 엑셀식 사각형 병합(마이그레이션 015) ──────────────────────────────
|
||||
class GoalMigration015Needed(RuntimeError):
|
||||
"""세로 병합·주간 회의록은 마이그레이션 015 뒤에만 된다."""
|
||||
|
||||
Reference in New Issue
Block a user