重构代码,新增了MarkdownBasedManager和TXTManager实现
This commit is contained in:
0
docutranslate/ir/__init__.py
Normal file
0
docutranslate/ir/__init__.py
Normal file
24
docutranslate/ir/document.py
Normal file
24
docutranslate/ir/document.py
Normal 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)
|
||||
7
docutranslate/ir/markdown_document.py
Normal file
7
docutranslate/ir/markdown_document.py
Normal 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"
|
||||
Reference in New Issue
Block a user