Better postASP tscreen support using LyX-Code. More checks in preASP.

* Use Lyx-Code more extensively. Do not use begin/end_deeper
* Better postASP support for non verbatim in tscreen.

    We want to support things like

    <tscreen><verb>
    I am a <tt/verbatim/ line
    </verb>
    I am not a <tt/verbatim/ line
    </tscreen>

  Since nsgmls will break lines when look changing commands are found in
  tscreen+non-verbatim, we need to make sure that LyX-Code commands are
  not sent neither during the look change nor in the line after it. No
  problem in verbatim+tscreen, since lines will not be broken.

  We use $inlookchange to signal this, 0 or undefined means no look change,
  1 means in look change and 2 means last line ended a look change.
parent 5f96f08e
......@@ -36,6 +36,7 @@ my $lyx_escape = sub {
# -----------------------------------------------------------------------
my ($data) = @_;
# The single exception backslash is treated below
return ($data);
};
......@@ -46,7 +47,8 @@ $lyx->{preASP} = sub {
# Note that currently LyX works only with isolatin1
# -----------------------------------------------------------------------
my ($INFILE, $OUTFILE) = @_;
# The single exception backslash is treated bellow
my $verbatim;
my $inheading;
# `sdata_dirs' list is passed as anonymous array to make a single argument
my $char_maps = load_char_maps ('.2l1b', [ Text::EntityMap::sdata_dirs() ]);
......@@ -61,7 +63,7 @@ $lyx->{preASP} = sub {
s/\\\|refnam\\\|/ /g;
if ( s/^-// ) {
print $OUTFILE "-" . &parse_data($_, $char_maps, $lyx_escape) . "\n";
print $OUTFILE "-" . parse_data($_, $char_maps, $lyx_escape) . "\n";
} elsif (/^A/) {
/^A(\S+) (IMPLIED|CDATA|NOTATION|ENTITY|TOKEN)( (.*))?$/
|| die "bad attribute data: $_\n";
......@@ -72,6 +74,15 @@ $lyx->{preASP} = sub {
}
print $OUTFILE "A$name $type $value\n";
} else {
if (/^\(HEADING/){
$inheading = 1;
} elsif (/^\)HEADING/){
$inheading = '';
} elsif (/^\((VERB|CODE)/) {
$verbatim = 1;
} elsif (/^\)(VERB|CODE)/) {
$verbatim = '';
}
print $OUTFILE $_ . "\n";
}
}
......@@ -91,6 +102,7 @@ $lyx->{postASP} = sub {
my $indent_level = -1;
my $verb_last_line = "";
my $verbatim = 0;
my $inlookchange;
my $inheading;
my $initem;
my $intag;
......@@ -172,11 +184,8 @@ $lyx->{postASP} = sub {
} # tscreen
elsif( /^\@tscreen\@/ ) {
$tscreen = 1;
$lyxout .= "\\begin_deeper\n";
$lyxout .= "\\layout Standard\n"
} elsif ( /^\@\/tscreen\@/ ) {
} elsif ( /^\@\/tscreen\@/ ) {
$tscreen = 0;
$lyxout .= "\\end_deeper\n";
$lyxout .= "\\layout Standard\n";
} # Verbatim
elsif( /^\@verb\@/ ) {
......@@ -184,23 +193,41 @@ $lyx->{postASP} = sub {
} elsif ( /^\@\/verb\@/ ) {
$verbatim = 0;
} else {
$inheading = 0 if ( /^\\layout Standard/ );
$intt = 0 if ( /^\\family default.*$/ );
$inheading = 1 if ( /^\\layout (Part|Chapter|.*section|.*paragraph)/ );
$inlookchange = 1 if ( m/^\\(family|series|shape)/ && ! m/default/ );
$intt = 1 if ( /^\\family typewriter.*$/ );
# For LyX file clarity
s/\\backslash/\n\\backslash\n/g unless ( $verbatim or $inheading or $intt);
s/\s+/ /g unless ( $verbatim or $intt );
s/\s+/ /g unless ( $verbatim or $intt or $tscreen );
if ( $intag ) {
s/\s+/\n\\protected_separator\n/g unless m/^\\(family|series|shape)/;
} elsif ( $verbatim ) {
$_ = "\\layout LyX-Code\n$_";
} elsif ( $tscreen ) {
if ( $verbatim ) {
# If verbatim, there are no line breaks when things like <tt/../ appears.
$_ = "\\layout LyX-Code\n$_";
} else {
# We do not want to have LyX-Code commands when line breaks are caused by
# look changing commands like \family .... This also applies to the line
# after \... default (so the $inlookchange == 2 hack below.)
$_ = "\\layout LyX-Code\n$_" unless $inlookchange;
}
} elsif ( $inheading) {
s/\s+/ /g;
}
$inheading = 1 if ( /^\\layout (Part|Chapter|.*section|.*paragraph)/ );
$intt = 1 if ( /^\\family typewriter.*$/ );
$inheading = 0 if ( /^\\layout Standard/ );
if ( /^\\family default.*$/ ) {
$intt = 0;
# Signal for next line processing that this is an end-look-change command
$inlookchange = 2;
} elsif ( $inlookchange == 2 ) {
# Line previous to this one was an end-look-change command
$inlookchange = 0;
}
$lyxout .= "$_\n";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment