Improved handling in pandoc conversion
authorTomas Vavra <tvavra@openssl.org>
Thu, 30 Nov 2023 20:48:35 +0000 (21:48 +0100)
committerTomas Vavra <tvavra@openssl.org>
Mon, 8 Jan 2024 10:58:08 +0000 (11:58 +0100)
bin/from-tt
bin/md-to-html5
bin/mk-omc
bin/strip-man-html

index 9ab111a48905d6882aebb4bd199475dc73cc4afb..e7bea79af69e3e40a7ef1ca57166d4353e74b790 100755 (executable)
@@ -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
index e7b40b7e07014dcd27f208463f7fd89056159fab..03b4052ca30232cc8c0b814566d4f27b425b5c11 100755 (executable)
@@ -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
@@ -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
 
 ######################################################################
@@ -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
index 24144df3388148b446134aabec0009d0f70355e9..1d5907edf4a4b0859516ed371d5af32108f625b6 100755 (executable)
@@ -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$|) };
     }
 }
 
@@ -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";
 }
 
index c4842d106372dc2b2914251f238689d1d1ea60ec..0a1bf168bb4ad349452fd90bf5d20fc710c043a7 100755 (executable)
@@ -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;
@@ -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;