Add functions for creating Div's and Attributes

This commit is contained in:
Folkert Kevelam 2025-05-25 20:14:56 +02:00
parent b00feb3652
commit 6cb6e6bb38
2 changed files with 104 additions and 3 deletions

View File

@ -1,7 +1,90 @@
with League.JSON.Values; with League.JSON.Arrays;
package body Pandoc is package body Pandoc is
function Attr (
Id : Ustr.Universal_String;
Key : Ustr_Array;
Value : Ustr_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 Get_Type (B : League.JSON.Objects.JSON_Object) function Get_Type (B : League.JSON.Objects.JSON_Object)
return Object_Type is return Object_Type is
begin begin

View File

@ -2,6 +2,7 @@ with Ada.Containers;
with Ada.Containers.Hashed_Maps; with Ada.Containers.Hashed_Maps;
with League.JSON.Objects; with League.JSON.Objects;
with League.Strings; with League.Strings;
with League.JSON.Values;
package Pandoc is package Pandoc is
@ -48,12 +49,29 @@ package Pandoc is
Inline_Span Inline_Span
); );
type Content_Arr is array (Natural range <>)
of League.JSON.Values.JSON_Value;
function Get_Type ( function Get_Type (
B : League.JSON.Objects.JSON_Object) return Object_Type; B : League.JSON.Objects.JSON_Object) return Object_Type;
function "+" (T : Wide_Wide_String) return Ustr.Universal_String function "+" (T : Wide_Wide_String) return Ustr.Universal_String
renames Ustr.To_Universal_String; renames Ustr.To_Universal_String;
function Attr (
Id : Ustr.Universal_String;
Key : Ustr_Array;
Value : Ustr_Array) return League.JSON.Values.JSON_Value;
function Div (
Attr : League.JSON.Values.JSON_Value;
Content : Content_Arr) return League.JSON.Values.JSON_Value;
function Div (
Attr : League.JSON.Values.JSON_Value;
Content : League.JSON.Values.JSON_Value)
return League.JSON.Values.JSON_Value;
Type_String : constant Ustr.Universal_String := +"t"; Type_String : constant Ustr.Universal_String := +"t";
Content_String : constant Ustr.Universal_String := +"c"; Content_String : constant Ustr.Universal_String := +"c";
@ -63,7 +81,7 @@ private
return Ada.Containers.Hash_Type; return Ada.Containers.Hash_Type;
Obj_String_Representation : Obj_String_Representation :
constant array (Object_Type) of Ustr.Universal_String := ( constant array (Object_Type) of Ustr.Universal_String := [
+"Plain", +"Plain",
+"Para", +"Para",
+"LineBlock", +"LineBlock",
@ -98,7 +116,7 @@ private
+"Image", +"Image",
+"Note", +"Note",
+"Span" +"Span"
); ];
package Type_Map is new Ada.Containers.Hashed_Maps ( package Type_Map is new Ada.Containers.Hashed_Maps (
Key_Type => Ustr.Universal_String, Key_Type => Ustr.Universal_String,