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); Columns_Div : Pandoc.Content_Arr (1 .. Cell_List.Length);
Outer_Attr : constant League.JSON.Values.JSON_Value := 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 := Inner_Attr : constant League.JSON.Values.JSON_Value :=
Pandoc.Attr (+"className", +"multi-column-child"); Pandoc.Attr (
+"", ( 1 => +"className"), ( 1 => +"multi-column-child"));
begin begin
pragma Assert (Content.Length = 6); pragma Assert (Content.Length = 6);

View File

@ -1,21 +1,11 @@
pragma Ada_2022;
with League.JSON.Arrays; with League.JSON.Arrays;
package body Pandoc is package body Pandoc is
function Attr function Attr (
(Key : League.Strings.Universal_String; Id : Ustr.Universal_String;
Value : League.Strings.Universal_String; Key : Ustr_Array;
Id : League.Strings.Universal_String := Value : Ustr_Array) return League.JSON.Values.JSON_Value
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 is
Outer : League.JSON.Arrays.JSON_Array; Outer : League.JSON.Arrays.JSON_Array;
Other : League.JSON.Arrays.JSON_Array; Other : League.JSON.Arrays.JSON_Array;
@ -69,8 +59,8 @@ package body Pandoc is
return Block.To_JSON_Value; return Block.To_JSON_Value;
end Div; end Div;
function Div function Div (
(Attr : League.JSON.Values.JSON_Value; Attr : League.JSON.Values.JSON_Value;
Content : League.JSON.Values.JSON_Value) Content : League.JSON.Values.JSON_Value)
return League.JSON.Values.JSON_Value return League.JSON.Values.JSON_Value
is is
@ -96,13 +86,26 @@ package body Pandoc is
end Div; 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
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 begin
for Key in Object_Type loop for Key in Object_Type loop
declare declare
Str_Rep : constant League.Strings.Universal_String := Str_Rep : constant Ustr.Universal_String :=
Obj_String_Representation (Key); Obj_String_Representation (Key);
begin begin
Type_Mapping.Insert (Str_Rep, Key); Type_Mapping.Insert (Str_Rep, Key);

View File

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