Compare commits

..

2 Commits

Author SHA1 Message Date
Maxim Reznik
1a75f9620f Avoid abbreviations 2025-05-31 14:20:27 +03:00
Folkert Kevelam
1eb07a262c
Add options for multi column code examples (#8)
* 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.

* Rename Package to reduce text

* Correct indent

* Add functions for creating Div's and Attributes

* Change table with codeblocks to nested div's

* Add sidebar_position for Ada_Style_Guide.mdx
2025-05-31 13:59:57 +03:00
3 changed files with 83 additions and 88 deletions

View File

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

View File

@ -1,11 +1,21 @@
pragma Ada_2022;
with League.JSON.Arrays; with League.JSON.Arrays;
package body Pandoc is package body Pandoc is
function Attr ( function Attr
Id : Ustr.Universal_String; (Key : League.Strings.Universal_String;
Key : Ustr_Array; Value : League.Strings.Universal_String;
Value : Ustr_Array) return League.JSON.Values.JSON_Value 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 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;
@ -59,8 +69,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
@ -86,26 +96,13 @@ 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 return Object_Type is (Type_Mapping (B (Type_String).To_String));
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 Ustr.Universal_String := Str_Rep : constant League.Strings.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,19 +1,17 @@
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
Pandoc_Type_Error : exception; type String_Array is array (Natural range <>) of
League.Strings.Universal_String;
package Ustr renames League.Strings; type Object_Type is
(Block_Plain,
type Ustr_Array is array (Natural range <>) of Ustr.Universal_String;
type Object_Type is (
Block_Plain,
Block_Para, Block_Para,
Block_LineBlock, Block_LineBlock,
Block_CodeBlock, Block_CodeBlock,
@ -46,42 +44,44 @@ package Pandoc is
Inline_Link, Inline_Link,
Inline_Image, Inline_Image,
Inline_Note, Inline_Note,
Inline_Span 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 ( 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 League.Strings.Universal_String
renames Ustr.To_Universal_String; renames League.Strings.To_Universal_String;
function Attr ( function Attr
Id : Ustr.Universal_String; (Key : League.Strings.Universal_String;
Key : Ustr_Array; Value : League.Strings.Universal_String;
Value : Ustr_Array) return League.JSON.Values.JSON_Value; Id : League.Strings.Universal_String :=
League.Strings.Empty_Universal_String)
return League.JSON.Values.JSON_Value;
function Div ( function Attr
Attr : League.JSON.Values.JSON_Value; (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; 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 Ustr.Universal_String := +"t"; Type_String : constant League.Strings.Universal_String := +"t";
Content_String : constant Ustr.Universal_String := +"c"; Content_String : constant League.Strings.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 Ustr.Universal_String := ( constant array (Object_Type) of League.Strings.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 => Ustr.Universal_String, Key_Type => League.Strings.Universal_String,
Element_Type => Object_Type, Element_Type => Object_Type,
Hash => Hash, Hash => League.Strings.Hash,
Equivalent_Keys => Ustr."="); Equivalent_Keys => League.Strings."=");
Type_Mapping : Type_Map.Map := Type_Map.Empty; Type_Mapping : Type_Map.Map := Type_Map.Empty;