gsd4me has asked for the wisdom of the Perl Monks concerning the following question:

Am trying to generate some HTML using HTML::Tiny, which has been a good resource, up until now! I want to create an HTML5 tag of audio, such as:

<audio controls> src = "file.mp3", type = "audio/mpeg" </audio>
using the perl code:
$co->tag ('audio', { controls=>[], type => "audio\/mpeg", src => "$fil +ename.".mp3"})
which produces this output:
<audio controls="controls" src="theme1.mp3" type="audio/mpeg"></audio>
In the HTML::Tiny documentation, it states (from the CPAN depository)
An empty attribute - such as 'checked' in a checkbox can be encoded by + passing an empty array reference: print $h->closed( 'input', { type => 'checkbox', checked => [] } ); would print <input checked type="checkbox" />
so what I want is an empty attribute for my "controls" part of the audio tag, which is obviously what is not happening. Any guidance? regards ADB

Replies are listed 'Best First'.
Re: HTML::Tiny, null parameter tags contradicting documentation
by tobyink (Canon) on Aug 24, 2018 at 11:21 UTC

    As an aside, in SGML-based versions of HTML (i.e. before HTML5), <foo bar> is considered to be a shorthand for <foo bar="bar">. Most web browsers treated <foo bar> as being equivalent to <foo bar=""> though, which is why the HTML5 spec treats it that way.

Re: HTML::Tiny, null parameter tags contradicting documentation
by TheloniusMonk (Sexton) on Aug 24, 2018 at 07:41 UTC
    Perhaps a doc bug. But an empty attribute can also be set as e.g. controls="". So
    use HTML::Tiny; my $co = HTML::Tiny->new; my $filename = 'theme1'; print $co->tag ('audio', { controls=>"", type => "audio\/mpeg", src => + "$filename.mp3"}); print "\n";
    produces
    <audio controls="" src="theme1.mp3" type="audio/mpeg"></audio>
    which ought to have the same effect.
Re: HTML::Tiny, null parameter tags contradicting documentation
by Lotus1 (Vicar) on Sep 02, 2018 at 18:08 UTC

    I could not reproduce your results. Your example output an empty attribute in my test code. Please provide a complete program with your actual code and output.

    use warnings; use strict; use HTML::Tiny; ## from the module documention my $h = HTML::Tiny->new( mode => 'html' ); print $h->closed( 'input', { type => 'checkbox', checked => [] } ); print "\n"; ## example from OP print $h->tag ('audio', { controls=>[], type => "audio\/mpeg", src => +"test.mp3"}); __DATA__ <input checked type="checkbox"> <audio controls src="test.mp3" type="audio/mpeg"></audio>