Compare commits

...

10 Commits

Author SHA1 Message Date
Maxim Reznik
72c71e2a70 Rewrite to work with pandoc-3.1.3
Refs #7
2025-05-12 23:24:18 +03:00
Maxim Reznik
1c3d56ed30 Add required pandoc version and a structure comment. 2025-05-12 22:40:35 +03:00
Maxim Reznik
ef2f6df2b0 Split long sections into subdirectories.
I've found, that wikibook has just part of Section 5, so I converted
missing text from html and put it on the wikibook. I put here the
conversion script just in case. Probably we can reuse it if we
will work on restoring links present in HTML, but lost on wikibook.
2023-04-21 14:19:07 +03:00
Maxim Reznik
b1eb1a2eb2 Fix markdown to match one expected by yarn format. 2022-09-26 13:51:50 +03:00
Paul Jarrett
453daed416 Remove draft status of style guide
Draft prevents the guide from showing up when built.
2022-09-26 13:50:17 +03:00
Maxim Reznik
0c45391362 Replace "wikilinks" links
with absolute links to wikipedia and wikibooks.
Fix #2
2022-09-26 13:49:50 +03:00
Maxim Reznik
181c366690 Add an empty line before :::note admonitions
to avoid broken notes after applying `yarn format`.
2022-09-26 13:49:31 +03:00
Maxim Reznik
c34b061dff Move CC SA license note at the end of each page. 2022-09-12 15:01:24 +03:00
Maxim Reznik
a262903d0a Add license note to each page. 2022-09-11 18:19:29 +03:00
Maxim Reznik
e7096e302e Drop slug from the index page. 2022-09-10 11:30:51 +03:00
5 changed files with 221 additions and 24 deletions

24
2wiki.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# I used this script to convert a lost part of section 5 to MediaWiki
for X in `seq 564 569;echo 5610 57;seq 571 575;echo 58;seq 581 584;echo 59; seq 591 599;echo 5910 510`; do curl -O http://archive.adaic.com/ase/ase02_01/bookcase/ada_sh/style95/sec_5/$X.htm ;done
for X in *.htm; do pandoc -f html -t mediawiki $X -o `basename $X .htm`.wiki; done
sed -i -e '1,/^-----$/d' *.wiki
sed -i -e '/^-----$/,$d' *.wiki
sed -i -e 's#</blockquote>##' -e 's#<blockquote>##' *.wiki
sed -i -e 's#<span[^>]*>##' -e 's#</span>##' *.wiki
sed -i -e 's/code>/TT>/g' *.wiki
sed -i -e "s/'''\([a-z ]*\)'''/==== \1 ====/" *.wiki
sed -i -e 's/&gt;/>/g' -e 's/&lt;/</g' -e 's/&quot;/"/g' *.wiki
sed -i -e 's#<pre>#<syntaxhighlight lang=ada>\n#' -e 's#</pre>#\n</syntaxhighlight>#' *.wiki
sed -i -e "s/'''[0-9.]* \([A-Za-z ]*\)'''/=== \1 ===/" *.wiki
sed -i -e "s/=== [0-9.]* \([A-Za-z ]*\) ===/== \1 ==/" ??.wiki
sed -i -e '/toc.htm/,/^$/d' *.wiki
sed -i -e 's/\[\[[^|]*|\([^]]*\)\]\]/\1/g' *.wiki
sed -i -e '/<br \/>/{N;s/^/* /;s/^\* -/**/;s#<br />\n##}' *.wiki
sed -i -e '/^\*/{N;s/\n$//}' *.wiki
for X in `seq 564 569;echo 5610 57;seq 571 575;echo 58;seq 581 584;echo 59; seq 591 599;echo 5910 510`;do cat $X.wiki; done > /tmp/result.wiki
# fix '=== erroneous ===', upper cases headers ??.wiki, missing list item markers,

View File

@ -2,9 +2,13 @@
These scripts convert the WiKi book to ada-lang.io markdown. These scripts convert the WiKi book to ada-lang.io markdown.
## Requirements
You need `pandoc-3.1.3`, `curl`, `sed` installed.
## Build and run ## Build and run
You need `pandoc`, `curl`, `sed` installed. Build a pandoc filter with Alire: Build a pandoc filter with Alire:
alr build alr build
@ -12,6 +16,9 @@ Then run:
./fetch.sh <OUTPUT_DIR> ./fetch.sh <OUTPUT_DIR>
Then run `yarn format` in ada-lang.io repository to reformat output according
to Docusaurus style.
## To be fixed ## To be fixed
* Arrange code blocks in Source Code Presentation in two columns * Arrange code blocks in Source Code Presentation in two columns

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
set -e set -e
ulimit -s unlimited # To fix stack overflow on a large JSON input
OUTPUT=${1:-/tmp/src/ada-lang-io/docs/style-guide} OUTPUT=${1:-/tmp/src/ada-lang-io/docs/style-guide}
AQS2MDX=./bin/aqs2mdx AQS2MDX=./bin/aqs2mdx
@ -9,7 +11,7 @@ mkdir -p $OUTPUT
curl -o data/Ada_Style_Guide.wiki "https://en.wikibooks.org/w/index.php?title=Ada_Style_Guide&action=raw" curl -o data/Ada_Style_Guide.wiki "https://en.wikibooks.org/w/index.php?title=Ada_Style_Guide&action=raw"
CHAPTERS=`grep -F '* [[' data/Ada_Style_Guide.wiki | sed -e 's#.*/\([^|]*\)|.*#\1#' -e 's/ /_/g'` CHAPTERS=`grep -F '* [[' data/Ada_Style_Guide.wiki | sed -e 's#.*/\([^|]*\)|.*#\1#' -e 's/ /_/g'`
INDEX=2 INDEX=1
for J in $CHAPTERS; do for J in $CHAPTERS; do
curl -o data/$J.wiki "https://en.wikibooks.org/w/index.php?title=Ada_Style_Guide/$J&action=raw" curl -o data/$J.wiki "https://en.wikibooks.org/w/index.php?title=Ada_Style_Guide/$J&action=raw"
# Suppress quote format to replace it latter # Suppress quote format to replace it latter
@ -19,14 +21,35 @@ for J in $CHAPTERS; do
# Use quote markdown # Use quote markdown
sed -i -e 's/^QUOTE/>/' /tmp/mdx sed -i -e 's/^QUOTE/>/' /tmp/mdx
# Create front matter # Create front matter
SECTION="${INDEX}. ${J//_/ }"
if [[ ${INDEX} -eq 11 ]] ; then SECTION="11. Complete Example" ; fi
if [[ ${INDEX} -gt 11 ]] ; then SECTION="${J//_/ }" ; fi
cat > /tmp/front_matter <<-EOF cat > /tmp/front_matter <<-EOF
--- ---
title: ${J//_/ } title: ${SECTION}
sidebar_position: $INDEX sidebar_position: ${INDEX}
--- ---
EOF EOF
cat /tmp/front_matter /tmp/mdx > $OUTPUT/$J.mdx cat /tmp/front_matter /tmp/mdx note.mdx > $OUTPUT/$J.mdx
if [[ ${INDEX} -ge 3 ]] && [[ ${INDEX} -le 10 ]] ; then
mkdir $OUTPUT/s${INDEX}
mv $OUTPUT/$J.mdx $OUTPUT/s${INDEX}/$J
cd $OUTPUT/s${INDEX}
csplit -s -f "" $J '/^## /' '{*}'
rm $J
for X in * ; do
mv $X $X.mdx;
if [[ $X != 00 ]] ; then
# Turn subsection header into front matter
sed -i -e '/^## /i---' -e '/^## /a---' \
-e "/^## /s/^##/title: ${INDEX}.${X#0}/" $X.mdx
fi
done
# Rename top section file to match the folder name
mv 00.mdx s${INDEX}.mdx
cd - > /dev/null
fi
INDEX=$((INDEX+1)) INDEX=$((INDEX+1))
done done
@ -35,16 +58,16 @@ cat > /tmp/front_matter <<-EOF
--- ---
title: Ada Quality and Style Guide title: Ada Quality and Style Guide
description: Guidelines for Professional Programmers description: Guidelines for Professional Programmers
sidebar_position: 1
draft: true
slug: /style-guide
--- ---
> __*Guidelines for Professional Programmers*__ > **_Guidelines for Professional Programmers_**
EOF EOF
sed -e '/<noinclude>/,/<.noinclude>/d' data/Ada_Style_Guide.wiki | sed -e '/<noinclude>/,/<.noinclude>/d' data/Ada_Style_Guide.wiki |
pandoc -f mediawiki -t gfm --filter ./bin/aqs2mdx > /tmp/mdx pandoc -f mediawiki -t gfm --filter ./bin/aqs2mdx > /tmp/mdx
cat /tmp/front_matter /tmp/mdx > $OUTPUT/Ada_Style_Guide.mdx cat /tmp/front_matter /tmp/mdx note.mdx > $OUTPUT/Ada_Style_Guide.mdx
echo From ada-lang-io repo-folder run:
echo yarn prettier --write $OUTPUT

12
note.mdx Normal file
View File

@ -0,0 +1,12 @@
:::note
This page of the "Ada Quality and Style Guide" has been adapted from the
original work at https://en.wikibooks.org/wiki/Ada_Style_Guide, which is
licensed under the
[Creative Commons Attribution-ShareAlike License](https://creativecommons.org/licenses/by-sa/3.0/);
additional terms may apply. Page not endorsed by Wikibooks or the Ada
Style Guide Wikibook authors. This page is licensed under the same license
as the original work.
:::

View File

@ -20,9 +20,21 @@ procedure Aqs2mdx is
function Traverse (Blocks : League.JSON.Arrays.JSON_Array) function Traverse (Blocks : League.JSON.Arrays.JSON_Array)
return League.JSON.Arrays.JSON_Array; return League.JSON.Arrays.JSON_Array;
function Traverse_List (List : League.JSON.Arrays.JSON_Array)
return League.JSON.Arrays.JSON_Array;
function Traverse_Block (Block : League.JSON.Objects.JSON_Object) function Traverse_Block (Block : League.JSON.Objects.JSON_Object)
return League.JSON.Arrays.JSON_Array; return League.JSON.Arrays.JSON_Array;
function Traverse_Link (Block : League.JSON.Objects.JSON_Object)
return League.JSON.Values.JSON_Value;
Wiki : constant League.Strings.Universal_String :=
+"https://en.wikipedia.org/wiki/";
Wikibook : constant League.Strings.Universal_String :=
+"https://en.wikibooks.org/wiki/";
--------------- ---------------
-- Read_JSON -- -- Read_JSON --
--------------- ---------------
@ -60,6 +72,7 @@ procedure Aqs2mdx is
declare declare
Block : constant League.JSON.Objects.JSON_Object := Block : constant League.JSON.Objects.JSON_Object :=
Blocks (J).To_Object; Blocks (J).To_Object;
Result : constant League.JSON.Arrays.JSON_Array := Result : constant League.JSON.Arrays.JSON_Array :=
Traverse_Block (Block); Traverse_Block (Block);
begin begin
@ -85,26 +98,62 @@ procedure Aqs2mdx is
-- Flatting tables because no multiline tables in .md -- Flatting tables because no multiline tables in .md
declare declare
-- Table structure in pandoc-types-1.23.1. See
-- https://hackage.haskell.org/package/pandoc-types-1.23.1/docs/
-- Text-Pandoc-Definition.html
--
-- Table:
-- Attr Caption [ColSpec] TableHead [TableBody] TableFoot
-- 1 2 3 4 5 6
Content : constant League.JSON.Arrays.JSON_Array := Content : constant League.JSON.Arrays.JSON_Array :=
Block (+"c").To_Array; Block (+"c").To_Array;
Rows : constant League.JSON.Arrays.JSON_Array :=
Table_Body_List : constant League.JSON.Arrays.JSON_Array :=
Content (5).To_Array; Content (5).To_Array;
Columns : constant League.JSON.Arrays.JSON_Array := -- A body of a table, with an intermediate head, intermediate
Rows (1).To_Array; -- body, and the specified number of row header columns in the
begin -- intermediate body.
pragma Assert (Content.Length = 5); --
pragma Assert (Rows.Length = 1); -- TableBody Attr RowHeadColumns [Row] [Row]
pragma Assert (Columns.Length <= 3); -- 1 2 3 4
for J in 1 .. Columns.Length loop 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
Cell_List : constant League.JSON.Arrays.JSON_Array :=
Row (2).To_Array;
begin
pragma Assert (Content.Length = 6);
pragma Assert (Table_Body_List.Length = 1);
pragma Assert (Row_List.Length = 1);
pragma Assert (Cell_List.Length <= 3);
for J in 1 .. Cell_List.Length loop
declare declare
Item : constant League.JSON.Arrays.JSON_Array := Cell : constant League.JSON.Arrays.JSON_Array :=
Columns (J).To_Array; Cell_List (J).To_Array;
begin -- A table cell.
pragma Assert (Item.Length <= 1); -- Cell Attr Alignment RowSpan ColSpan [Block]
-- 1 2 3 4 5
for K in 1 .. Item.Length loop Block_List : constant League.JSON.Arrays.JSON_Array :=
List.Append (Item (K)); 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; end loop;
end; end;
end loop; end loop;
@ -117,13 +166,95 @@ procedure Aqs2mdx is
then then
-- Drop toppest 'Introduction' section header -- Drop toppest 'Introduction' section header
null; null;
else
elsif Block (+"t").To_String.To_Wide_Wide_String = "Link" then
List.Append (Traverse_Link (Block));
elsif Block (+"c").To_Array.Length > 0 then
declare
-- Traverse nested blocks
Copy : League.JSON.Objects.JSON_Object := Block;
begin
Copy.Insert
(+"c", Traverse_List (Block (+"c").To_Array).To_JSON_Value);
List.Append (Copy.To_JSON_Value);
end;
else -- Something else (if any?)
List.Append (Block.To_JSON_Value); List.Append (Block.To_JSON_Value);
end if; end if;
return List; return List;
end Traverse_Block; end Traverse_Block;
-------------------
-- Traverse_Link --
-------------------
function Traverse_Link (Block : League.JSON.Objects.JSON_Object)
return League.JSON.Values.JSON_Value
is
Copy : League.JSON.Objects.JSON_Object := Block;
Args : League.JSON.Arrays.JSON_Array := Copy (+"c").To_Array;
Fix : League.JSON.Arrays.JSON_Array := Args (3).To_Array;
Link : League.Strings.Universal_String := Fix (1).To_String;
begin
if Fix (2).To_String.To_Wide_Wide_String = "wikilink" then
if Link.Starts_With ("w:") then
Link := Wiki & Link.Tail_From (3);
else
Link := Wikibook & Link;
end if;
Fix.Replace (1, League.JSON.Values.To_JSON_Value (Link));
Fix.Replace (2, League.JSON.Values.To_JSON_Value (+""));
Args.Replace (3, Fix.To_JSON_Value);
Copy.Insert (+"c", Args.To_JSON_Value);
end if;
return Copy.To_JSON_Value;
end Traverse_Link;
-------------------
-- Traverse_List --
-------------------
function Traverse_List (List : League.JSON.Arrays.JSON_Array)
return League.JSON.Arrays.JSON_Array
is
Result : League.JSON.Arrays.JSON_Array;
begin
for J in 1 .. List.Length loop
declare
Item : constant League.JSON.Values.JSON_Value := List (J);
begin
if Item.Is_Object then
declare
Block : constant League.JSON.Objects.JSON_Object :=
Item.To_Object;
Blocks : constant League.JSON.Arrays.JSON_Array :=
Traverse_Block (Block);
begin
for K in 1 .. Blocks.Length loop
Result.Append (Blocks (K));
end loop;
end;
elsif Item.Is_Array then
Result.Append (Traverse_List (Item.To_Array).To_JSON_Value);
else
Result.Append (Item);
end if;
end;
end loop;
return Result;
end Traverse_List;
Doc : League.JSON.Documents.JSON_Document; Doc : League.JSON.Documents.JSON_Document;
begin begin