@@ -30,13 +30,135 @@ describe('Jupyter converter', () => {
3030 const ipynb = JSON . parse ( result )
3131 expect ( ipynb . metadata . language_info . name ) . is . equal ( 'python' )
3232 expect ( ipynb . metadata . language_info . version ) . is . equal ( '2.7.10' )
33+ expect ( ipynb . metadata . kernelspec . name ) . is . equal ( 'python3' )
34+ expect ( ipynb . metadata . kernelspec . language ) . is . equal ( 'python' )
3335 expect ( ipynb . cells . length ) . is . equal ( 32 )
3436 const codeCells = ipynb . cells . filter ( cell => cell . cell_type === 'code' )
3537 expect ( codeCells . length ) . is . equal ( 21 )
3638 expect ( codeCells [ 0 ] . source . join ( '' ) ) . is . equal ( `from py2neo import Graph
3739
3840graph = Graph()
3941` )
42+ } )
43+ it ( 'should configure language with document attributes' , async ( ) => {
44+ const result = asciidoctor . convert ( `= Hello World
45+ :jupyter-language-name: c++
46+ :jupyter-language-version: 17
47+
48+ ` , { backend : 'jupyter' } )
49+ expect ( result ) . is . not . empty ( )
50+ const ipynb = JSON . parse ( result )
51+ expect ( ipynb . metadata . language_info . name ) . is . equal ( 'c++' )
52+ expect ( ipynb . metadata . language_info . version ) . is . equal ( '17' )
53+ } )
54+ it ( 'should configure kernelspec with document attributes' , async ( ) => {
55+ const result = asciidoctor . convert ( `= Hello World
56+ :jupyter-language-name: c++
57+ :jupyter-language-version: 17
58+ :jupyter-kernel-name: xcpp17
59+ :jupyter-kernel-language: C++17
60+
61+ ` , { backend : 'jupyter' } )
62+ expect ( result ) . is . not . empty ( )
63+ const ipynb = JSON . parse ( result )
64+ expect ( ipynb . metadata . language_info . name ) . is . equal ( 'c++' )
65+ expect ( ipynb . metadata . language_info . version ) . is . equal ( '17' )
66+ expect ( ipynb . metadata . kernelspec . name ) . is . equal ( 'xcpp17' )
67+ expect ( ipynb . metadata . kernelspec . language ) . is . equal ( 'C++17' )
68+ } )
69+ it ( 'should convert source blocks depending on language name (C++)' , async ( ) => {
70+ const result = asciidoctor . convert ( `= Hello World
71+ :jupyter-language-name: c++
72+ :jupyter-language-version: 17
73+ :jupyter-kernel-name: xcpp17
74+ :jupyter-kernel-language: C++17
75+
76+ .Python
77+ [source,py]
78+ ----
79+ print('hello')
80+ ----
81+
82+ .C{pp}
83+ [source,cpp]
84+ ----
85+ int i=1;
86+ ----
87+ ` , { backend : 'jupyter' } )
88+ expect ( result ) . is . not . empty ( )
89+ const ipynb = JSON . parse ( result )
90+ expect ( ipynb . cells . length ) . is . equal ( 2 )
91+ expect ( ipynb . cells [ 0 ] . cell_type ) . is . equal ( 'markdown' )
92+ expect ( ipynb . cells [ 0 ] . source . join ( '' ) ) . is . equal ( `# Hello World
93+
94+ \`\`\`py
95+ print('hello')
96+ \`\`\`` )
97+ expect ( ipynb . cells [ 1 ] . cell_type ) . is . equal ( 'code' )
98+ expect ( ipynb . cells [ 1 ] . source . join ( '' ) ) . is . equal ( `int i=1;
99+ ` )
100+ } )
101+ it ( 'should convert source blocks depending on language name (Python)' , async ( ) => {
102+ const result = asciidoctor . convert ( `= Hello World
103+ :jupyter-language-name: python
104+ :jupyter-language-version: 3.11.5
105+
106+ .Python
107+ [source,py]
108+ ----
109+ print('hello')
110+ ----
111+
112+ .C{pp}
113+ [source,cpp]
114+ ----
115+ int i=1;
116+ ----
117+ ` , { backend : 'jupyter' } )
118+ expect ( result ) . is . not . empty ( )
119+ const ipynb = JSON . parse ( result )
120+ expect ( ipynb . cells . length ) . is . equal ( 3 )
121+ expect ( ipynb . cells [ 0 ] . cell_type ) . is . equal ( 'markdown' )
122+ expect ( ipynb . cells [ 0 ] . source . join ( '' ) ) . is . equal ( `# Hello World
123+
124+ ` )
125+ expect ( ipynb . cells [ 1 ] . cell_type ) . is . equal ( 'code' )
126+ expect ( ipynb . cells [ 1 ] . source . join ( '' ) ) . is . equal ( `print('hello')
127+ ` )
128+ expect ( ipynb . cells [ 2 ] . cell_type ) . is . equal ( 'markdown' )
129+ expect ( ipynb . cells [ 2 ] . source . join ( '' ) ) . is . equal ( `\`\`\`cpp
130+ int i=1;
131+ \`\`\`` )
132+ } )
133+ it ( 'should convert source blocks depending on language name (default -> Python)' , async ( ) => {
134+ const result = asciidoctor . convert ( `= Hello World
135+
136+ .Python
137+ [source,py]
138+ ----
139+ print('hello')
140+ ----
141+
142+ .C{pp}
143+ [source,cpp]
144+ ----
145+ int i=1;
146+ ----
147+ ` , { backend : 'jupyter' } )
148+ expect ( result ) . is . not . empty ( )
149+ const ipynb = JSON . parse ( result )
150+ expect ( ipynb . cells . length ) . is . equal ( 3 )
151+ expect ( ipynb . cells [ 0 ] . cell_type ) . is . equal ( 'markdown' )
152+ expect ( ipynb . cells [ 0 ] . source . join ( '' ) ) . is . equal ( `# Hello World
153+
154+ ` )
155+ expect ( ipynb . cells [ 1 ] . cell_type ) . is . equal ( 'code' )
156+ expect ( ipynb . cells [ 1 ] . source . join ( '' ) ) . is . equal ( `print('hello')
157+ ` )
158+ expect ( ipynb . cells [ 2 ] . cell_type ) . is . equal ( 'markdown' )
159+ expect ( ipynb . cells [ 2 ] . source . join ( '' ) ) . is . equal ( `\`\`\`cpp
160+ int i=1;
161+ \`\`\`` )
40162 } )
41163 it ( 'should convert an exercise guide to ipynb' , async ( ) => {
42164 const inputFile = path . join ( __dirname , 'fixtures' , 'intro-neo4j-guides-01.adoc' )
0 commit comments