import-style-guide/source/pandoc.ads
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

109 lines
2.2 KiB
Ada

with Ada.Containers;
with Ada.Containers.Hashed_Maps;
with League.Strings;
with League.JSON;
with League.JSON.Objects;
package Pandoc is
package Ustr renames League.Strings;
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
);
function Get_Type (
B : League.JSON.Objects.JSON_Object) return Object_Type;
function "+" (T : Wide_Wide_String) return Ustr.Universal_String
renames Ustr.To_Universal_String;
Type_String : constant Ustr.Universal_String := +"t";
Content_String : constant Ustr.Universal_String := +"c";
private
Obj_String_Representation :
constant array (Object_Type) of Ustr.Universal_String := (
+"Plain",
+"Para",
+"LineBlock",
+"CodeBlock",
+"RawBlock",
+"BlockQuote",
+"OrderedList",
+"BulletList",
+"DefinitionList",
+"Header",
+"HorizontalRule",
+"Table",
+"Figure",
+"Div",
+"Str",
+"Emph",
+"Underline",
+"Strong",
+"Strikeout",
+"Superscript",
+"Subscript",
+"SmallCaps",
+"Quoted",
+"Cite",
+"Code",
+"Space",
+"SoftBreak",
+"LineBreak",
+"Math",
+"RawInline",
+"Link",
+"Image",
+"Note",
+"Span"
);
function Hash (Item : Ustr.Universal_String)
return Ada.Containers.Hash_Type;
package Type_Map is new Ada.Containers.Hashed_Maps (
Key_Type => Ustr.Universal_String,
Element_Type => Object_Type,
Hash => Hash,
Equivalent_Keys => Ustr."=");
Type_Mapping : Type_Map.Map := Type_Map.Empty;
end Pandoc;