Compare commits

...

3 Commits

Author SHA1 Message Date
Folkert Kevelam
cbb9f100a3 Fix error due to constant map 2025-06-11 20:01:18 +02:00
Folkert Kevelam
6bfb264532 Refactor to use callbacks 2025-06-09 16:46:12 +02:00
Folkert Kevelam
384443692c Add an initial solution to the parsing of definition lists for MDX
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.
2025-06-07 19:41:37 +02:00
5 changed files with 220 additions and 128 deletions

View File

@ -188,6 +188,15 @@ procedure Aqs2mdx is
end if; end if;
when Inline_Link => when Inline_Link =>
List.Append (Traverse_Link (Block)); List.Append (Traverse_Link (Block));
when Block_DefinitionList =>
declare
Arr : League.JSON.Arrays.JSON_Array :=
Pandoc.Definition_List (Block);
begin
for I in 1 .. Arr.Length loop
List.Append (Arr(I));
end loop;
end;
when others => when others =>
if Block (Pandoc.Content_String).To_Array.Length > 0 then if Block (Pandoc.Content_String).To_Array.Length > 0 then
declare declare

59
source/pandoc-blocks.adb Normal file
View File

@ -0,0 +1,59 @@
package body Pandoc.Blocks is
function Create_Block
(T : Object_Type;
Content : League.JSON.Values.JSON_Value)
return League.JSON.Values.JSON_Value
is
begin
return Create_Block (T, Empty_Attribute, Content);
end Create_Block;
function Create_Block
(T : Object_Type;
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;
New_Content : League.JSON.Arrays.JSON_Array;
begin
New_Content.Append (Attr);
New_Content.Append (Content);
Block.Insert
(Type_String, League.JSON.Values.To_JSON_Value( Type_To_String (T)));
Block.Insert (Content_String, New_Content);
return Block.To_JSON_Value;
end Create_Block;
function Raw_Block
(T : League.Strings.Universal_String;
Content : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value
is
begin
return Raw_Block (Empty_Attribute, T, Content);
end Raw_Block;
function Raw_Block
(Attr : League.JSON.Values.JSON_Value;
T : League.Strings.Universal_String;
Content : League.Strings.Universal_String
return League.JSON.Values.JSON_Value
is
Formatted_Content : League.JSON.Arrays.JSON_Array;
begin
Formatted_Content.Append (
League.JSON.Values.To_JSON_Value (T));
Formatted_Content.Append (
League.JSON.Values.To_JSON_Value (Content));
return Create_Block (Block_RawBlock, Attr, Formatted_Content);
end Raw_Block;
end Pandoc.Blocks;

28
source/pandoc-blocks.ads Normal file
View File

@ -0,0 +1,28 @@
with League.JSON.Values;
with League.JSON.Arrays.JSON_Array;
package Pandoc.Blocks is
function Create_Block
(T : Object_Type;
Content : League.JSON.Values.JSON_Value)
return League.JSON.Values.JSON_Value;
function Create_Block
(T : Object_Type;
Attr : League.JSON.Values.JSON_Value;
Content : League.JSON.Values.JSON_Value)
return League.JSON.Values.JSON_Value;
function Raw_Block
(T : League.Strings.Universal_String;
Content : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value;
function Raw_Block
(Attr : League.JSON.Values.JSON_Value;
T : League.Strings.Universal_String;
Content : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value;
end Pandoc.Blocks;

View File

@ -1,103 +1,86 @@
pragma Ada_2022;
with League.JSON.Arrays;
package body Pandoc is 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 Get_Type (B : League.JSON.Objects.JSON_Object) function Get_Type (B : League.JSON.Objects.JSON_Object)
return Object_Type is (Type_Mapping (B (Type_String).To_String)); return Object_Type is (Type_Mapping (B (Type_String).To_String));
function Type_To_String (T : Object_Type)
return League.Strings.Universal_String
is
begin
return Obj_String_Representation (T);
end Type_To_String;
function Attr
(Id : League.Strings.Universal_String;
Key : League.Strings.Universal_String;
Value : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value
is
Key_Value_Pair : League.JSON.Arrays.JSON_Array;
Attr_Map : League.JSON.Arrays.JSON_Array;
Attr : League.JSON.Arrays.JSON_Array;
begin
Key_Value_Pair.Append (
League.JSON.Values.To_JSON_Value (Key));
Key_Value_Pair.Append (
League.JSON.Values.To_JSON_Value (Value));
Attr_Map.Append (Key_Value_Pair.To_JSON_Value);
Attr.Append (
League.JSON.Values.To_JSON_Value (Id));
Attr.Append (Attr_Map.To_JSON_Value);
return Attr.To_JSON_Value;
end Attr;
function Attr
(Id : League.Strings.Universal_String;
Key_Value : Key_Value_Pairs)
return League.JSON.Values.JSON_Value
is
Attr_Map : League.JSON.Arrays.JSON_Array;
Attr : League.JSON.Arrays.JSON_Array;
begin
for J in Key_Value'Range loop
declare
Pair : League.JSON.Arrays.JSON_Array;
begin
Pair.Append (
League.JSON.Values.To_JSON_Value (Key_Value (J).Key));
Pair.Append (
League.JSON.Values.To_JSON_Value (Key_Value (J).Value));
Attr_Map.Append (Pair.To_JSON_Value);
end;
end loop;
Attr.Append (
League.JSON.Values.To_JSON_Value (Id));
Attr.Append (Attr_Map.To_JSON_Value);
return Attr.To_JSON_Value;
end Attr;
function Attr
(Key : League.Strings.Universal_String;
Value : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value
is
begin
return Attr (+"", Key, Value);
end Attr;
function Attr (Key_Value : Key_Value_Pairs)
return League.JSON.Values.JSON_Value
is
begin
return Attr (+"", Key_Value);
end Attr;
begin begin
for Key in Object_Type loop for Key in Object_Type loop

View File

@ -1,15 +1,15 @@
pragma Ada_2022;
with Ada.Containers; with Ada.Containers;
with Ada.Containers.Hashed_Maps; with Ada.Containers.Hashed_Maps;
with League.JSON.Objects; with League.JSON.Objects;
with League.Strings.Hash; with League.Strings.Hash;
with League.Strings; with League.Strings;
with League.JSON.Values; with League.JSON.Values;
with League.JSON.Arrays;
package Pandoc is package Pandoc is
type String_Array is array (Natural range <>) of
League.Strings.Universal_String;
type Object_Type is type Object_Type is
(Block_Plain, (Block_Plain,
Block_Para, Block_Para,
@ -46,42 +46,55 @@ package Pandoc is
Inline_Note, Inline_Note,
Inline_Span); Inline_Span);
type Content_Arr is array (Natural range <>) type Key_Value_Pair is
of League.JSON.Values.JSON_Value; record
Key : League.Strings.Universal_String;
Value : League.Strings.Universal_String;
end record;
type Key_Value_Pairs is array (Natural range <>) of Key_Value_Pair;
function Get_Type (B : League.JSON.Objects.JSON_Object) return Object_Type; function Get_Type (B : League.JSON.Objects.JSON_Object) return Object_Type;
function Type_To_String (T : Object_Type)
return League.Strings.Universal_String;
Type_String : constant League.Strings.Universal_String :=
League.Strings.To_Universal_String ("t");
Content_String : constant League.Strings.Universal_String :=
League.Strings.To_Universal_String ("c");
function Attr
(Id : League.Strings.Universal_String;
Key : League.Strings.Universal_String;
Value : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value;
function Attr
(Id : League.Strings.Universal_String;
Key_Value : Key_Value_Pairs)
return League.JSON.Values.JSON_Value;
function Attr
(Key : League.Strings.Universal_String;
Value : League.Strings.Universal_String)
return League.JSON.Values.JSON_Value;
function Attr (Key_Value : Key_Value_Pairs)
return League.JSON.Values.JSON_Value;
Empty_Attribute : constant League.JSON.Values.JSON_Value := Attr([]);
private
type String_Array is array (Natural range <>) of
League.Strings.Universal_String;
function "+" (T : Wide_Wide_String) return League.Strings.Universal_String function "+" (T : Wide_Wide_String) return League.Strings.Universal_String
renames League.Strings.To_Universal_String; renames League.Strings.To_Universal_String;
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;
function Attr
(Id : League.Strings.Universal_String;
Key : String_Array;
Value : String_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 League.Strings.Universal_String := +"t";
Content_String : constant League.Strings.Universal_String := +"c";
private
Obj_String_Representation : Obj_String_Representation :
constant array (Object_Type) of League.Strings.Universal_String := ( constant array (Object_Type) of League.Strings.Universal_String := [
+"Plain", +"Plain",
+"Para", +"Para",
+"LineBlock", +"LineBlock",
@ -116,7 +129,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 => League.Strings.Universal_String, Key_Type => League.Strings.Universal_String,