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
« 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."""
3from abc import ABC, abstractmethod
5import markdown
8class DocumentConverter(ABC):
9 """Interface for a document converter.
11 A converter will convert a certain format (markdown for example) into HTML.
12 """
14 @abstractmethod
15 def convert(self, content: str) -> str:
16 """Convert a string to HTML."""
17 raise NotImplementedError
20class MarkdownConverter(DocumentConverter):
21 """Converter for converting markdown into HTML."""
23 def convert(self, content: str) -> str:
24 """Convert markdown to HTML."""
25 return markdown.markdown(content, extensions=["tables"])