diff --git a/wolfSSL/Makefile b/wolfSSL/Makefile index 335ef25c..55365ffd 100644 --- a/wolfSSL/Makefile +++ b/wolfSSL/Makefile @@ -90,6 +90,10 @@ html-prep: api # 4. Three regexes to remove metadata which outputs in the PDF text # 5. Fix titles of the header files Markdown # 6. Two regexes to handle bad Doxygen that didn't convert and the LaTeX processor thinks is LaTeX commands +# 7. Escape any other backslash followed by a letter in the API text, for +# example "\xHH" in a comment (pdf-escape-backslashes.pl; code and existing +# Markdown escapes are left alone). pandoc otherwise passes it through as a +# raw LaTeX command and xelatex fails with "Undefined control sequence". # Cat: # A. wolfSSL API Reference # B. wolfCrypt API Reference -> Utilities / basic items, then Algorithms @@ -115,6 +119,7 @@ pdf-prep: api $(Q)perl -i -pe "s/dox_comments\/$(HEADER_FILES)\///" build/pdf/*8h* $(Q)perl -i -pe "s/^\\\\//" build/pdf/group* build/pdf/*8h* $(Q)perl -i -pe "s/\\\\par/par/g" build/pdf/group* build/pdf/*8h* + $(Q)perl pdf-escape-backslashes.pl build/pdf/group* build/pdf/*8h* $(Q)perl -i -pe "s/group__.*?\.md//g" build/pdf/*8h* build/pdf/chapter* build/pdf/appendix* $(Q)perl -i -pe "s/[A-Za-z0-9_-]+_8h\.md//g" build/pdf/chapter* build/pdf/appendix* $(Q)cat build/pdf/group__CertManager.md build/pdf/group__Memory.md build/pdf/group__openSSL.md build/pdf/group__CertsKeys.md build/pdf/group__IO.md build/pdf/group__Setup.md build/pdf/group__Debug.md build/pdf/group__TLS.md >> build/pdf/appendix01.md diff --git a/wolfSSL/pdf-escape-backslashes.pl b/wolfSSL/pdf-escape-backslashes.pl new file mode 100644 index 00000000..7a60a54a --- /dev/null +++ b/wolfSSL/pdf-escape-backslashes.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +# +# Escape backslashes in the Doxybook2 API reference pages before the PDF +# build. pandoc reads a backslash followed by letters (for example "\xHH" in +# an API comment) as a raw LaTeX command and passes it to xelatex, which then +# fails with "Undefined control sequence". Such a backslash is doubled so that +# pandoc prints it literally. +# +# Left unchanged: +# - fenced code blocks (``` or ~~~, closed by a fence of the same character +# that is at least as long as the opening one) +# - inline code spans, including spans that continue onto the next line +# - existing Markdown escapes, i.e. a backslash followed by anything other +# than a letter (this includes an already escaped "\\") +# +# Usage: perl pdf-escape-backslashes.pl FILE... (files are edited in place) + +use strict; +use warnings; + +sub escape_prose { + my ($text) = @_; + $text =~ s{ + ( # 1: inline code span + (?; + close $in; + + my ($out, $prose, $fence) = ('', '', ''); + for my $line (@lines) { + if ($fence eq '') { + if ($line =~ /^[ \t]*(`{3,}|~{3,})/) { + $out .= escape_prose($prose) . $line; + $prose = ''; + $fence = $1; + } + else { + $prose .= $line; + } + } + else { + $out .= $line; + my $c = substr($fence, 0, 1); + if ($line =~ /^[ \t]*(\Q$c\E{3,})\s*$/ + && length($1) >= length($fence)) { + $fence = ''; + } + } + } + $out .= escape_prose($prose); + + open my $o, '>', $file or die "$file: $!\n"; + print {$o} $out; + close $o or die "$file: $!\n"; +}