Skip to content

Commit

Permalink
Improved handling in pandoc conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
vavroch2010 committed Jan 8, 2024
1 parent 04fc13a commit 99f95ac
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 132 deletions.
1 change: 0 additions & 1 deletion bin/from-tt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ else
for f in "$@"; do
base_with_ext="${f##*/}"
base=${base_with_ext%.tt}
# base=$(basename "$f" .tt)
filedir=$(dirname "$f")

if [ "$f" != "$base" ]; then
Expand Down
197 changes: 102 additions & 95 deletions bin/md-to-html5
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#! /bin/bash
. ./bin/utils.sh

HERE=$(cd $(dirname_custom $0); pwd)
HERE=$(
cd $(dirname_custom $0)
pwd
)
THIS=$(basename_custom $0)

# Our HTML5 template, produced from the default pandoc template with some
Expand Down Expand Up @@ -45,37 +48,37 @@ They must come before any file name."

# Standard getopt calling sequence
if ! TEMP=$(getopt -o "$shortopts" --long "$longopts" -n $THIS -- "$@"); then
echo >&2 "$usage"
exit 1
echo >&2 "$usage"
exit 1
fi
eval set -- "$TEMP"
unset TEMP

# Check the parsed options
while true; do
case "$1" in
'-o' | '--output' )
output="$2"
shift 2
;;
'-i' | '--index' )
index=1
shift
;;
'-h' | '--help' )
echo >&2 "$usage"
exit 0
;;
'--' )
shift
break
;;
* )
echo >&2 'Internal error!'
echo >&2 "$usage"
exit 1
;;
esac
case "$1" in
'-o' | '--output')
output="$2"
shift 2
;;
'-i' | '--index')
index=1
shift
;;
'-h' | '--help')
echo >&2 "$usage"
exit 0
;;
'--')
shift
break
;;
*)
echo >&2 'Internal error!'
echo >&2 "$usage"
exit 1
;;
esac
done

######################################################################
Expand All @@ -87,96 +90,100 @@ done
# --output. Otherwise, read from the input files and write to corresponding
# output files.
if [ $# -eq 0 ]; then
if [ -z "$output" ]; then
echo >&2 'Output path must be set with -o / --output in this mode'
exit 1
fi
if [ -z "$output" ]; then
echo >&2 'Output path must be set with -o / --output in this mode'
exit 1
fi

if [ "$(basename_custom "$output" .html)" = "$output" ]; then
echo >&2 'Output path must end with .html'
exit 1
fi
if [ "$(basename_custom "$output" .html)" = "$output" ]; then
echo >&2 'Output path must end with .html'
exit 1
fi

# Set '-' to mean stdin / stdout
set -- -
# Set '-' to mean stdin / stdout
set -- -
elif [ -n "$output" ]; then
echo >&2 '-o / --output is confusing in this mode'
exit 1
echo >&2 '-o / --output is confusing in this mode'
exit 1
fi

# Check that all the arguments are existing and correctly named files
errfiles=
nofiles=
for f in "$@"; do
[ "$f" = "-" ] && continue
[ "$f" = "-" ] && continue

base=$(basename_custom "$f" md)
base=$(basename_custom "$f" md)

if [ "$base" = "$f" ]; then
errfiles="$errfiles '$f'"
elif [ ! -f "$f" ]; then
nofiles="$nofiles '$f'"
fi
if [ "$base" = "$f" ]; then
errfiles="$errfiles '$f'"
elif [ ! -f "$f" ]; then
nofiles="$nofiles '$f'"
fi
done
if [ -n "$errfiles" ]; then
echo >&2 "Files not ending with .md:$errfiles"
echo >&2 "Files not ending with .md:$errfiles"
fi
if [ -n "$nofiles" ]; then
echo >&2 "Files no present:$nofiles"
echo >&2 "Files no present:$nofiles"
fi
if [ -n "$errfiles" -o -n "$nofiles" ]; then
exit 1
exit 1
fi

title_prefix=""
for f in "$@"; do
if [ "$f" != "-" ]; then
base=$(basename_custom "$f" md)
dir=$(dirname "$f")

if [ "$f" = "$base" ]; then
continue;
fi
else
base=$(basename_custom "$output" html)
dir=$(dirname "$output")
fi

if [ "$dir" = "." -o "$dir" = "" ]; then
title="/$base.html"
top=""
else
title="/$dir/$base.html"
top=`echo "$dir" | sed -E -e 's|[^/]+|..|g'`/
if [ "$f" != "-" ]; then
base=$(basename_custom "$f" md)
dir=$(dirname "$f")
input=$(grep "breadcrumb: " < $f);
prefix=${input#"breadcrumb: "}
if [ ! -z "$prefix" ]
then
title_prefix="[ ${prefix} ] - "
fi

# is it an index file?
def_isindex=
if [ -n "$index" -o "$base" = "index" ]; then
def_isindex="-M is-index=true"
if [ "$f" = "$base" ]; then
continue
fi
else
base=$(basename_custom "$output" html)
dir=$(dirname "$output")
fi

if [ "$dir" = "." -o "$dir" = "" ]; then
title="/$base.html"
top=""
else
title="$title_prefix/$dir/$base.html"
top=$(echo "$dir" | sed -E -e 's|[^/]+|..|g')/
fi

# is it an index file?
def_isindex=
if [ -n "$index" -o "$base" = "index" ]; then
def_isindex="-M is-index=true"
fi

# metadata
meta_file=""
input_file=""
meta="$dir/dirdata.yaml"
if [ -f "$meta" ]; then
meta_file="$HERE/../$meta"
fi

if [ "$f" = "-" ]; then
input_file="-"
else
input_file="$HERE/../$f"
fi

pandoc -t html5 -f markdown --template="$template" \
--highlight-style="$highlightstyle" \
--tab-stop=8 --shift-heading-level-by=1 \
-M author-meta='OpenSSL Foundation, Inc.' \
-M lang=en \
-M pagetitle="$title" \
$def_isindex -M top="$top" -o "$dir/$base.html" $meta_file $input_file

(
# metadata
meta="$dir/dirdata.yaml"
if [ -f "$meta" ]; then
cat $meta
fi

if [ "$f" = "-" ]; then
cat
else
cat "$f"
fi
) | (
cd $dir
pandoc -t html5 -f markdown --template="$template" \
--highlight-style="$highlightstyle" \
--tab-stop=8 --shift-heading-level-by=1 \
-M author-meta='OpenSSL Foundation, Inc.' \
-M lang=en \
-M pagetitle="$title" \
$def_isindex -M top="$top"
) | (
cat > "$dir/$base.html"
)
done
69 changes: 34 additions & 35 deletions bin/mk-omc
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ use HTML::Entities;
my %options = ();
GetOptions(
\%options,
'name|n', # Show name
'email|e', # Show email
'locale|l', # Show locale
'pgp|p', # Show PGP key ID
'activity|a', # Show whether person is active
'title|t=s', # Title of the resulting table
'help|?', # Help
'man', # Full manual
) or pod2usage(2);
'name|n', # Show name
'email|e', # Show email
'locale|l', # Show locale
'pgp|p', # Show PGP key ID
'activity|a', # Show whether person is active
'title|t=s', # Title of the resulting table
'help|?', # Help
'man', # Full manual
) or pod2usage(2);

pod2usage(1) unless $options{title};
pod2usage(1)
unless ($options{name} || $options{email} || $options{locale}
|| $options{activity} || $options{pgp});
|| $options{activity} || $options{pgp});
pod2usage(1) if $options{help};
pod2usage(-exitval => 0, -verbose => 2) if $options{man};

my $query = OpenSSL::Query->new();

my %data = (); # Indexed by name, value is a hash table of vals
my %data = (); # Indexed by name, value is a hash table of vals
foreach my $groupname (@ARGV) {
my @members = $query->members_of($groupname);
foreach my $ids (@members) {
my $name = (grep m|\s|, @$ids)[0];
my $email = (grep m|\@openssl\.org$|, @$ids)[0];
my $locale = $query->find_person_tag($email, 'country');
my $pgpid = $query->find_person_tag($email, 'pgp');
$data{$name} = { email => $email, locale => $locale, pgpid => $pgpid,
active => !!($groupname !~ m|-inactive$|),
emeritus => !!($groupname =~ m|-emeritus$|) };
my $name = (grep m|\s|, @$ids)[0];
my $email = (grep m|\@openssl\.org$|, @$ids)[0];
my $locale = $query->find_person_tag($email, 'country');
my $pgpid = $query->find_person_tag($email, 'pgp');
$data{$name} = { email => $email, locale => $locale, pgpid => $pgpid,
active => !!($groupname !~ m|-inactive$|),
emeritus => !!($groupname =~ m|-emeritus$|) };
}
}

Expand All @@ -53,36 +53,35 @@ push @columns, 'PGP Key ID' if $options{pgp};
print "<table summary=\"$options{title}\">\n";
print " <tr>\n";
print join(" <th>&nbsp;&nbsp;</th>\n",
map { " <th>$_</th>\n" } @columns);
map {" <th>$_</th>\n"} @columns);
print " </tr>\n";

foreach my $key (sort { mk_sortable($a) cmp mk_sortable($b) } keys %data) {
foreach my $key (sort {mk_sortable($a) cmp mk_sortable($b)} keys %data) {
my $pgpurl = $data{$key}->{pgpid} if $options{pgp};
$pgpurl =~ s|\s+||g if $pgpurl;
$pgpurl =
"https://keys.openpgp.org/search?q=$pgpurl"
if $pgpurl;
$pgpurl = "https://keys.openpgp.org/search?q=$pgpurl"
if $pgpurl;

my @columndata = ();
push @columndata,
join('',
$data{$key}->{active} ? "" : "<i>",
encode_entities($key),
$data{$key}->{active} ? "" : "</i> (I)",
$data{$key}->{emeritus} ? " (OMC Emeritus)" : "")
if $options{name};
join('',
$data{$key}->{active} ? "" : "<i>",
encode_entities($key),
$data{$key}->{active} ? "" : "</i> (I)",
$data{$key}->{emeritus} ? " (OMC Emeritus)" : "")
if $options{name};
push @columndata,
"<a href='mailto:$data{$key}->{email}'>$data{$key}->{email}</a>"
if $options{email};
"<a href='mailto:$data{$key}->{email}'>$data{$key}->{email}</a>"
if $options{email};
push @columndata, $data{$key}->{locale} if $options{locale};
push @columndata,
$data{$key}->{pgpid}
? "<a href='$pgpurl'>$data{$key}->{pgpid}</a>" : '&nbsp;'
if $options{pgp};
$data{$key}->{pgpid}
? "<a href='$pgpurl'>$data{$key}->{pgpid}</a>" : '&nbsp;'
if $options{pgp};

print " <tr>\n";
print join(" <td>&nbsp;&nbsp;</td>\n",
map { " <td>$_</td>\n" } @columndata);
map {" <td>$_</td>\n"} @columndata);
print " </tr>\n";
}

Expand Down
6 changes: 5 additions & 1 deletion bin/strip-man-html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# pod2html creates complete pages, but we want embeddable ones.
# Fortunately, it's easy to find the stuff that need to go away.

local $/; # Slurp the whole file
use strict;
use warnings;
local $/; # Slurp the whole file
my $contents = <STDIN>;

$contents =~ m@^<h1 id="NAME">NAME</h1>@m;
Expand All @@ -13,5 +15,7 @@ $contents = $`; # </body> and everything after is stripped

# Adapt all H tags to be wrapped inside H1 and H2
$contents =~ s@(</?h)(\d)(\s|>)@$1.($2 + 2).$3@emg;
#added from /bin/fix-man-html
$contents =~ s|\]\(|\&rbrack;(|g; # ]( suggests a markdown link

print $contents;

0 comments on commit 99f95ac

Please sign in to comment.