Re: Better block literals
Ingy dot Net <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
>From what I understand, you are taking HTML textarea input and trying to
write your own YAML stream using your own JavaScript (because PyYaml has not
yet been ported to JavaScript :).
You can do something like this:
yaml = '---\nstringskey: |2+\n' + jQuery('textarea').val().replace(/^(.)/mg,
' $1') + '...\n';
At one point we considered adding terminators to literal blocks (like in
Perl's HEREDOCs), but we decided they were problematic, not elegant, and
ultimately unneeded.
Cheers, Ingy
On Sat, Apr 11, 2009 at 10:25 AM, <7845330-4/[email protected]> wrote:
> The block literal string scalar needs what every other data format has -
> a length header. YAML needs a way to accept literal blocks that have
> nothing to do with any indentation.
>
> A user-specified terminator is another way. This is just the Pascal/C
> difference in strings, applied at a block abstraction level. As I see
> it, YAML only uses indentation. For block literals that's awkward at
> best if the machine did not create the text.
>
> So take either or both approaches.
>
> 1. Length header (number of lines, or number of chars, computed
> elsehwere, e.g. JavaScript)
> 2. User-specified termination sequence (alone on a final line, or
> anywhere in text?)
>
>
> Why? I'm doing a form. An input textarea box will accept rather
> arbitrary code and chars, etc. All I can guarantee is UTF8. But
> there's no way to fit YAML block literal requirements (that I know
> about). I need to preserve user input exactly, esp. code from many
> different languages.
>
> Cheap example: 4-line input with empty last line. Indentation is off
> for all but first line, assuming my JavaScript inserted a space up
> front.
>
> ---
> stringskey: |1+
> My very long user input form here,
> with arbitrary code and weird characters
> that would cause YAML to glitch.
>
> ...
>
>
> Instead we'd do this,
>
> ---
> stringskey: lines(4)|+
> My very long user input form here,
> with arbitrary code and weird characters
> that would cause YAML to glitch.
>
> ...
>
>
> Or this,
>
> ---
> stringskey: term("abcdefghijklmnop")|+
> My very long user input form here,
> with arbitrary code and weird characters
> that would cause YAML to glitch.
>
> abcdefghijklmnop
> ...
>
> --
>
> davecode-Nbr/[email protected]
>
> --
> http://www.fastmail.fm - And now for something completely different…
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> Yaml-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/yaml-core
>
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core