App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Output/Text.pm view on Meta::CPAN
$t_line =~ s/\s+$//;
return $t_line;
}
unless ( $elt->{chords} ) {
return ( $config->{settings}->{'inline-chords'} ? () : "",
join( " ", @phrases ) );
}
if ( my $f = $config->{settings}->{'inline-chords'} ) {
$f = '[%s]' unless $f =~ /^[^%]*\%s[^%]*$/;
$f .= '%s';
foreach ( 0..$#{$elt->{chords}} ) {
if ( $elt->{chords}->[$_] ) {
$t_line .= sprintf( $f,
chord( $song, $elt->{chords}->[$_] ),
$phrases[$_] );
}
else {
$t_line .= $phrases[$_];
}
}
return ( $t_line );
}
my $c_line = "";
foreach my $c ( 0..$#{$elt->{chords}} ) {
$c_line .= chord( $song, $elt->{chords}->[$c] ) . " "
if ref $elt->{chords}->[$c];
$t_line .= $phrases[$c];
my $d = length($c_line) - length($t_line);
$t_line .= "-" x $d if $d > 0;
$c_line .= " " x -$d if $d < 0;
}
s/\s+$// for ( $t_line, $c_line );
return $chords_under
? ( $t_line, $c_line )
: ( $c_line, $t_line )
}
sub chord {
my ( $s, $c ) = @_;
return "" unless length($c);
$layout->set_markup($c->chord_display);
my $t = $layout->render;
return $c->info->is_annotation ? "*$t" : $t;
}
# Temporary. Eventually we'll have a decent HTML backend for Text::Layout.
package Text::Layout::Text;
use parent 'Text::Layout';
use ChordPro::Utils qw( fq );
# Eliminate warning when HTML backend is loaded together with Text backend.
no warnings 'redefine';
sub new {
my ( $pkg, @data ) = @_;
my $self = $pkg->SUPER::new;
$self;
}
sub render {
my ( $self ) = @_;
my $res = "";
foreach my $fragment ( @{ $self->{_content} } ) {
next unless length($fragment->{text});
$res .= fq($fragment->{text});
}
$res;
}
1;
( run in 0.780 second using v1.01-cache-2.11-cpan-5a3173703d6 )