- 근거(메모)를 문단·굵게·표·그림 자리표로 펼쳐 편집, 붙여넣기(서식 있는 글·표), 저장 - WPTools 글 형식 읽기·쓰기(native-memo-wpt.cjs) — 그림 원문 보존, ASCII 로 써서 cp949 변환 없음 - ESTX 저장: 원래 메모가 있던 행만, 새 메모는 JSON 저장 안내 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
"""근거(메모) WPTools 글 형식 읽기·쓰기: 문단·굵게·표 칸·그림 원문 보존."""
|
|
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SOURCE = (
|
|
"<!WPTools_Format V=560/>\r\n<stylesheet></stylesheet>"
|
|
"<cs nr=1 wpsty=[[CharFont:'A';]]/><cs nr=2 wpsty=[[CharStyleMask:1;CharStyleON:1;]]/>"
|
|
"<div cs=2><c nr=2/><근거><c nr=1/> A&B</div>\r\n<div cs=1></div>\r\n"
|
|
"<table cs=1><tr><td cs=1><c nr=1/>공종</td>\r\n<td cs=1><c nr=2/>1.5</td></tr></table>"
|
|
'<div cs=1><c nr=1/>x <txtobj wpsty=[[Type:12;]] type="TWPOImage">\r\n<!--QUJD--></txtobj></div>\r\n'
|
|
)
|
|
|
|
|
|
def node(script):
|
|
code = (
|
|
"const W=require(process.argv[1]);const S=process.argv[2];"
|
|
f"console.log(JSON.stringify(({script})()))"
|
|
)
|
|
out = subprocess.check_output(
|
|
["node", "-e", code, str(ROOT / "tools/est-test/native-memo-wpt.cjs"), SOURCE],
|
|
text=True,
|
|
encoding="utf-8",
|
|
)
|
|
return json.loads(out)
|
|
|
|
|
|
def test_read_paragraphs_bold_table_and_object():
|
|
nodes = node("()=>W.read(S)")
|
|
assert nodes[0] == {
|
|
"p": [{"text": "<근거>", "bold": True}, {"text": " A&B", "bold": False}]
|
|
}
|
|
assert nodes[1] == {"p": []}
|
|
assert nodes[2]["table"] == [
|
|
[[{"p": [{"text": "공종", "bold": False}]}], [{"p": [{"text": "1.5", "bold": True}]}]]
|
|
]
|
|
assert nodes[3]["p"][0] == {"text": "x ", "bold": False}
|
|
assert nodes[3]["p"][1]["object"].startswith("<txtobj") and "QUJD" in nodes[3]["p"][1]["object"]
|
|
|
|
|
|
def test_write_round_trips_and_stays_ascii():
|
|
result = node(
|
|
"()=>{const n=W.read(S),w=W.write(n);"
|
|
"return {same:JSON.stringify(W.read(w))===JSON.stringify(n),ascii:/^[\\x00-\\x7e]*$/.test(w),"
|
|
"html:W.html(n)}}"
|
|
)
|
|
assert result["same"] is True
|
|
assert result["ascii"] is True
|
|
assert "<b><근거></b>" in result["html"]
|
|
assert 'data-obj="0"' in result["html"] and "<table" in result["html"]
|