diff --git a/core/covert.py b/core/covert.py index baf594a..27ca165 100644 --- a/core/covert.py +++ b/core/covert.py @@ -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: diff --git a/test/test-convert.json b/test/test-convert.json new file mode 100644 index 0000000..2e83554 --- /dev/null +++ b/test/test-convert.json @@ -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": "" +} diff --git a/test/test-convert.md b/test/test-convert.md new file mode 100644 index 0000000..0318288 --- /dev/null +++ b/test/test-convert.md @@ -0,0 +1 @@ +测试单行富文本丢失问题从**这里开始**之后的内容就没了 \ No newline at end of file diff --git a/test/test.py b/test/test.py index 0e6ce53..1a69d23 100644 --- a/test/test.py +++ b/test/test.py @@ -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"