Remove -s binder switch.
[diouzhtu.git] / diouzhtu / src / diouzhtu.adb
blob7643bed79b002ba2e072cc0a94d4efed32860cf4
1 ------------------------------------------------------------------------------
2 -- Diouzhtu --
3 -- --
4 -- Copyright (C) 2007-2008 --
5 -- Olivier Ramonat --
6 -- --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
11 -- --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
16 -- --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
22 with Ada.Containers.Vectors;
24 package body Diouzhtu is
26 use Ada;
27 use Ada.Strings.Unbounded;
29 type Callback is record
30 To_HTML : Converter;
31 end record;
33 package Callbacks is new Containers.Vectors
34 (Index_Type => Positive,
35 Element_Type => Callback,
36 "=" => "=");
37 use Callbacks;
39 Blocks : Vector := Empty_Vector;
40 Inlines : Vector := Empty_Vector;
42 ----------------
43 -- Initialize --
44 ----------------
46 function Initialize
47 (Base_URL : in String;
48 Img_Base_URL : in String;
49 Text_Directory : in String)
50 return Wiki_Information is
51 begin
52 return Wiki_Information'
53 (Base_URL => To_Unbounded_String (Base_URL),
54 Img_Base_URL => To_Unbounded_String (Img_Base_URL),
55 Text_Directory => To_Unbounded_String (Text_Directory));
56 end Initialize;
58 -----------------------
59 -- Internal_Register --
60 -----------------------
62 procedure Internal_Register
63 (Level : in Register_Level;
64 To_HTML : in Converter)
66 Register_Callback : Callback;
67 begin
68 Register_Callback.To_HTML := To_HTML;
69 if Level = Block_Level then
70 Blocks.Append (Register_Callback);
71 else
72 Inlines.Append (Register_Callback);
73 end if;
74 end Internal_Register;
76 -----------
77 -- Parse --
78 -----------
80 function Parse
81 (Wiki : in Wiki_Information;
82 Level : in Register_Level;
83 Content : in String;
84 Index : in Natural := 0)
85 return String
87 Current : Positive;
88 Container : Vector;
89 begin
90 if Level = Block_Level then
91 Container := Blocks;
92 else
93 Container := Inlines;
94 end if;
96 if Index = 0 then
97 Current := Container.First_Index;
98 else
99 Current := Index + 1;
100 end if;
102 if Last_Index (Container) >= Current then
103 return Callback (Element (Container, Current)).To_HTML
104 (Wiki, Current, Content);
105 end if;
107 return Content;
108 end Parse;
110 --------------
111 -- Register --
112 --------------
114 procedure Register
115 (Level : in Register_Level;
116 To_HTML : Converter)
118 Register_Callback : Callback;
119 begin
120 -- ???
121 -- First Inlines callback is code and user callbacks should
122 -- not erase this.
123 -- Insert them after code callback
125 Register_Callback.To_HTML := To_HTML;
126 if Level = Block_Level then
127 Blocks.Prepend (New_Item => Register_Callback);
128 else
129 Inlines.Insert (Before => Next (Inlines.First),
130 New_Item => Register_Callback);
131 end if;
132 end Register;
134 end Diouzhtu;