
    ^h
                    F    S r SSKJr  SSKJrJr  S rSS jrS rS r	S	 r
g
)z8Code for converting notebooks to and from the v2 format.    )annotations   )nbformatnbformat_minorc                <   [        U [        5      (       a(  U R                  5        H  u  p[        U5      X'   M     U $ [        U [        5      (       a#  [        U 5       H  u  p2[        U5      X'   M     U $ [        U [        5      (       a  U R                  S5      n U $ )zVThere should be no bytes objects in a notebook

v2 stores png/jpeg as b64 ascii bytes
ascii)
isinstancedictitems_unbyteslist	enumeratebytesdecode)objkvis       M/home/james-whalen/.local/lib/python3.13/site-packages/nbformat/v3/convert.pyr   r   
   s    
 #tIIKDAa[CF   J 
C		cNDAa[CF #
 J 
C		jj!J    c                   US:X  aT  [         U l         [        U l        SU l        [        U 5      n U S    H!  nUS    H  nUR	                  S0 5        M     M#     U $ US:X  a  U[        :w  a  X l        [        U l        U $ SU-  n[        U5      e)a,  Convert a notebook to v3.

Parameters
----------
nb : NotebookNode
    The Python representation of the notebook to convert.
from_version : int
    The original version of the notebook to convert.
from_minor : int
    The original minor version of the notebook to convert (only relevant for v >= 3).
   
worksheetscellsmetadata   zZCannot convert a notebook directly from v%s to v3.  Try using the nbformat.convert module.)r   r   orig_nbformatr   
setdefaultorig_nbformat_minor
ValueError)nbfrom_version
from_minorwscellmsgs         r   upgrader'      s     q*b\\"B7
B/ $ # 	q'%/"*		13?	@  S/r   c                j    SU l         U R                  SS5      nSU-  S-   U R                  -   U l        g)z-turn heading cell into corresponding markdownmarkdownlevelr   # N)	cell_typepopsource)r%   r*   s     r   heading_to_mdr0   >   s2    DNHHWa E+#dkk1DKr   c                    SU l         g)zlet raw passthrough as markdownr)   N)r-   )r%   s    r   	raw_to_mdr2   E   s	    DNr   c                    U R                   S:w  a  U $ SU l         U R                   HP  nUR                   H=  nUR                  S:X  a  [	        U5        M   UR                  S:X  d  M2  [        U5        M?     MR     U $ )zConvert a v3 notebook to v2.

Parameters
----------
nb : NotebookNode
    The Python representation of the notebook to convert.
r   r   headingraw)r   r   r   r-   r0   r2   )r!   r$   r%   s      r   	downgrader6   J   sf     
{{a	BKmmHHD~~*d#5($	   Ir   N)r   r   )__doc__
__future__r   nbbaser   r   r   r'   r0   r2   r6    r   r   <module>r;      s*    > # ," F2 
r   