mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 07:09:31 +00:00
parent
63c3a0e56c
commit
fe8c9d621a
@ -7,7 +7,7 @@ from typing import Iterable, Tuple
|
||||
|
||||
import nbformat
|
||||
from nbconvert.exporters import MarkdownExporter
|
||||
from nbconvert.preprocessors import Preprocessor, RegexRemovePreprocessor
|
||||
from nbconvert.preprocessors import Preprocessor
|
||||
|
||||
|
||||
class EscapePreprocessor(Preprocessor):
|
||||
@ -79,11 +79,30 @@ class ExtractAttachmentsPreprocessor(Preprocessor):
|
||||
return cell, resources
|
||||
|
||||
|
||||
class CustomRegexRemovePreprocessor(Preprocessor):
|
||||
def check_conditions(self, cell):
|
||||
pattern = re.compile(r"(?s)(?:\s*\Z)|(?:.*#\s*\|\s*output:\s*false.*)")
|
||||
rtn = not pattern.match(cell.source)
|
||||
if not rtn:
|
||||
print("--remove--")
|
||||
print(cell.source)
|
||||
return False
|
||||
else:
|
||||
print("--keep--")
|
||||
print(cell.source)
|
||||
return True
|
||||
|
||||
def preprocess(self, nb, resources):
|
||||
nb.cells = [cell for cell in nb.cells if self.check_conditions(cell)]
|
||||
|
||||
return nb, resources
|
||||
|
||||
|
||||
exporter = MarkdownExporter(
|
||||
preprocessors=[
|
||||
EscapePreprocessor,
|
||||
ExtractAttachmentsPreprocessor,
|
||||
RegexRemovePreprocessor(patterns=[r"^\s*$"]),
|
||||
CustomRegexRemovePreprocessor,
|
||||
],
|
||||
template_name="mdoutput",
|
||||
extra_template_basedirs=["./scripts/notebook_convert_templates"],
|
||||
|
Loading…
Reference in New Issue
Block a user