Compare commits

..

6 Commits

Author SHA1 Message Date
Folkert Kevelam
1fad5c1683 Add sidebar_position for Ada_Style_Guide.mdx 2025-05-25 20:34:17 +02:00
Folkert Kevelam
8d33bcc1c1 Change table with codeblocks to nested div's 2025-05-25 20:19:11 +02:00
Folkert Kevelam
6cb6e6bb38 Add functions for creating Div's and Attributes 2025-05-25 20:14:56 +02:00
Folkert Kevelam
b00feb3652 Correct indent 2025-05-23 18:17:59 +02:00
Folkert Kevelam
6b1d8a59f0 Rename Package to reduce text 2025-05-23 18:15:01 +02:00
Folkert Kevelam
fee47e4039 Reformat Blocks with a hashed_map
In the package Pandoc a function called `Get_Type()` is defined,
which takes a JSON block and returns the pandoc assigned type.

The main code of the `Traverse_Block` function is changed to
use an enumeration of Pandoc types instead of comparing string.
2025-05-17 21:27:23 +02:00
3 changed files with 88 additions and 83 deletions

View File

@ -142,10 +142,12 @@ procedure Aqs2mdx is
Columns_Div : Pandoc.Content_Arr (1 .. Cell_List.Length);
Outer_Attr : constant League.JSON.Values.JSON_Value :=
Pandoc.Attr (+"className", +"multi-column");
Pandoc.Attr (
+"", ( 1 => +"className"), ( 1 => +"multi-column"));
Inner_Attr : constant League.JSON.Values.JSON_Value :=
Pandoc.Attr (+"className", +"multi-column-child");
Pandoc.Attr (
+"", ( 1 => +"className"), ( 1 => +"multi-column-child"));
begin
pragma Assert (Content.Length = 6);

View File

@ -1,21 +1,11 @@
pragma Ada_2022;
with League.JSON.Arrays;
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
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;
@ -69,8 +59,8 @@ package body Pandoc is
return Block.To_JSON_Value;
end Div;
function Div
(Attr : 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
is
@ -96,13 +86,26 @@ package body Pandoc is
end Div;
function Get_Type (B : League.JSON.Objects.JSON_Object)
return Object_Type is (Type_Mapping (B (Type_String).To_String));
return Object_Type is
begin
return Type_Map.Element (
Type_Mapping.Find (
B (Type_String).To_String
)
);
end Get_Type;
function Hash (Item : Ustr.Universal_String)
return Ada.Containers.Hash_Type is
begin
return Ada.Containers.Hash_Type (League.Hash_Type'(Item.Hash));
end Hash;
begin
for Key in Object_Type loop
declare
Str_Rep : constant League.Strings.Universal_String :=
Str_Rep : constant Ustr.Universal_String :=
Obj_String_Representation (Key);
begin
Type_Mapping.Insert (Str_Rep, Key);

View File

@ -1,87 +1,87 @@
with Ada.Containers;
with Ada.Containers.Hashed_Maps;
with League.JSON.Objects;
with League.Strings.Hash;
with League.Strings;
with League.JSON.Values;
package Pandoc is
type String_Array is array (Natural range <>) of
League.Strings.Universal_String;
Pandoc_Type_Error : exception;
type Object_Type is
(Block_Plain,
Block_Para,
Block_LineBlock,
Block_CodeBlock,
Block_RawBlock,
Block_BlockQuote,
Block_OrderedList,
Block_BulletList,
Block_DefinitionList,
Block_Header,
Block_HorizontalRule,
Block_Table,
Block_Figure,
Block_Div,
Inline_String,
Inline_Emph,
Inline_Underline,
Inline_Strong,
Inline_Strikeout,
Inline_Superscript,
Inline_Subscript,
Inline_SmallCaps,
Inline_Quoted,
Inline_Cite,
Inline_Code,
Inline_Space,
Inline_SoftBreak,
Inline_LineBreak,
Inline_Math,
Inline_RawInline,
Inline_Link,
Inline_Image,
Inline_Note,
Inline_Span);
package Ustr renames League.Strings;
type Ustr_Array is array (Natural range <>) of Ustr.Universal_String;
type Object_Type is (
Block_Plain,
Block_Para,
Block_LineBlock,
Block_CodeBlock,
Block_RawBlock,
Block_BlockQuote,
Block_OrderedList,
Block_BulletList,
Block_DefinitionList,
Block_Header,
Block_HorizontalRule,
Block_Table,
Block_Figure,
Block_Div,
Inline_String,
Inline_Emph,
Inline_Underline,
Inline_Strong,
Inline_Strikeout,
Inline_Superscript,
Inline_Subscript,
Inline_SmallCaps,
Inline_Quoted,
Inline_Cite,
Inline_Code,
Inline_Space,
Inline_SoftBreak,
Inline_LineBreak,
Inline_Math,
Inline_RawInline,
Inline_Link,
Inline_Image,
Inline_Note,
Inline_Span
);
type Content_Arr is array (Natural range <>)
of League.JSON.Values.JSON_Value;
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 "+" (T : Wide_Wide_String) return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
function "+" (T : Wide_Wide_String) return Ustr.Universal_String
renames Ustr.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 : Ustr.Universal_String;
Key : Ustr_Array;
Value : Ustr_Array) 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;
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;
function Div (
Attr : League.JSON.Values.JSON_Value;
Content : League.JSON.Values.JSON_Value)
return 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";
Type_String : constant Ustr.Universal_String := +"t";
Content_String : constant Ustr.Universal_String := +"c";
private
function Hash (Item : Ustr.Universal_String)
return Ada.Containers.Hash_Type;
Obj_String_Representation :
constant array (Object_Type) of League.Strings.Universal_String := (
constant array (Object_Type) of Ustr.Universal_String := (
+"Plain",
+"Para",
+"LineBlock",
@ -119,10 +119,10 @@ private
);
package Type_Map is new Ada.Containers.Hashed_Maps (
Key_Type => League.Strings.Universal_String,
Key_Type => Ustr.Universal_String,
Element_Type => Object_Type,
Hash => League.Strings.Hash,
Equivalent_Keys => League.Strings."=");
Hash => Hash,
Equivalent_Keys => Ustr."=");
Type_Mapping : Type_Map.Map := Type_Map.Empty;