66# SPDX-License-Identifier: GPL-2.0-or-later
77
88# #
9- InstallGlobalFunction( INSERT_IN_STRING_WITH_REPLACE,
9+ BindGlobal( " INSERT_IN_STRING_WITH_REPLACE" ,
1010 function ( string, new_string, position, nr_letters_to_be_replaced )
1111 return Concatenation(
1212 string{[ 1 .. position - 1 ]} ,
@@ -15,6 +15,70 @@ InstallGlobalFunction( INSERT_IN_STRING_WITH_REPLACE,
1515 );
1616end );
1717
18+ # #
19+ BindGlobal( " AUTODOC_EscapeXMLTextForInlineCode" ,
20+ function ( string )
21+ local escaped_string, split_pos;
22+
23+ escaped_string := " " ;
24+ while Length(string) > 0 do
25+ split_pos := PositionProperty( string, c -> c in " &\" <>" );
26+ if split_pos = fail then
27+ Append( escaped_string, string );
28+ break ;
29+ fi ;
30+ if split_pos > 1 then
31+ Append( escaped_string, string{ [ 1 .. split_pos - 1 ] } );
32+ fi ;
33+ if string[ split_pos ] = ' &' then
34+ Append( escaped_string, " &" );
35+ elif string[ split_pos ] = ' "' then
36+ Append( escaped_string, " "" );
37+ elif string[ split_pos ] = ' <' then
38+ Append( escaped_string, " <" );
39+ else
40+ Append( escaped_string, " >" );
41+ fi ;
42+ string := string{ [ split_pos + 1 .. Length( string ) ] } ;
43+ od ;
44+
45+ return escaped_string;
46+ end );
47+
48+ # #
49+ BindGlobal( " AUTODOC_ConvertInlineBackticksInLine" ,
50+ function ( string, keyword_set )
51+ local opening_pos, closing_pos, inline_content, tag_name;
52+
53+ while PositionSublist( string, " `" ) <> fail do
54+ opening_pos := PositionSublist( string, " `" );
55+ closing_pos := PositionSublist( string, " `" , opening_pos + 1 );
56+ if closing_pos = fail then
57+ Error( " did you forget some `" );
58+ fi ;
59+
60+ if opening_pos + 1 <= closing_pos - 1 then
61+ inline_content := string{ [ opening_pos + 1 .. closing_pos - 1 ] } ;
62+ else
63+ inline_content := " " ;
64+ fi ;
65+ if inline_content in keyword_set then
66+ tag_name := " Keyword" ;
67+ else
68+ tag_name := " Code" ;
69+ fi ;
70+ string := Concatenation(
71+ string{ [ 1 .. opening_pos - 1 ] } ,
72+ " <" , tag_name, " >" ,
73+ AUTODOC_EscapeXMLTextForInlineCode( inline_content ),
74+ " </" , tag_name, " >" ,
75+ string{ [ closing_pos + 1 .. Length( string ) ] }
76+ );
77+ od ;
78+
79+ return string;
80+ end );
81+
1882# #
1983InstallGlobalFunction( CONVERT_LIST_OF_STRINGS_IN_MARKDOWN_TO_GAPDOC_XML,
2084 function ( string_list )
@@ -23,8 +87,7 @@ InstallGlobalFunction( CONVERT_LIST_OF_STRINGS_IN_MARKDOWN_TO_GAPDOC_XML,
2387 commands, position_of_command, insert, beginning_whitespaces, temp, string_list_temp, skipped,
2488 already_inserted_paragraph, in_list, in_item, converted_string_list,
2589 fence_char, fence_length, trimmed_line, code_block, info_string,
26- fence_element, keyword_set, opening_pos, closing_pos, inline_content,
27- tag_name;
90+ fence_element, keyword_set;
2891
2992 converted_string_list := [ ] ;
3093 i := 1 ;
@@ -94,6 +157,25 @@ InstallGlobalFunction( CONVERT_LIST_OF_STRINGS_IN_MARKDOWN_TO_GAPDOC_XML,
94157 od ;
95158 string_list := converted_string_list;
96159
160+ # Convert inline backticks before list detection so literal tags such as
161+ # `<List>` inside code spans do not look like structural GAPDoc tags.
162+ keyword_set := Set( ALL_KEYWORDS() );
163+ skipped := false ;
164+ for i in [ 1 .. Length( string_list ) ] do
165+ if PositionSublist( string_list[ i ] , " <![CDATA[" ) <> fail then
166+ skipped := true ;
167+ fi ;
168+ if PositionSublist( string_list[ i ] , " ]]>" ) <> fail then
169+ skipped := false ;
170+ continue ;
171+ fi ;
172+ if skipped = true then
173+ continue ;
174+ fi ;
175+ string_list[ i ] :=
176+ AUTODOC_ConvertInlineBackticksInLine( string_list[ i ] , keyword_set );
177+ od ;
178+
97179 # # Check for paragraphs by turning an empty string into <P/>
98180
99181 already_inserted_paragraph := false ;
@@ -218,45 +300,6 @@ InstallGlobalFunction( CONVERT_LIST_OF_STRINGS_IN_MARKDOWN_TO_GAPDOC_XML,
218300 [ " $" , " Math" ] ,
219301 [ " **" , " Emph" ] ,
220302 [ " __" , " Emph" ] ] ;
221- keyword_set := Set( ALL_KEYWORDS() );
222-
223- skipped := false ;
224- for i in [ 1 .. Length( string_list ) ] do
225- if PositionSublist( string_list[ i ] , " <![CDATA[" ) <> fail then
226- skipped := true ;
227- fi ;
228- if PositionSublist( string_list[ i ] , " ]]>" ) <> fail then
229- skipped := false ;
230- continue ;
231- fi ;
232- if skipped = true then
233- continue ;
234- fi ;
235-
236- while PositionSublist( string_list[ i ] , " `" ) <> fail do
237- opening_pos := PositionSublist( string_list[ i ] , " `" );
238- closing_pos := PositionSublist( string_list[ i ] , " `" , opening_pos + 1 );
239- if closing_pos = fail then
240- Error( " did you forget some `" );
241- fi ;
242-
243- if opening_pos + 1 <= closing_pos - 1 then
244- inline_content := string_list[ i ]{ [ opening_pos + 1 .. closing_pos - 1 ] } ;
245- else
246- inline_content := " " ;
247- fi ;
248- if inline_content in keyword_set then
249- tag_name := " Keyword" ;
250- else
251- tag_name := " Code" ;
252- fi ;
253- string_list[ i ] := Concatenation(
254- string_list[ i ]{ [ 1 .. opening_pos - 1 ] } ,
255- " <" , tag_name, " >" , inline_content, " </" , tag_name, " >" ,
256- string_list[ i ]{ [ closing_pos + 1 .. Length( string_list[ i ] ) ] }
257- );
258- od ;
259- od ;
260303
261304 # # special handling for \$
262305 for i in [ 1 .. Length( string_list ) ] do
0 commit comments