@@ -2,13 +2,33 @@ const fs = require("fs");
22const path = require ( "path" ) ;
33const entities = require ( "entities" ) ;
44
5+ const specificReplacements = {
6+ "<<string>>" : "`string`" ,
7+ "<<String>>" : "`String`" ,
8+ "<<Object>>" : "`Object`" ,
9+ "<<object>>" : "`object`" ,
10+ "<<integer>>" : "`integer`" ,
11+ "<<Integer>>" : "`Integer`" ,
12+ } ;
13+
514// Function to capitalize the first letter of a string
615const capitalizeFirstLetter = ( string ) => {
716 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
817} ;
918
19+ // Function to process special case
20+ function processSpecialCase ( line ) {
21+ const match = line . match ( / ( .* ?) ( _ .* ?_ ) ( .* ) / ) ;
22+ if ( match ) {
23+ const [ _ , part1 , part2 , part3 ] = match ;
24+ return `${ part1 } ${ part2 } \n${ part3 } ` ;
25+ }
26+ return line ;
27+ }
28+
1029// Function to update the AsciiDoc file
1130const updateAsciiDoc = ( filePath ) => {
31+ const context = path . basename ( fileName , path . extname ( fileName ) ) ;
1232 // Read the file
1333 fs . readFile ( filePath , "utf8" , ( err , data ) => {
1434 if ( err ) {
@@ -43,11 +63,16 @@ const updateAsciiDoc = (filePath) => {
4363
4464 // Stop processing when we encounter '[#models]'
4565 if ( line . startsWith ( "[#models]" ) ) {
46- updatedLines . push ( '[id="common-object-reference "]' ) ;
66+ updatedLines . push ( '[id="common-object-reference_{context} "]' ) ;
4767 updatedLines . push ( "== Common object reference" ) ;
4868 updatedLines . push ( "" ) ;
4969 for ( let j = i + 2 ; j < lines . length ; j ++ ) {
50- const decodedLine = entities . decodeHTML ( lines [ j ] ) ;
70+ let decodedLine = entities . decodeHTML ( lines [ j ] ) ;
71+
72+ //replace \" with "
73+ if ( decodedLine . includes ( '"' ) ) {
74+ decodedLine = decodedLine . replace ( / \" / g, '"' ) ;
75+ }
5176
5277 // Check if the current line is "JSON" and skip it
5378 if ( decodedLine . trim ( ) === "JSON" ) {
@@ -60,6 +85,49 @@ const updateAsciiDoc = (filePath) => {
6085 continue ; // Skip adding the original "====" line
6186 }
6287
88+ if ( decodedLine . startsWith ( "[#" ) ) {
89+ const updatedLine = decodedLine . replace (
90+ / \[ ( # ) ( .* ) \] / g,
91+ ( match , p1 , p2 ) => {
92+ return `[id="${ p2 } _{context}"]` ;
93+ }
94+ ) ;
95+ updatedLines . push ( updatedLine ) ;
96+ continue ;
97+ }
98+
99+ // New case for updated lines starting with '=' and containing '_<some-text>_'
100+ if ( decodedLine . startsWith ( "=" ) && / _ [ ^ _ ] + _ / . test ( decodedLine ) ) {
101+ decodedLine = processSpecialCase ( decodedLine ) ;
102+ updatedLines . push ( decodedLine ) ;
103+ continue ;
104+ }
105+
106+ if ( decodedLine . includes ( "<<" ) && decodedLine . includes ( ">>" ) ) {
107+ // Check for the specific edge case
108+ if ( decodedLine . includes ( "<<Stream_result_of_" ) ) {
109+ decodedLine = decodedLine . replace (
110+ / < < S t r e a m _ r e s u l t _ o f _ ( .* ?) > > / g,
111+ ( match , p1 ) => {
112+ // Capitalize the first letter of p1
113+ const capitalizedP1 =
114+ p1 . charAt ( 0 ) . toUpperCase ( ) + p1 . slice ( 1 ) ;
115+ return `<<StreamResultOf${ capitalizedP1 } _{context}, Stream_result_of_${ p1 } >>` ;
116+ }
117+ ) ;
118+ } else {
119+ for ( const [ key , value ] of Object . entries ( specificReplacements ) ) {
120+ decodedLine = decodedLine . replace ( new RegExp ( key , "g" ) , value ) ;
121+ }
122+
123+ decodedLine = decodedLine . replace ( / < < ( [ ^ > ] * ) > > / g, ( match , p1 ) => {
124+ return `<<${ p1 } _{context}, ${ p1 } >>` ;
125+ } ) ;
126+ }
127+
128+ updatedLines . push ( decodedLine ) ;
129+ continue ;
130+ }
63131 updatedLines . push ( decodedLine ) ;
64132 }
65133 break ;
@@ -69,14 +137,17 @@ const updateAsciiDoc = (filePath) => {
69137 if ( updatedLines . length === 0 ) {
70138 updatedLines . push ( "// Auto-generated by scripts. Do not edit." ) ;
71139 updatedLines . push ( ":_mod-docs-content-type: ASSEMBLY" ) ;
140+ updatedLines . push ( `:context: ${ context } ` ) ;
72141 updatedLines . push ( "" ) ;
73142 nextHeadingIsMainHeading = true ;
74143 }
75144
76145 // Capitalize the first letter of lines starting with '[.'
77146 if ( line . startsWith ( "[." ) ) {
78147 const updatedLine = line . slice ( 2 , - 1 ) . trim ( ) ; // Remove '[.' and trim spaces, then remove last character
79- updatedLines . push ( `[id="${ capitalizeFirstLetter ( updatedLine ) } "]` ) ; // Format as [id="..."]
148+ updatedLines . push (
149+ `[id="${ capitalizeFirstLetter ( updatedLine ) } _{context}"]`
150+ ) ;
80151 continue ;
81152 }
82153
@@ -104,6 +175,11 @@ const updateAsciiDoc = (filePath) => {
104175 updatedLine = newLine ;
105176 }
106177
178+ // New case for updated lines starting with '=' and containing '_<some-text>_'
179+ if ( updatedLine . startsWith ( "=" ) && / _ < [ ^ _ ] + > _ / . test ( updatedLine ) ) {
180+ updatedLine = processSpecialCase ( updatedLine ) ;
181+ }
182+
107183 updatedLines . push ( updatedLine ) ; // Add the updated line
108184
109185 if ( nextHeadingIsMainHeading ) {
@@ -119,11 +195,51 @@ const updateAsciiDoc = (filePath) => {
119195 } else if ( equalCount === 2 ) {
120196 // If there are exactly 2 '=', just trim the line
121197 let updatedLine = line . slice ( 2 ) . trim ( ) ;
198+ // New case for updated lines starting with '=' and containing '_<some-text>_'
199+ if ( updatedLine . startsWith ( "=" ) && / _ < [ ^ _ ] + > _ / . test ( line ) ) {
200+ updatedLine = processSpecialCase ( updatedLine ) ;
201+ }
122202 updatedLines . push ( updatedLine ) ; // Add the updated line
123203 continue ;
124204 }
125205 }
126206
207+ // Check if line contains both <<some_text>> and add context to it <<some_text_{context}>>
208+ if ( line . includes ( "<<" ) && line . includes ( ">>" ) ) {
209+ let updatedLine = line ;
210+
211+ for ( const [ key , value ] of Object . entries ( specificReplacements ) ) {
212+ updatedLine = updatedLine . replace ( new RegExp ( key , "g" ) , value ) ;
213+ }
214+
215+ // Check for the specific edge case
216+ if ( updatedLine . includes ( "<<Stream_result_of_" ) ) {
217+ updatedLine = updatedLine . replace (
218+ / < < S t r e a m _ r e s u l t _ o f _ ( .* ?) > > / g,
219+ ( match , p1 ) => {
220+ // Capitalize the first letter of p1
221+ const capitalizedP1 = p1 . charAt ( 0 ) . toUpperCase ( ) + p1 . slice ( 1 ) ;
222+ return `<<StreamResultOf${ capitalizedP1 } _{context}, Stream_result_of_${ p1 } >>` ;
223+ }
224+ ) ;
225+ } else {
226+ updatedLine = updatedLine . replace ( / < < ( [ ^ > ] * ) > > / g, ( match , p1 ) => {
227+ return `<<${ p1 } _{context}, ${ p1 } >>` ;
228+ } ) ;
229+ }
230+ updatedLines . push ( updatedLine ) ;
231+ continue ;
232+ }
233+
234+ // Check if line matches [#<some-text>] and change it to [id="<some-text>_{context}"]
235+ if ( / $ $ # ( [ ^ ] ] + ) $ $ / . test ( line ) ) {
236+ const updatedLine = line . replace ( / $ $ # ( [ ^ ] ] + ) $ $ / g, ( match , p1 ) => {
237+ return `[id="${ p1 } _{context}"]` ;
238+ } ) ;
239+ updatedLines . push ( updatedLine ) ;
240+ continue ;
241+ }
242+
127243 // Push other lines unchanged
128244 updatedLines . push ( line ) ;
129245 }
0 commit comments