重构代码,新增了MarkdownBasedManager和TXTManager实现

This commit is contained in:
xunbu
2025-07-28 23:41:35 +08:00
parent 6ab3278481
commit 80634fe749
45 changed files with 885 additions and 139 deletions

View File

View File

@@ -0,0 +1,24 @@
import dataclasses
from pathlib import Path
class Document:
def __init__(self,suffix:str,content:bytes,stem:str|None=None,path:Path=None):
self.suffix=suffix
self.content=content
self.stem=stem
self.path=path
@property
def name(self)->str|None:
if not self.stem:
return None
return self.stem+self.suffix
@classmethod
def from_path(cls,path:Path|str):
if isinstance(path,str):
path=Path(path)
return cls(suffix=path.suffix,content=path.read_bytes(),stem=path.stem,path=path)
@classmethod
def from_bytes(cls,content:bytes,suffix:str,stem:str|None):
return cls(content=content,suffix=suffix,stem=stem)

View File

@@ -0,0 +1,7 @@
from docutranslate.ir.document import Document
class MarkdownDocument(Document):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.suffix=".md"