@@ -18,25 +18,10 @@ async function _processCodesIncludeInMarkdown(mdText, baseUrlPath) {
1818 if ( line . trim ( ) . startsWith ( "```{codes_include}" ) ) {
1919 const match = line . match ( / ` ` ` { codes_ i n c l u d e } \s + ( .* ) / ) ;
2020 if ( match ) {
21- console . log ( "Found codes_include directive:" , match [ 1 ] ) ; // Log matched directive
21+ // console.log("Found codes_include directive:", match[1]); // Log matched directive
2222 const baseName = match [ 1 ] . trim ( ) ;
2323
2424 // Generate HTML as a string
25- // const tabsHtml = `
26- // <div class="code-editor-tab-container" data-base-name="${baseName}">
27- // <div class="code-editor-tab-buttons">
28- // <button class="code-editor-tab-button active" data-tab="Python">Python</button>
29- // <button class="code-editor-tab-button" data-tab="C++">C++</button>
30- // </div>
31- // <div class="code-editor-tab-content">
32- // <div class="code-editor-tab-pane" data-language="Python" data-file="${baseName}.py">
33- // <div class="codemirror-placeholder" data-language="python"></div>
34- // </div>
35- // <div class="code-editor-tab-pane hidden" data-language="C++" data-file="${baseName}.cpp">
36- // <div class="codemirror-placeholder" data-language="cpp"></div>
37- // </div>
38- // </div>
39- // </div>`;
4025 const tabsHtml = `
4126<div class="code-editor-tab-container" data-base-name="${ baseName } ">
4227 <div class="code-editor-tab-buttons">
@@ -52,9 +37,7 @@ async function _processCodesIncludeInMarkdown(mdText, baseUrlPath) {
5237 </div>
5338 </div>
5439</div>` ;
55-
56-
57- console . log ( "Generated HTML for tabs:" , tabsHtml ) ; // Debug log
40+ // console.log("Generated HTML for tabs:", tabsHtml); // Debug log
5841 processedLines . push ( tabsHtml ) ;
5942 }
6043 insideCodesIncludeBlock = true ;
@@ -68,31 +51,37 @@ async function _processCodesIncludeInMarkdown(mdText, baseUrlPath) {
6851 return processedLines . join ( "\n" ) ;
6952}
7053
54+
7155async function _initializeCodeMirrorEditors ( baseUrlPath ) {
7256 const containers = document . querySelectorAll ( ".code-editor-tab-container" ) ;
7357
74- console . log ( "Found Code Editor Containers:" , containers . length ) ; // Debug log
58+ // console.log("Found Code Editor Containers:", containers.length); // Debug log
7559
7660 for ( const container of containers ) {
7761 const tabPanes = container . querySelectorAll ( ".code-editor-tab-pane" ) ;
7862
79- console . log ( "Found Tab Panes:" , tabPanes . length ) ; // Debug log
63+ // console.log("Found Tab Panes:", tabPanes.length); // Debug log
8064
8165 for ( const tabPane of tabPanes ) {
8266 const filePath = tabPane . dataset . file ;
8367 const language = tabPane . dataset . language . toLowerCase ( ) ;
8468
85- console . log ( `Initializing CodeMirror for file: ${ filePath } , language: ${ language } ` ) ; // Debug log
69+ // console.log(`Initializing CodeMirror for file: ${filePath}, language: ${language}`); // Debug log
8670
8771 try {
88- const fileResponse = await fetch ( `${ baseUrlPath } ${ filePath } ` ) ;
72+ // Correctly handle baseUrlPath and filePath to avoid duplication
73+ // Relative path; combine with baseUrlPath
74+ let fullPath = new URL ( filePath , `${ window . location . origin } /${ baseUrlPath } /` ) . toString ( ) ;
75+ // console.log(`Full Path for Fetch: ${fullPath}`); // Debug log
76+
77+ const fileResponse = await fetch ( fullPath ) ;
8978 if ( ! fileResponse . ok ) {
90- console . warn ( `File not found: ${ baseUrlPath } ${ filePath } ` ) ;
79+ console . warn ( `File not found: ${ fullPath } ` ) ;
9180 continue ;
9281 }
9382
9483 const codeContent = await fileResponse . text ( ) ;
95- console . log ( `Fetched Code Content for ${ filePath } :\n` , codeContent ) ; // Debug log
84+ // console.log(`Fetched Code Content for ${filePath}:\n`, codeContent); // Debug log
9685
9786 const cmPlaceholder = tabPane . querySelector ( ".codemirror-placeholder" ) ;
9887
@@ -129,16 +118,17 @@ async function _initializeCodeMirrorEditors(baseUrlPath) {
129118 _setupCodeEditorTabs ( containers ) ; // Ensure tab setup is called
130119}
131120
121+
132122function _setupCodeEditorTabs ( containers ) {
133123 containers . forEach ( ( container ) => {
134124 const buttons = container . querySelectorAll ( ".code-editor-tab-button" ) ;
135125 const panes = container . querySelectorAll ( ".code-editor-tab-pane" ) ;
136126
137127 buttons . forEach ( ( button ) => {
138- console . log ( `Attaching click event to button: ${ button . dataset . tab } ` ) ; // Debugging log
128+ // console.log(`Attaching click event to button: ${button.dataset.tab}`); // Debugging log
139129 button . addEventListener ( "click" , ( ) => {
140130 const targetTab = button . dataset . tab ;
141- console . log ( `Tab clicked: ${ targetTab } ` ) ; // Debugging log
131+ // console.log(`Tab clicked: ${targetTab}`); // Debugging log
142132
143133 // Deactivate all buttons and panes
144134 buttons . forEach ( ( btn ) => btn . classList . remove ( "active" ) ) ;
@@ -191,12 +181,13 @@ export async function prepareCodeEditors(mdText, baseUrlPath) {
191181 const renderedHtml = marked ( processedMdText ) ;
192182
193183 // Debug log: Final rendered HTML
194- console . log ( "Final Rendered HTML:" , renderedHtml ) ;
184+ // console.log("Final Rendered HTML:", renderedHtml);
195185
196186 // Update the content area with the rendered HTML
197187 const contentArea = document . getElementById ( "content-area" ) ;
198188 contentArea . innerHTML = renderedHtml ;
199189
200190 // Initialize CodeMirror editors for the placeholders
201- await _initializeCodeMirrorEditors ( baseUrlPath ) ;
191+ //await _initializeCodeMirrorEditors(baseUrlPath);
192+ await _initializeCodeMirrorEditors ( "jbook" ) ;
202193}
0 commit comments