Skip to content

Commit

Permalink
Output context with "unmatched #/" message (DistributedProofreaders…
Browse files Browse the repository at this point in the history
…#1287)

* Output context with "unmatched `#/`" message

Output up to two lines before the closing `#/` to give the user
context if they have unmatched blockquote markup when rewrapping.

Also, set stdout & stderr to utf8 to avoid "wide character" errors
when printing utf8 characters.
  • Loading branch information
windymilla authored Dec 5, 2023
1 parent 05353d1 commit d221a7b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
behavior
- Basic Fixup options are now persistent across different runs of Guiguts
- The Word Count and QuickSearch Count dialogs have clearer titles
- "Unmatched `#/`" message when rewrapping now includes two lines of
context to help user track down which blockquote is failing
- Included latest version of ebookmaker (0.12.36)
- Included latest version of Epubcheck (5.1.0)
- New TROUBLESHOOTING.md guide included with release
Expand Down
4 changes: 4 additions & 0 deletions src/guiguts.pl
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@
# Redirect warn by overriding signal handler
local $SIG{__WARN__} = \&::warnerror;

# Ensure stdout & stderr accept utf8 characters
binmode( STDOUT, ":utf8" );
binmode( STDERR, ":utf8" );

# An alternative for catching Tk background errors,
# but they are caught by the warn override above
# sub Tk::Error {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/Guiguts/SelectionMenu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ sub selectrewrap {
( $leftmargin, $firstmargin, $rightmargin ) = setblockmargins($::blockwrap);
} else {
::warnerror("Close blockquote (#/) found with no matching open markup");

# Last line in block is the closing markup, and output up to
# two more context lines before that
my @splitsel = split( /\n/, $notpmselection );
my $ncontext = scalar @splitsel;
$ncontext = 3 if $ncontext > 3;
::infoerror("Context:");
for my $ln ( 1 .. $ncontext ) {
::infoerror(" $splitsel[$ln-$ncontext-1]");
}
}
}
} else {
Expand Down

0 comments on commit d221a7b

Please sign in to comment.