feat: enhance code block rendering by adding language support for syntax highlighting

This commit is contained in:
myhloli
2026-03-24 00:08:21 +08:00
parent d3e79967df
commit 4beb2ad207

View File

@@ -260,7 +260,11 @@ def make_blocks_to_content_list(para_block, img_buket_path, page_idx, page_size)
para_content = {'type': BlockType.CODE, 'sub_type': para_block["sub_type"], BlockType.CODE_CAPTION: []}
for block in para_block['blocks']:
if block['type'] == BlockType.CODE_BODY:
para_content[BlockType.CODE_BODY] = merge_para_with_text(block)
code_text = merge_para_with_text(block)
if block['sub_type'] == BlockType.CODE:
guess_lang = para_block.get("guess_lang", "txt")
code_text = f"```{guess_lang}\n{code_text}\n```"
para_content[BlockType.CODE_BODY] = code_text
if block['type'] == BlockType.CODE_CAPTION:
para_content[BlockType.CODE_CAPTION].append(merge_para_with_text(block))