From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 6C3F0BB84 for ; Sun, 9 Jul 2006 09:04:28 +0200 (CEST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.188]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6974Rhu000325 for ; Sun, 9 Jul 2006 09:04:28 +0200 Received: by nf-out-0910.google.com with SMTP id d4so431593nfe for ; Sun, 09 Jul 2006 00:04:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=DeKLOr0FSecDXzfYRuDEWujBQlnFpEGjjeNdPobs+5nrSRE3hej7F/VXnSCWJCtNEC92SXBh7EI3ntrssJb1Qa7P97b8AqKFrTQOpXbIUzbreioHPTEOiWgajqOOIQ7+9+5kZE0OlEVoil8xIGZXZVcHuspr6+zUaCsaRBz6uck= Received: by 10.78.138.14 with SMTP id l14mr1278017hud; Sun, 09 Jul 2006 00:04:27 -0700 (PDT) Received: by 10.78.13.17 with HTTP; Sun, 9 Jul 2006 00:04:27 -0700 (PDT) Message-ID: Date: Sun, 9 Jul 2006 09:04:27 +0200 From: "Nicolas Pouillard" Sender: nicolas.pouillard@gmail.com To: "Jonathan Roewen" Subject: Re: [Caml-list] Format & breaking Cc: OCaml In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: 7fa67b9ee21437a5 X-Miltered: at nez-perce with ID 44B0AA7B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; semantics:01 elt:01 fprintf:01 rec:01 elt:01 elts:01 elts:01 rec:01 printf:01 ,...:98 wrote:01 caml-list:01 behaviour:01 short:01 nicolas:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE,RCVD_BY_IP autolearn=disabled version=3.0.3 On 7/8/06, Jonathan Roewen wrote: > Hi, > > I have a small question about format module, and pretty-printing XHTML. > > Basically, I want to print something like: > >
>

....

>

....

// when content fits on a single line.. >

// when content doesn't fit on a single line... > .... >

>
> > but I can't get it to generate that. I was reading about the > structural hovboxes, but the behaviour it describes doesn't seem to > work -- at least with xhtml tags. > > For example, the above would be printed as: >
>

....

>

....

// when content fits on a single line.. >

// when content doesn't fit on a single line... > ....

> > which is frustrating. Or else I'm just misunderstanding the semantics > of the Format module, which wouldn't surprise me ;-) > To do that you need two boxes: "@[@[

@,...@]@,

@]" Here a more complete example: type xml = Elt of string * xml list | Pcdata of string let pp = Format.fprintf let rec print_elt f = function | Elt (tag, contents) -> pp f "@[@[<%s>@,%a@]@,@]" tag print_list_elts contents tag | Pcdata s -> Format.pp_print_string f s and print_list_elts f = let rec loop = function | [] -> () | x::xs -> (pp f "@,"; print_elt f x; loop xs) in function | [] -> () | [x] -> print_elt f x | x::xs -> (print_elt f x; loop xs) let tree = Elt ("div", [ Elt ("p", [Pcdata "a short text"]); Elt ("p", [Pcdata "a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text"]) ]) let () = Format.printf "%a@." print_elt tree Regards, -- Nicolas Pouillard