-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ imrove project structure & performance
- Loading branch information
Showing
26 changed files
with
865 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.4.0 | ||
2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from functools import wraps | ||
|
||
|
||
def partial(func, *args, **keywords): | ||
@wraps(func) | ||
def new_func(*f_args, **f_keywords): | ||
new_keywords = {**f_keywords, **keywords} | ||
return func(*f_args, *args, **new_keywords) | ||
|
||
return new_func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from .cell_output import CellOutput | ||
from .cells import Cell, CodeCell, MarkdownCell, RawCell | ||
from .output_parsers import HtmlParser, ImageParser, TextParser | ||
|
||
CellOutput.register_parser('text', TextParser()) | ||
CellOutput.register_parser('text/html', HtmlParser()) | ||
CellOutput.register_parser('image', ImageParser()) | ||
|
||
|
||
__all__ = ['Cell', 'CellOutput', 'MarkdownCell', 'CodeCell', 'RawCell'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from abc import ABCMeta, abstractmethod | ||
|
||
from nbmanips.cell.cell_utils import COLOR_SUPPORTED | ||
|
||
try: | ||
from html2text import html2text | ||
except ImportError: | ||
html2text = None | ||
|
||
try: | ||
from img2text import img_to_ascii | ||
except ImportError: | ||
img_to_ascii = None | ||
|
||
|
||
class ParserBase(metaclass=ABCMeta): | ||
@abstractmethod | ||
def parse(self, content, **kwargs): | ||
return content | ||
|
||
@property | ||
def default_state(self): | ||
return True | ||
|
||
|
||
class TextParser(ParserBase): | ||
def parse(self, content, **kwargs): | ||
return content | ||
|
||
|
||
class ImageParser(ParserBase): | ||
def parse( | ||
self, | ||
content, | ||
width=80, | ||
colorful=COLOR_SUPPORTED, | ||
bright=COLOR_SUPPORTED, | ||
reverse=True, | ||
**kwargs, | ||
): | ||
if callable(img_to_ascii): | ||
return img_to_ascii( | ||
content, | ||
base64=True, | ||
colorful=colorful, | ||
reverse=reverse, | ||
width=width, | ||
bright=bright, | ||
**kwargs, | ||
) | ||
else: | ||
raise ModuleNotFoundError( | ||
'You need to pip install img2text for readable option' | ||
) | ||
|
||
@property | ||
def default_state(self): | ||
return img_to_ascii is not None | ||
|
||
|
||
class HtmlParser(ParserBase): | ||
def parse(self, content, width=78, **kwargs): | ||
if callable(html2text): | ||
return html2text(content, bodywidth=width, **kwargs) | ||
else: | ||
raise ModuleNotFoundError( | ||
'You need to pip install html2txt for readable option' | ||
) | ||
|
||
@property | ||
def default_state(self): | ||
return html2text is not None |
Oops, something went wrong.