Compare commits

..

No commits in common. "72c71e2a7015867a2aec56802c3323a18fddd931" and "fb06c44f340729a7ec5b36a563ec52b443d722a7" have entirely different histories.

5 changed files with 23 additions and 220 deletions

View File

@ -1,24 +0,0 @@
#!/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,13 +2,9 @@
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 a pandoc filter with Alire:
You need `pandoc`, `curl`, `sed` installed. Build a pandoc filter with Alire:
alr build
@ -16,9 +12,6 @@ Then run:
./fetch.sh <OUTPUT_DIR>
Then run `yarn format` in ada-lang.io repository to reformat output according
to Docusaurus style.
## To be fixed
* Arrange code blocks in Source Code Presentation in two columns

View File

@ -1,7 +1,5 @@
#!/bin/bash
set -e
ulimit -s unlimited # To fix stack overflow on a large JSON input
OUTPUT=${1:-/tmp/src/ada-lang-io/docs/style-guide}
AQS2MDX=./bin/aqs2mdx
@ -11,7 +9,7 @@ mkdir -p $OUTPUT
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'`
INDEX=1
INDEX=2
for J in $CHAPTERS; do
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
@ -21,35 +19,14 @@ for J in $CHAPTERS; do
# Use quote markdown
sed -i -e 's/^QUOTE/>/' /tmp/mdx
# 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
---
title: ${SECTION}
sidebar_position: ${INDEX}
title: ${J//_/ }
sidebar_position: $INDEX
---
EOF
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
cat /tmp/front_matter /tmp/mdx > $OUTPUT/$J.mdx
INDEX=$((INDEX+1))
done
@ -58,16 +35,16 @@ cat > /tmp/front_matter <<-EOF
---
title: Ada Quality and Style Guide
description: Guidelines for Professional Programmers
sidebar_position: 1
draft: true
slug: /style-guide
---
> **_Guidelines for Professional Programmers_**
> __*Guidelines for Professional Programmers*__
EOF
sed -e '/<noinclude>/,/<.noinclude>/d' data/Ada_Style_Guide.wiki |
pandoc -f mediawiki -t gfm --filter ./bin/aqs2mdx > /tmp/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
cat /tmp/front_matter /tmp/mdx > $OUTPUT/Ada_Style_Guide.mdx

View File

@ -1,12 +0,0 @@
:::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,21 +20,9 @@ procedure Aqs2mdx is
function Traverse (Blocks : 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)
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 --
---------------
@ -72,7 +60,6 @@ procedure Aqs2mdx is
declare
Block : constant League.JSON.Objects.JSON_Object :=
Blocks (J).To_Object;
Result : constant League.JSON.Arrays.JSON_Array :=
Traverse_Block (Block);
begin
@ -98,62 +85,26 @@ procedure Aqs2mdx is
-- Flatting tables because no 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/
-- Text-Pandoc-Definition.html
--
-- Table:
-- Attr Caption [ColSpec] TableHead [TableBody] TableFoot
-- 1 2 3 4 5 6
Content : constant League.JSON.Arrays.JSON_Array :=
Block (+"c").To_Array;
Table_Body_List : constant League.JSON.Arrays.JSON_Array :=
Rows : 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
Cell_List : constant League.JSON.Arrays.JSON_Array :=
Row (2).To_Array;
Columns : constant League.JSON.Arrays.JSON_Array :=
Rows (1).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);
pragma Assert (Content.Length = 5);
pragma Assert (Rows.Length = 1);
pragma Assert (Columns.Length <= 3);
for J in 1 .. Cell_List.Length loop
for J in 1 .. Columns.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
Block_List : constant League.JSON.Arrays.JSON_Array :=
Cell (5).To_Array;
Item : constant League.JSON.Arrays.JSON_Array :=
Columns (J).To_Array;
begin
pragma Assert (Cell.Length = 5);
pragma Assert (Item.Length <= 1);
for K in 1 .. Block_List.Length loop
List.Append (Block_List (K));
for K in 1 .. Item.Length loop
List.Append (Item (K));
end loop;
end;
end loop;
@ -166,95 +117,13 @@ procedure Aqs2mdx is
then
-- Drop toppest 'Introduction' section header
null;
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?)
else
List.Append (Block.To_JSON_Value);
end if;
return List;
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;
begin