Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions wolfSSL/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
66 changes: 66 additions & 0 deletions wolfSSL/pdf-escape-backslashes.pl
Original file line number Diff line number Diff line change
@@ -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
(?<!`) (`+) (?!`) # 2: opening backtick run
(?: (?! \n [ \t]* \n ) . )*? # content, not across a blank line
(?<!`) \2 (?!`) # closing run of the same length
)
| ( \\ [^A-Za-z] ) # 3: existing escape, kept as is
| \\ (?= [A-Za-z] ) # lone backslash before a letter
}{ defined $1 ? $1 : defined $3 ? $3 : "\\\\" }gsxe;
return $text;
}

for my $file (@ARGV) {
open my $in, '<', $file or die "$file: $!\n";
my @lines = <$in>;
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";
}
Loading