Skip to content

Commit 55441ec

Browse files
committed
Merge branch 'topic/vadim/odf' into 'edge'
Replace multiple spaces by `text:s` element in code blocks See merge request eng/ide/gnatdoc!173
2 parents 9e63e97 + 7536bc1 commit 55441ec

File tree

1 file changed

+124
-17
lines changed

1 file changed

+124
-17
lines changed

source/backend/odf/gnatdoc-backend-odf_markup.adb

Lines changed: 124 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with VSS.Characters;
1819
with VSS.IRIs;
20+
with VSS.Strings.Character_Iterators;
21+
with VSS.Strings.Formatters.Integers;
22+
with VSS.Strings.Markers;
23+
with VSS.Strings.Templates;
1924
with VSS.XML.Events;
2025

2126
with Markdown.Attribute_Lists;
@@ -48,7 +53,9 @@ package body GNATdoc.Backend.ODF_Markup is
4853
List_Element : constant VSS.Strings.Virtual_String := "list";
4954
List_Item_Element : constant VSS.Strings.Virtual_String := "list-item";
5055
P_Element : constant VSS.Strings.Virtual_String := "p";
56+
S_Element : constant VSS.Strings.Virtual_String := "s";
5157

58+
C_Attribute : constant VSS.Strings.Virtual_String := "c";
5259
Height_Attribute : constant VSS.Strings.Virtual_String := "height";
5360
Style_Name_Attribute : constant VSS.Strings.Virtual_String := "style-name";
5461
Width_Attribute : constant VSS.Strings.Virtual_String := "width";
@@ -202,6 +209,121 @@ package body GNATdoc.Backend.ODF_Markup is
202209
end loop;
203210
end Build_Block_Container;
204211

212+
procedure Write_Code_Block
213+
(Output : in out VSS.XML.Event_Vectors.Vector;
214+
Text : VSS.String_Vectors.Virtual_String_Vector);
215+
216+
----------------------
217+
-- Write_Code_Block --
218+
----------------------
219+
220+
procedure Write_Code_Block
221+
(Output : in out VSS.XML.Event_Vectors.Vector;
222+
Text : VSS.String_Vectors.Virtual_String_Vector)
223+
is
224+
Template : VSS.Strings.Templates.Virtual_String_Template := "{}";
225+
226+
begin
227+
for Index in Text.First_Index .. Text.Last_Index loop
228+
if Index /= Text.First_Index then
229+
Write_Start_Element (Output, Text_Namespace, Line_Break_Element);
230+
Write_End_Element (Output, Text_Namespace, Line_Break_Element);
231+
end if;
232+
233+
declare
234+
use type VSS.Characters.Virtual_Character;
235+
236+
procedure Write_Text_S;
237+
238+
procedure Set_From_To_Next;
239+
240+
Line : constant VSS.Strings.Virtual_String :=
241+
Text.Element (Index);
242+
From : VSS.Strings.Markers.Character_Marker :=
243+
Line.At_First_Character.Marker;
244+
Iterator : VSS.Strings.Character_Iterators.Character_Iterator :=
245+
Line.Before_First_Character;
246+
Character : VSS.Characters.Virtual_Character'Base;
247+
Count : Natural := 0;
248+
249+
----------------------
250+
-- Set_From_To_Next --
251+
----------------------
252+
253+
procedure Set_From_To_Next is
254+
Aux : VSS.Strings.Character_Iterators.Character_Iterator;
255+
256+
begin
257+
Aux.Set_At (Iterator);
258+
259+
if Aux.Forward then
260+
From := Aux.Marker;
261+
262+
else
263+
From := Line.After_Last_Character.Marker;
264+
end if;
265+
end Set_From_To_Next;
266+
267+
------------------
268+
-- Write_Text_S --
269+
------------------
270+
271+
procedure Write_Text_S is
272+
begin
273+
Write_Start_Element (Output, Text_Namespace, S_Element);
274+
275+
if Count > 2 then
276+
Write_Attribute
277+
(Output,
278+
Text_Namespace,
279+
C_Attribute,
280+
Template.Format (VSS.Strings.Formatters.Integers.Image
281+
(Count - 1)));
282+
end if;
283+
284+
Write_End_Element (Output, Text_Namespace, S_Element);
285+
end Write_Text_S;
286+
287+
begin
288+
while Iterator.Forward (Character) loop
289+
if Character = ' ' then
290+
if Count = 0 then
291+
Write_Text (Output, Line.Slice (From, Iterator));
292+
Set_From_To_Next;
293+
Count := 1;
294+
295+
else
296+
Set_From_To_Next;
297+
Count := @ + 1;
298+
end if;
299+
300+
else
301+
if Count = 0 then
302+
null;
303+
304+
elsif Count = 1 then
305+
Count := 0;
306+
307+
else
308+
Write_Text_S;
309+
Count := 0;
310+
end if;
311+
end if;
312+
end loop;
313+
314+
if Count = 0 then
315+
Write_Text (Output, Line.Tail_From (From));
316+
317+
elsif Count = 1 then
318+
null;
319+
320+
else
321+
Write_Text_S;
322+
end if;
323+
end;
324+
end loop;
325+
end Write_Code_Block;
326+
205327
-------------------------------
206328
-- Build_Code_Snipped_Markup --
207329
-------------------------------
@@ -218,15 +340,7 @@ package body GNATdoc.Backend.ODF_Markup is
218340
Style_Name_Attribute,
219341
GNATdoc_Code_Block_Style);
220342

221-
for Index in Text.First_Index .. Text.Last_Index loop
222-
if Index /= Text.First_Index then
223-
Write_Start_Element
224-
(Result, Text_Namespace, Line_Break_Element);
225-
Write_End_Element (Result, Text_Namespace, Line_Break_Element);
226-
end if;
227-
228-
Write_Text (Result, Text.Element (Index));
229-
end loop;
343+
Write_Code_Block (Result, Text);
230344

231345
Write_End_Element (Result, Text_Namespace, P_Element);
232346
end return;
@@ -247,14 +361,7 @@ package body GNATdoc.Backend.ODF_Markup is
247361
Style_Name_Attribute,
248362
GNATdoc_Code_Block_Style);
249363

250-
for Index in Item.Text.First_Index .. Item.Text.Last_Index loop
251-
if Index /= Item.Text.First_Index then
252-
Write_Start_Element (Result, Text_Namespace, Line_Break_Element);
253-
Write_End_Element (Result, Text_Namespace, Line_Break_Element);
254-
end if;
255-
256-
Write_Text (Result, Item.Text.Element (Index));
257-
end loop;
364+
Write_Code_Block (Result, Item.Text);
258365

259366
Write_End_Element (Result, Text_Namespace, P_Element);
260367
end Build_Indented_Code_Block;

0 commit comments

Comments
 (0)