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

I'm a little perplexed on how to get formatted {newlined and indented} HTML out of HTML::LoL. Here's my code:
my $htmlTEMP ; sub MakeHTML { my $spec = $_[0] ; $htmlTEMP = "" ; return &hl(sub{$htmlTEMP .= $_[0] ; }, $spec) ; } print MakeHTML([HTML => [BODY => [FORM => [LABEL => {for => "user"}, "Who are you?" +], [INPUT => {type => "text", name=> "user"} + ] ] ]]);
and what it prints is correct but ugly :)
<html> <body><form><label for="user">Who are you?</label><input type="text" +name="user"></form></body> </html>
What am I doing wrong? tnx

Replies are listed 'Best First'.
Re: Newlines in HTML::LoL
by Radiola (Monk) on Feb 01, 2021 at 18:52 UTC

    Run the output of HTML::LoL through something like HTML::Tidy or HTML::Tidy5 on its way out?


    – Aaron
    Preliminary operational tests were inconclusive. (The damn thing blew up.)
Re: Newlines in HTML::LoL
by Your Mother (Archbishop) on Feb 01, 2021 at 18:53 UTC

    Never use HTML to achieve layout, only semantic structure. All formatting should be via CSS. Use templates. They are easy once you get the hang of them. HTML widgets are not your friend, especially not long term and super duper especially not 19 year-old abandonware with perl4 idioms. CGI has better HTML routines in it, should it come to that, and is tested and current.

    <html lang="en-lolcat"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" / +> <title>I CAN HAZ FRENS?</title> <style type="text/css" media="all"> html,body { height:100%; width: 100%; font-family:"trebuchet ms","helvetica neue",helvetica,sans-serif; margin: 5% 10%; padding: 0; font-size:16px; } h1.literal { white-space:pre; } h1.hang { text-indent:-2rem; margin-left:2rem; } </style> </head> <body> <h1 class="literal">OHAI DER, …FREN</h1> <h3>…or possibly more correct…</h3> <h1 class="hang">OHAI DER,<br/>…FREN</h1> <p>Other options no doubt exist at this point in the CSS game.</p> </body> </html>
      > CGI has better HTML routines in it, should it come to that, and is tested and current.

      agreed, but the current maintainer is discouraging the use.°

      https://metacpan.org/pod/CGI#HTML-Generation-functions-should-no-longer-be-used

      I'd rather prefer to have them factored out into an extra module and maintained by someone else. (this is NOT a critic of Lee!!!)

      I'm wondering if SawyerX' talk about how "CGI must die" went too far in it's effects ...

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      °) which is why I didn't mention it.

      All formatting should be via CSS. Use templates. They are easy once you get the hang of them

      I'll second that!
      As a recent convert to templates, there is no way I would use anything else now.

      Template is easy to use and very versatile

Re: Newlines in HTML::LoL
by LanX (Saint) on Feb 01, 2021 at 17:43 UTC
    Hi

    did you try

    hl_preserve(...) ?

    From the docs:

    - hl_preserve(...)

    Normally, HTML::LoL tries to optimize the whitespace in the HTML it emits (without changing the meaning of the HTML). This suppresses that behavior within its arguments.

    update

    HINT: If you want good and quick answers to exotic modules, try linking to them with [mod://...] to help those who wanna help you...

    Like [mod://HTML::LoL] --> HTML::LoL

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      Sorry about that -- I didn't realize HTML::LoL was an exotic/strange module. I"m using CGI::Simple and I wanted to supplement it with something similarly simple to generate the HTML. I know that that the one-line HTML is perfectly legal, but that was a test to see how HTML::LoL worked. In my actual web page the HTML will be a lot more complicated and it'll be easier for me to see what I messed up in the array refs and stuff if the HTML is nicely, rather than just legally, formatted.
        No need to apologize it's just that you'll get more answers if you link to the modules in question.

        FWIW: I'm using an JS-addon which does auto-linking of colon separated strings like CGI::Simple --> CGI::Simple .

        See link in my signature if interested.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        h1_preserve didn't work at all. What I got back for the same program, but the h1 changed to hl_preserve was an array ref, no text at all and a dd on the result showed me:
        [ bless(do{\(my $o = "preserve")}, "HTML::LoL::Special"), sub { ... }, [ "HTML", [ "BODY", [ "FORM", ["LABEL", { for => "user" }, "Who are you?"], ["INPUT", { name => "user", type => "text" }], ], ], ], ]
        which isn't quite what I wanna send to a browser :)
A reply falls below the community's threshold of quality. You may see it by logging in.