Coverage for src/kwai/api/converter.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that defines an interface for a document converter.""" 

2 

3from abc import ABC, abstractmethod 

4 

5import markdown 

6 

7 

8class DocumentConverter(ABC): 

9 """Interface for a document converter. 

10 

11 A converter will convert a certain format (markdown for example) into HTML. 

12 """ 

13 

14 @abstractmethod 

15 def convert(self, content: str) -> str: 

16 """Convert a string to HTML.""" 

17 raise NotImplementedError 

18 

19 

20class MarkdownConverter(DocumentConverter): 

21 """Converter for converting markdown into HTML.""" 

22 

23 def convert(self, content: str) -> str: 

24 """Convert markdown to HTML.""" 

25 return markdown.markdown(content, extensions=["tables"])