11from jupyter_server .base .call_context import CallContext
2- import nbformat
32
43
54def get_serverapp ():
@@ -54,7 +53,7 @@ def notebook_json_to_md(notebook_json: dict, include_outputs: bool = True) -> st
5453
5554 Returns:
5655 Markdown string representation of the notebook
57-
56+
5857 Example:
5958 ```markdown
6059 ```yaml
@@ -63,20 +62,20 @@ def notebook_json_to_md(notebook_json: dict, include_outputs: bool = True) -> st
6362 language: python
6463 name: python3
6564 ```
66-
65+
6766 ### Cell 0
68-
67+
6968 #### Metadata
7069 ```yaml
7170 type: code
7271 execution_count: 1
7372 ```
74-
73+
7574 #### Source
7675 ```python
7776 print("Hello world")
7877 ```
79-
78+
8079 #### Output
8180 ```
8281 Hello world
@@ -87,13 +86,11 @@ def notebook_json_to_md(notebook_json: dict, include_outputs: bool = True) -> st
8786 md_parts = []
8887
8988 # Add notebook metadata at the top
90- md_parts .append (
91- metadata_to_md (notebook_json .get ("metadata" , {}))
92- )
89+ md_parts .append (metadata_to_md (notebook_json .get ("metadata" , {})))
9390
9491 # Process all cells
9592 for i , cell in enumerate (notebook_json .get ("cells" , [])):
96- md_parts .append (cell_to_md (cell , index = i , include_outputs = outputs ))
93+ md_parts .append (cell_to_md (cell , index = i , include_outputs = include_outputs ))
9794
9895 # Join all parts with double newlines
9996 return "\n \n " .join (md_parts )
@@ -202,29 +199,3 @@ def format_outputs(outputs: list) -> str:
202199 result .append (f"```\n { traceback } ```" )
203200
204201 return "\n \n " .join (result )
205-
206- # Note: We might end up removing this, as nbconvert doesn't emit metadata
207- # and currently failing with server outputs
208- def nbformat_to_md (notebook : nbformat .NotebookNode , outputs : bool = False ) -> str :
209- """Converts a notebook in nbformat to markdown string
210-
211- Args:
212- notebook: The notebook to convert to markdown
213- outputs: Whether to include cell outputs in the markdown. Default is False.
214-
215- Returns:
216- Markdown string representation of the notebook
217- """
218- from nbconvert .exporters import MarkdownExporter
219-
220- # Create the markdown exporter instance
221- exporter = MarkdownExporter ()
222-
223- # Configure exporter based on outputs flag
224- if not outputs :
225- exporter .exclude_output = True
226-
227- # Convert notebook to markdown
228- markdown , _ = exporter .from_notebook_node (notebook )
229-
230- return markdown
0 commit comments