Skip to content

Commit

Permalink
Ajustes
Browse files Browse the repository at this point in the history
  • Loading branch information
michelmetran committed Nov 29, 2023
1 parent 8f500cd commit c0693a3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion my_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,45 @@
Summary
"""

import os
from pathlib import Path

from nbconvert import MarkdownExporter
from nbconvert.preprocessors import TagRemovePreprocessor
from traitlets.config import Config


def convert2md(input_file, output_file):
# Import the exporter
c = Config()
c.TagRemovePreprocessor.enabled = True
c.ClearOutputPreprocessor.enabled = True
c.TemplateExporter.exclude_markdown = False
c.TemplateExporter.exclude_code_cell = False
c.TemplateExporter.exclude_output = True
c.TemplateExporter.exclude_raw = False
c.TemplateExporter.exclude_input_prompt = True
c.TagRemovePreprocessor.remove_cell_tags = ['remove_cell']
c.TagRemovePreprocessor.remove_cell_tags = ('remove_cell',)
c.TagRemovePreprocessor.remove_input_tags = ('remove_cell',)
c.TagRemovePreprocessor.remove_input_tags = ('remove_input',)
c.TagRemovePreprocessor.remove_all_outputs_tags = ('remove_output',)
c.preprocessors = ['TagRemovePreprocessor']
c.HTMLExporter.preprocessors = [
'nbconvert.preprocessors.TagRemovePreprocessor'
]

# Configure and run out exporter
md_exporter = MarkdownExporter(config=c)
md_exporter.register_preprocessor(TagRemovePreprocessor(config=c), True)

# Configure and run out exporter - returns a tuple - first element with html, second with notebook metadata
body, metadata = MarkdownExporter(config=c).from_filename(input_file)

# Write to output html file
with open(output_file, 'w') as f:
f.write(body)


project_path = Path(__file__).parent
post_path = project_path / 'collections' / '_posts'

Expand All @@ -15,6 +51,8 @@

for ipynb in list_ipynb:
print(ipynb)
print(ipynb.parent)
convert2md(input_file=ipynb, output_file=ipynb.parent / f'{ipynb.stem}.md')


print('Helloooooo')

0 comments on commit c0693a3

Please sign in to comment.