docs: ignore nb echo:false blocks (#21624)

not working currently
pull/19608/head
Erick Friis 3 weeks ago committed by GitHub
parent 63c3a0e56c
commit fe8c9d621a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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…
Cancel
Save