Skip to content

Commit

Permalink
Merge pull request #146 from BinghamChi/master
Browse files Browse the repository at this point in the history
修复单行内富文本丢失问题
  • Loading branch information
DeppWang authored Jul 6, 2024
2 parents 76dd82f + f631b0d commit 762659b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/covert.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,15 @@ def convert_text_func(self, content) -> str:

# 获取文本和属性
if seven_contents and not two_five_contents:
text = seven_contents[0].get("8")
text_attrs = seven_contents[0].get("9")
if text and text_attrs:
text = self._convert_text_attribute(text, text_attrs)
text = ""
for seven_content in seven_contents:
# 8 文本
raw = seven_content.get("8")
# 9 文本属性
text_attrs = seven_content.get("9")
if raw and text_attrs:
raw = self._convert_text_attribute(raw, text_attrs)
text += raw

# 链接类型
elif text_type == "li" and two_five_contents:
Expand Down
38 changes: 38 additions & 0 deletions test/test-convert.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"2": "1",
"3": "Ju9C-1621846617594",
"4": {
"version": 1,
"incompatibleVersion": 0,
"fv": "0"
},
"5": [
{
"3": "FbBV-1718363156752",
"5": [
{
"2": "2",
"3": "vozk-1718363156751",
"7": [
{
"8": "测试单行富文本丢失问题从"
},
{
"8": "这里开始",
"9": [
{
"2": "b"
}
]
},
{
"8": "之后的内容就没了"
}
]
}
]
}
],
"__compress__": true,
"title": ""
}
1 change: 1 addition & 0 deletions test/test-convert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
测试单行富文本丢失问题从**这里开始**之后的内容就没了
11 changes: 11 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ def test_covert_json_to_markdown_content(self):
# CRLF => \r\n, LF => \n
self.assertEqual(content.replace("\r\n", "\n"), content_target)

def test_covert_json_to_markdown_single_line(self):
"""
测试 json 转换 markdown 单行富文本
python test.py YoudaoNoteCovert.test_covert_json_to_markdown_single_line
"""
line = YoudaoNoteConvert._covert_json_to_markdown_content("test/test-convert.json")
with open("test/test-convert.md", "rb") as f:
target = f.read().decode()
# CRLF => \r\n, LF => \n
self.assertEqual(line.replace("\r\n", "\n"), target)


class YoudaoNotePullTest(unittest.TestCase):
TEST_CONFIG_PATH = "test_config.json"
Expand Down

0 comments on commit 762659b

Please sign in to comment.