MDX does not follow the 'standard' way of parsing defintion lists. Instead, this commit adds a small filter that basically hacks some html tags to the source definition list.
193 lines
5.3 KiB
Ada
193 lines
5.3 KiB
Ada
pragma Ada_2022;
|
|
|
|
package body Pandoc is
|
|
|
|
function Attr
|
|
(Key : League.Strings.Universal_String;
|
|
Value : League.Strings.Universal_String;
|
|
Id : League.Strings.Universal_String :=
|
|
League.Strings.Empty_Universal_String)
|
|
return League.JSON.Values.JSON_Value is
|
|
(Attr (Id, [Key], [Value]));
|
|
|
|
function Attr
|
|
(Id : League.Strings.Universal_String;
|
|
Key : String_Array;
|
|
Value : String_Array) return League.JSON.Values.JSON_Value
|
|
is
|
|
Outer : League.JSON.Arrays.JSON_Array;
|
|
Other : League.JSON.Arrays.JSON_Array;
|
|
Inner : League.JSON.Arrays.JSON_Array;
|
|
begin
|
|
Outer.Append (League.JSON.Values.To_JSON_Value (Id));
|
|
Outer.Append (Other.To_JSON_Value);
|
|
|
|
for K in Key'Range loop
|
|
declare
|
|
Pair : League.JSON.Arrays.JSON_Array;
|
|
begin
|
|
Pair.Append (League.JSON.Values.To_JSON_Value (Key (K)));
|
|
Pair.Append (League.JSON.Values.To_JSON_Value (Value (K)));
|
|
Inner.Append (Pair.To_JSON_Value);
|
|
end;
|
|
end loop;
|
|
|
|
Outer.Append (Inner.To_JSON_Value);
|
|
|
|
return Outer.To_JSON_Value;
|
|
end Attr;
|
|
|
|
function Div (
|
|
Attr : League.JSON.Values.JSON_Value;
|
|
Content : Content_Arr) return League.JSON.Values.JSON_Value
|
|
is
|
|
Block : League.JSON.Objects.JSON_Object;
|
|
Out_Content : League.JSON.Arrays.JSON_Array;
|
|
Content_Block : League.JSON.Arrays.JSON_Array;
|
|
begin
|
|
Block.Insert (
|
|
Type_String,
|
|
League.JSON.Values.To_JSON_Value (
|
|
Obj_String_Representation (Block_Div)
|
|
)
|
|
);
|
|
|
|
for C in Content'Range loop
|
|
Content_Block.Append (Content (C));
|
|
end loop;
|
|
|
|
Out_Content.Append (Attr);
|
|
Out_Content.Append (Content_Block.To_JSON_Value);
|
|
|
|
Block.Insert (
|
|
Content_String,
|
|
Out_Content.To_JSON_Value
|
|
);
|
|
|
|
return Block.To_JSON_Value;
|
|
end Div;
|
|
|
|
function Div
|
|
(Attr : League.JSON.Values.JSON_Value;
|
|
Content : League.JSON.Values.JSON_Value)
|
|
return League.JSON.Values.JSON_Value
|
|
is
|
|
Block : League.JSON.Objects.JSON_Object;
|
|
Out_Content : League.JSON.Arrays.JSON_Array;
|
|
begin
|
|
Block.Insert (
|
|
Type_String,
|
|
League.JSON.Values.To_JSON_Value (
|
|
Obj_String_Representation (Block_Div)
|
|
)
|
|
);
|
|
|
|
Out_Content.Append (Attr);
|
|
Out_Content.Append (Content);
|
|
|
|
Block.Insert (
|
|
Content_String,
|
|
Out_Content.To_JSON_Value
|
|
);
|
|
|
|
return Block.To_JSON_Value;
|
|
end Div;
|
|
|
|
function HTML_Block (Text : League.Strings.Universal_String) return
|
|
League.JSON.Values.JSON_Value
|
|
is
|
|
Output : League.JSON.Objects.JSON_Object;
|
|
Content_Arr : League.JSON.Arrays.JSON_Array;
|
|
begin
|
|
Output.Insert (
|
|
Type_String,
|
|
League.JSON.Values.To_JSON_Value (+"RawBlock"));
|
|
|
|
Content_Arr.Append (
|
|
League.JSON.Values.To_JSON_Value (+"html"));
|
|
|
|
Content_Arr.Append (
|
|
League.JSON.Values.To_JSON_Value (Text));
|
|
|
|
Output.Insert (
|
|
Content_String,
|
|
Content_Arr.To_JSON_Value);
|
|
|
|
return Output.To_JSON_Value;
|
|
end HTML_Block;
|
|
|
|
function Plain (Inlines : League.JSON.Values.JSON_Value) return
|
|
League.JSON.Values.JSON_Value
|
|
is
|
|
Output : League.JSON.Objects.JSON_Object;
|
|
begin
|
|
Output.Insert (
|
|
Type_String,
|
|
League.JSON.Values.To_JSON_Value (+"Plain"));
|
|
|
|
Output.Insert (
|
|
Content_String,
|
|
Inlines);
|
|
|
|
return Output.To_JSON_Value;
|
|
end Plain;
|
|
|
|
function Definition_List (B : League.JSON.Objects.JSON_Object) return
|
|
League.JSON.Arrays.JSON_Array
|
|
is
|
|
Output : League.JSON.Arrays.JSON_Array;
|
|
Content : constant League.JSON.Arrays.JSON_Array :=
|
|
B (Content_String).To_Array;
|
|
begin
|
|
Output.Append (HTML_Block (+"<dl>"));
|
|
|
|
for I in 1 .. Content.Length loop
|
|
declare
|
|
Def_Item : constant League.JSON.Arrays.JSON_Array :=
|
|
Content (I).To_Array;
|
|
Def_Header : constant League.JSON.Arrays.JSON_Array :=
|
|
Def_Item (1).To_Array;
|
|
Def_Content : constant League.JSON.Arrays.JSON_Array :=
|
|
Def_Item (2).To_Array;
|
|
begin
|
|
Output.Append (HTML_Block (+"<dt>"));
|
|
Output.Append (Plain (Def_Header.To_JSON_Value));
|
|
Output.Append (HTML_Block (+"</dt><dd>"));
|
|
|
|
for J in 1 .. Def_Content.Length loop
|
|
declare
|
|
Def_Sub_Content : constant League.JSON.Arrays.JSON_Array :=
|
|
Def_Content (J).To_Array;
|
|
begin
|
|
for K in 1 .. Def_Sub_Content.Length loop
|
|
Output.Append (Def_Sub_Content (K));
|
|
end loop;
|
|
end;
|
|
end loop;
|
|
|
|
Output.Append (HTML_Block (+"</dd>"));
|
|
end;
|
|
end loop;
|
|
|
|
Output.Append (HTML_Block (+"</dl>"));
|
|
|
|
return Output;
|
|
|
|
end Definition_List;
|
|
|
|
function Get_Type (B : League.JSON.Objects.JSON_Object)
|
|
return Object_Type is (Type_Mapping (B (Type_String).To_String));
|
|
|
|
begin
|
|
|
|
for Key in Object_Type loop
|
|
declare
|
|
Str_Rep : constant League.Strings.Universal_String :=
|
|
Obj_String_Representation (Key);
|
|
begin
|
|
Type_Mapping.Insert (Str_Rep, Key);
|
|
end;
|
|
end loop;
|
|
|
|
end Pandoc;
|