Compare commits
2 Commits
72c71e2a70
...
1a75f9620f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a75f9620f | ||
|
|
1eb07a262c |
1
fetch.sh
1
fetch.sh
|
|
@ -58,6 +58,7 @@ cat > /tmp/front_matter <<-EOF
|
|||
---
|
||||
title: Ada Quality and Style Guide
|
||||
description: Guidelines for Professional Programmers
|
||||
sidebar_position: 0
|
||||
---
|
||||
|
||||
> **_Guidelines for Professional Programmers_**
|
||||
|
|
|
|||
|
|
@ -7,9 +7,12 @@ with League.JSON.Objects;
|
|||
with League.JSON.Values;
|
||||
with League.Strings;
|
||||
|
||||
with Pandoc;
|
||||
|
||||
procedure Aqs2mdx is
|
||||
use type League.Strings.Universal_String;
|
||||
use type League.Holders.Universal_Integer;
|
||||
use all type Pandoc.Object_Type;
|
||||
|
||||
function "+" (T : Wide_Wide_String) return League.Strings.Universal_String
|
||||
renames League.Strings.To_Universal_String;
|
||||
|
|
@ -93,13 +96,16 @@ procedure Aqs2mdx is
|
|||
return League.JSON.Arrays.JSON_Array
|
||||
is
|
||||
List : League.JSON.Arrays.JSON_Array;
|
||||
Pandoc_Type : constant Pandoc.Object_Type := Pandoc.Get_Type (Block);
|
||||
begin
|
||||
if Block (+"t").To_String.To_Wide_Wide_String = "Table" then
|
||||
-- Flatting tables because no multiline tables in .md
|
||||
|
||||
case Pandoc_Type is
|
||||
when Block_Table =>
|
||||
-- Flatten tables since there are no native multiline tables
|
||||
-- in .md
|
||||
declare
|
||||
-- Table structure in pandoc-types-1.23.1. See
|
||||
-- https://hackage.haskell.org/package/pandoc-types-1.23.1/docs/
|
||||
-- https://hackage.haskell.org/package/pandoc-types-1.23.1/
|
||||
-- docs/
|
||||
-- Text-Pandoc-Definition.html
|
||||
--
|
||||
-- Table:
|
||||
|
|
@ -107,32 +113,40 @@ procedure Aqs2mdx is
|
|||
-- 1 2 3 4 5 6
|
||||
|
||||
Content : constant League.JSON.Arrays.JSON_Array :=
|
||||
Block (+"c").To_Array;
|
||||
Block (Pandoc.Content_String).To_Array;
|
||||
|
||||
Table_Body_List : constant League.JSON.Arrays.JSON_Array :=
|
||||
Content (5).To_Array;
|
||||
|
||||
-- A body of a table, with an intermediate head, intermediate
|
||||
-- body, and the specified number of row header columns in the
|
||||
-- intermediate body.
|
||||
--
|
||||
-- TableBody Attr RowHeadColumns [Row] [Row]
|
||||
-- 1 2 3 4
|
||||
|
||||
Table_Body : constant League.JSON.Arrays.JSON_Array :=
|
||||
Table_Body_List (1).To_Array;
|
||||
|
||||
Row_List : constant League.JSON.Arrays.JSON_Array :=
|
||||
Table_Body (4).To_Array;
|
||||
|
||||
Row : constant League.JSON.Arrays.JSON_Array :=
|
||||
Row_List (1).To_Array;
|
||||
-- A table row.
|
||||
-- Row Attr [Cell]
|
||||
-- 1 2
|
||||
Row : constant League.JSON.Arrays.JSON_Array :=
|
||||
Row_List (1).To_Array;
|
||||
|
||||
Cell_List : constant League.JSON.Arrays.JSON_Array :=
|
||||
Row (2).To_Array;
|
||||
|
||||
Columns_Div : Pandoc.Content_Arr (1 .. Cell_List.Length);
|
||||
|
||||
Outer_Attr : constant League.JSON.Values.JSON_Value :=
|
||||
Pandoc.Attr (+"className", +"multi-column");
|
||||
|
||||
Inner_Attr : constant League.JSON.Values.JSON_Value :=
|
||||
Pandoc.Attr (+"className", +"multi-column-child");
|
||||
|
||||
begin
|
||||
pragma Assert (Content.Length = 6);
|
||||
pragma Assert (Table_Body_List.Length = 1);
|
||||
|
|
@ -141,49 +155,56 @@ procedure Aqs2mdx is
|
|||
|
||||
for J in 1 .. Cell_List.Length loop
|
||||
declare
|
||||
Cell : constant League.JSON.Arrays.JSON_Array :=
|
||||
Cell_List (J).To_Array;
|
||||
-- A table cell.
|
||||
-- Cell Attr Alignment RowSpan ColSpan [Block]
|
||||
-- 1 2 3 4 5
|
||||
Cell : constant League.JSON.Arrays.JSON_Array :=
|
||||
Cell_List (J).To_Array;
|
||||
|
||||
Block_List : constant League.JSON.Values.JSON_Value :=
|
||||
Cell (5);
|
||||
|
||||
Block_List : constant League.JSON.Arrays.JSON_Array :=
|
||||
Cell (5).To_Array;
|
||||
begin
|
||||
pragma Assert (Cell.Length = 5);
|
||||
|
||||
for K in 1 .. Block_List.Length loop
|
||||
List.Append (Block_List (K));
|
||||
end loop;
|
||||
Columns_Div (J) := Pandoc.Div (Inner_Attr, Block_List);
|
||||
end;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
elsif Block (+"t").To_String.To_Wide_Wide_String = "Header"
|
||||
and then Block (+"c").To_Array.Element (1).To_Integer = 2
|
||||
and then Block (+"c").To_Array.Element (2)
|
||||
List.Append (Pandoc.Div (Outer_Attr, Columns_Div));
|
||||
end;
|
||||
when Block_Header =>
|
||||
if Block (Pandoc.Content_String).To_Array.Element (1)
|
||||
.To_Integer = 2
|
||||
and then Block (Pandoc.Content_String).To_Array.Element (2)
|
||||
.To_Array.Element (1).To_String = +"introduction"
|
||||
-- This relies on the fact that Pandoc converts a title
|
||||
-- From mediawiki and adds a lower-case id to the header
|
||||
then
|
||||
-- Drop toppest 'Introduction' section header
|
||||
-- Drop toplevel 'Introduction' section header
|
||||
null;
|
||||
|
||||
elsif Block (+"t").To_String.To_Wide_Wide_String = "Link" then
|
||||
else
|
||||
List.Append (Block.To_JSON_Value);
|
||||
end if;
|
||||
when Inline_Link =>
|
||||
List.Append (Traverse_Link (Block));
|
||||
|
||||
elsif Block (+"c").To_Array.Length > 0 then
|
||||
when others =>
|
||||
if Block (Pandoc.Content_String).To_Array.Length > 0 then
|
||||
declare
|
||||
-- Traverse nested blocks
|
||||
Copy : League.JSON.Objects.JSON_Object := Block;
|
||||
Arr : constant League.JSON.Arrays.JSON_Array :=
|
||||
Block (Pandoc.Content_String).To_Array;
|
||||
begin
|
||||
Copy.Insert
|
||||
(+"c", Traverse_List (Block (+"c").To_Array).To_JSON_Value);
|
||||
|
||||
Copy.Insert (
|
||||
Pandoc.Content_String,
|
||||
Traverse_List (Arr).To_JSON_Value);
|
||||
List.Append (Copy.To_JSON_Value);
|
||||
end;
|
||||
|
||||
else -- Something else (if any?)
|
||||
else
|
||||
List.Append (Block.To_JSON_Value);
|
||||
end if;
|
||||
end case;
|
||||
|
||||
return List;
|
||||
end Traverse_Block;
|
||||
|
|
|
|||
112
source/pandoc.adb
Normal file
112
source/pandoc.adb
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
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
|
||||
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)
|
||||
return Object_Type is (Type_Mapping (B (Type_String).To_String));
|
||||
|
||||
begin
|
||||
|
||||
for Key in Object_Type loop
|
||||
declare
|
||||
Str_Rep : constant League.Strings.Universal_String :=
|
||||
Obj_String_Representation (Key);
|
||||
begin
|
||||
Type_Mapping.Insert (Str_Rep, Key);
|
||||
end;
|
||||
end loop;
|
||||
|
||||
end Pandoc;
|
||||
129
source/pandoc.ads
Normal file
129
source/pandoc.ads
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
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;
|
||||
|
||||
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 "+" (T : Wide_Wide_String) return League.Strings.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 :
|
||||
constant array (Object_Type) of League.Strings.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"
|
||||
);
|
||||
|
||||
package Type_Map is new Ada.Containers.Hashed_Maps (
|
||||
Key_Type => League.Strings.Universal_String,
|
||||
Element_Type => Object_Type,
|
||||
Hash => League.Strings.Hash,
|
||||
Equivalent_Keys => League.Strings."=");
|
||||
|
||||
Type_Mapping : Type_Map.Map := Type_Map.Empty;
|
||||
|
||||
end Pandoc;
|
||||
Loading…
Reference in New Issue
Block a user