feat(프로젝트): 설명란 하이퍼링크 글자 크기·굵기 변경
- 링크는 한 글자처럼 잠겨(contenteditable=false) execCommand 서식이 안 들어갔다 - 고른 범위의 링크는 링크 안쪽 span style 로 크기(글자 크기 도구)·굵기(굵게 버튼·Ctrl+B) - 링크 기본이 굵게라 보통 = font-weight: 400, 서버 desc_inline_style 이 400 만 허용 - 글자와 같이 고르면 글자에 적용된 굵기를 따름 - project.js 캐시 버전 20261030b, 브라우저·sanitize 테스트 추가 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8877,6 +8877,7 @@
|
||||
openStylePop(btn, cmd);
|
||||
return;
|
||||
}
|
||||
if (cmd === "bold") { boldWithLinks(); updateFmtState(); return; }
|
||||
// 체크리스트 — 글머리 목록처럼 켜고 끈다(줄마다 체크박스).
|
||||
if (cmd === "insertCheckbox") {
|
||||
toggleChecklist();
|
||||
@@ -8943,12 +8944,59 @@
|
||||
const sel = window.getSelection();
|
||||
if (range) { sel.removeAllRanges(); sel.addRange(range); }
|
||||
if (!sel.rangeCount || sel.isCollapsed) { showToast("바꿀 글자를 먼저 선택하세요.", "info"); return; }
|
||||
const links = kind === "size" ? linksIn(sel.getRangeAt(0)) : [];
|
||||
try { document.execCommand("styleWithCSS", false, false); } catch (_) {}
|
||||
try {
|
||||
if (kind === "color") document.execCommand("foreColor", false, value || RESET_COLOR);
|
||||
else document.execCommand("fontSize", false, "7");
|
||||
} catch (_) {}
|
||||
fontsToSpans(kind, value);
|
||||
links.forEach(function (a) { setLinkStyle(a, "font-size", value); });
|
||||
box.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
// ── 링크 서식(2026-10-30) — 링크는 한 글자처럼 잠겨(contenteditable=false) execCommand 굵게·크기가 안에 안 들어간다.
|
||||
// 고른 범위에 걸친 링크는 링크 안쪽 <span style> 하나로 크기·굵기만 바꾼다(링크는 그대로 한 덩어리).
|
||||
// 굵기: 링크 기본(CSS)이 굵게라 "보통"은 font-weight: 400, 굵게는 그 값을 뺀다(서버 desc_inline_style 이 400 만 받는다).
|
||||
function linksIn(range) {
|
||||
return Array.prototype.filter.call(box.querySelectorAll("a"), function (a) { return range.intersectsNode(a); });
|
||||
}
|
||||
function setLinkStyle(a, prop, value) {
|
||||
let sp = a.childNodes.length === 1 && a.firstChild.nodeName === "SPAN" && !a.firstChild.className ? a.firstChild : null;
|
||||
if (!sp) {
|
||||
sp = document.createElement("span");
|
||||
while (a.firstChild) sp.appendChild(a.firstChild);
|
||||
a.appendChild(sp);
|
||||
}
|
||||
stripInside(sp, prop);
|
||||
if (value) sp.style.setProperty(prop, value); else sp.style.removeProperty(prop);
|
||||
if (!sp.getAttribute("style")) sp.replaceWith.apply(sp, Array.prototype.slice.call(sp.childNodes));
|
||||
}
|
||||
function linkIsBold(a) {
|
||||
const sp = a.querySelector("span[style]") || a;
|
||||
return parseInt(getComputedStyle(sp).fontWeight, 10) >= 600;
|
||||
}
|
||||
// 굵게(도구 버튼·Ctrl+B) — 글자는 execCommand, 고른 링크는 같은 결과로(글자가 없으면 링크끼리 켜고 끄기)
|
||||
function boldWithLinks() {
|
||||
const sel = window.getSelection();
|
||||
const range = sel.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
|
||||
const links = range && !range.collapsed ? linksIn(range) : [];
|
||||
const allBold = links.every(linkIsBold);
|
||||
// 고른 범위의 링크 밖 글자(execCommand 뒤에도 같은 글자 노드가 <b> 로 옮겨질 뿐이라 굵기를 다시 잴 수 있다)
|
||||
const texts = [];
|
||||
if (links.length) {
|
||||
const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT);
|
||||
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
||||
if (n.nodeValue.trim() && range.intersectsNode(n) && !n.parentElement.closest("a")) texts.push(n);
|
||||
}
|
||||
}
|
||||
try { document.execCommand("bold"); } catch (_) {}
|
||||
if (!links.length) return;
|
||||
// 글자가 있으면 execCommand 가 실제로 만든 굵기를 따른다 — 잠긴 링크가 끼면 queryCommandState·선택 범위가 틀어진다
|
||||
const now = texts.filter(function (n) { return n.isConnected && box.contains(n); });
|
||||
const bold = now.length
|
||||
? now.every(function (n) { return parseInt(getComputedStyle(n.parentElement).fontWeight, 10) >= 600; })
|
||||
: !allBold;
|
||||
links.forEach(function (a) { setLinkStyle(a, "font-weight", bold ? "" : "400"); });
|
||||
box.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
function openStylePop(btn, cmd) {
|
||||
@@ -9004,6 +9052,12 @@
|
||||
try { document.execCommand("strikeThrough"); } catch (_) {}
|
||||
updateFmtState();
|
||||
}
|
||||
// Ctrl+B — 도구 버튼과 같이 고른 링크도 굵게/보통(브라우저 기본 굵게는 잠긴 링크에 안 들어간다)
|
||||
if ((e.ctrlKey || e.metaKey) && !e.shiftKey && !e.altKey && (e.key === "b" || e.key === "B")) {
|
||||
e.preventDefault();
|
||||
boldWithLinks();
|
||||
updateFmtState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user