Skip to content

Commit

Permalink
Perl script to mark lines in lg/sp elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellingman committed Jan 5, 2025
1 parent 3912bda commit 12bca16
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
11 changes: 11 additions & 0 deletions modules/divisions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@
</xsl:template>


<xsl:function name="f:has-head" as="xs:boolean">
<xsl:param name="div"/>
<xsl:sequence select="$div/head[not(f:rend-value(./@rend, 'display') = 'image-only')]"/>
</xsl:function>

<xsl:function name="f:determine-output-div-element" as="xs:string">
<xsl:param name="div"/>
<xsl:sequence select="if (f:is-html5() and f:has-head($div)) then 'section' else 'div'"/>
</xsl:function>


<xd:doc>
<xd:short>Format head element of div0.</xd:short>
<xd:detail>Format a head element for a <code>div0</code>. At this level we still set the running header (for ePub3).</xd:detail>
Expand Down
2 changes: 0 additions & 2 deletions tei2imageinfo.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
<xsl:variable name="p.element" select="'p'"/>




<xsl:template match="/">
<images>
<xsl:apply-templates mode="imageinfo"/>
Expand Down
95 changes: 95 additions & 0 deletions tools/tagPoetryLgSp.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# poetry.pl -- add <l> tags on new-lines in poetry / drama, based on the presence of <lg> or <sp> tags.

use strict;
use warnings;

my $lgSeen = 0;
my $spSeen = 0;
my $spLooksLikeProse = 0;
my $lineNumber = 0;


while (<>) {
my $line = $_;
$lineNumber++;

if ($line =~ /^<lg>$/) {
if ($spSeen > 0) {
print STDERR "WARNING: entering <lg> inside <sp> on line $lineNumber!\n";
}
if ($lgSeen > 0) {
print STDERR "WARNING: entering nested <lg> ($lgSeen) on line $lineNumber!\n";
}
$lgSeen++;
print "<lg>\n";

} elsif ($line =~ /^<\/lg>$/) {
if ($lgSeen == 0) {
print STDERR "ERROR: unmatched </lg> on line $lineNumber!\n";
} else {
$lgSeen--;
}
print "</lg>\n";

} elsif ($line =~ /^(<sp\b.*?>)/) {
my $tag = $1;
if ($lgSeen > 0) {
print STDERR "WARNING: entering $tag inside <lg> on line $lineNumber!\n";
}
if ($spSeen > 0) {
print STDERR "WARNING: entering $tag inside <sp> on line $lineNumber!\n";
} else {
$spLooksLikeProse = 0;
}
$spSeen++;
print $line;

} elsif ($line =~ /^<\/sp>$/) {
if ($spSeen == 0) {
print STDERR "ERROR: unmatched </sp> mode on line $lineNumber!\n";
} else {
$spSeen--;
}
print "</sp>\n";


} elsif ($lgSeen == 0 && $spSeen == 0 || ($spSeen > 0 && $spLooksLikeProse == 1)) {
print $line;

} elsif ($line =~ /^<speaker/) {
print $line;

} else {
if ($spSeen > 0 && $line =~ /^[a-z]/) {
print STDERR "WARNING: <sp> looks like prose on line $lineNumber!\n";
$spLooksLikeProse = 1;
print $line;
} elsif ($line =~ /^\s*$/) {
# blank line in poetry mode:

print "</lg>\n\n<lg>\n";
} elsif ($line =~ /^\s*<l>/) { # Already tagged
print $line;
} else {
# count white space before
$line =~ /^(\s*)(.*)$/;
my $spaces = $1;
$line = $2;
my $n = length($spaces);
if ($n == 0) {
print " <l>$line\n";
} else {
print " $spaces<l rend=\"indent($n)\">$line\n";
}
}
}
}

if ($spSeen != 0) {
print STDERR "ERROR: open <sp> tags ($spSeen) at end of file!\n"
}

if ($lgSeen != 0) {
print STDERR "ERROR: open <lg> tags ($lgSeen) at end of file!\n"
}

0 comments on commit 12bca16

Please sign in to comment.