스마트 에디터로 작성할 때 둥근 따옴표 사용
텍스트 에어리어 내에서 작성하는 경우에는
</p>
<p> function replaceText() {</p>
<p> var replacedText = content.value;</p>
<p> </p>
<p> var replacementRules = [</p>
<p> { find: /\?“/g, replace: "?”" },</p>
<p> { find: /\!“/g, replace: "!”" },</p>
<p> { find: /\.“/g, replace: ".”" },</p>
<p> { find: /\?‘/g, replace: "?’" },</p>
<p> { find: /\!‘/g, replace: "!’" },</p>
<p> { find: /\.‘/g, replace: ".’" },</p>
<p> { find: /\`/g, replace: "…" },</p>
<p> ];</p>
<p>
</p>
<p> var selectionStart = content.selectionStart; // 현재 포인터의 위치 저장</p>
<p> var selectionEnd = content.selectionEnd;</p>
<p> </p>
<p> replacementRules.forEach(function (rule) {</p>
<p> replacedText = replacedText.replace(rule.find, rule.replace);</p>
<p> });</p>
<p>
</p>
<p> content.value = replacedText;</p>
<p> content.setSelectionRange(selectionStart, selectionEnd); // 포인터 위치 복원</p>
<p> }</p>
<p> </p>
<p> </p>
<p> document.getElementById("content").addEventListener("input", function () {</p>
<p> replaceQuotes();</p>
<p> replaceText();</p>
<p> });</p>
<p>
위와 같은 코드를 사용해서 곧은 따옴표를 둥근 따옴표로 바꿔서 사용할 수 있더라고요.
스마트 에디터2를 사용하는 게시판에서 작성하는 글은 모두 따옴표가 곧은 따옴표로 나오는데
어떻게 하면 여기에 작성 되는 따옴표를 둥근 따옴표로 바꿀 수 있을까요? ㅠㅠ
답변 2개
자문자답 같아서 부끄럽네요
생각해보니 꼭 에디터에서 둥근 따옴표가 적용되어야 할 필요는 없겠더라고요.
그래서 작성 후 뷰페이지에서 볼 때 텍스트를 대치하는 것으로 문제를 해결하기로 했습니다.
</strong></p>
<p>document.addEventListener("DOMContentLoaded", function() {
var contentDiv = document.getElementById('bo_v_con');
if (contentDiv) {
var content = contentDiv.innerHTML;</p>
<p> // "와 '를 각각 “와 ‘로 대체
var replacedText = content.replace(/"/g, '“').replace(/'/g, '‘');</p>
<p> // 대체 규칙 배열
var replacementRules = [
{ find: /\?“/g, replace: "?”" },
{ find: /\!“/g, replace: "!”" },
{ find: /\.“/g, replace: ".”" },
{ find: /\?‘/g, replace: "?’" },
{ find: /\!‘/g, replace: "!’" },
{ find: /\.‘/g, replace: ".’" },
{ find: /\`/g, replace: "…" }
];</p>
<p> // 각 규칙에 대해 텍스트 대체
replacementRules.forEach(function(rule) {
replacedText = replacedText.replace(rule.find, rule.replace);
});</p>
<p> // 대체된 텍스트를 적용
contentDiv.innerHTML = replacedText;
}
});
</p>
<p><strong>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인