Convert YAML to HTML?

Rubies:

This has to have been on the YAML thought leader's Do List.

Is there a library, or a snippet, out there that converts YAML to esthetic,
meaningful XHTML?

I don't want to load the document into Ruby variables then stream them with
RedCloth because I'd lose the comments.

Can I load the comments, too, and stream everything?

···

--
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces

Phlip wrote:

This has to have been on the YAML thought leader's Do List.

Is there a library, or a snippet, out there that converts YAML to

esthetic,

meaningful XHTML?

I don't want to load the document into Ruby variables then stream them

with

RedCloth because I'd lose the comments.

Can I load the comments, too, and stream everything?

Here's JB's Syntax module:

http://jamisbuck.org/jamis/blog.cgi/programming/ruby/Syntax%200.7_20050323235420.tx

Here's a sample output:

<span class="punct">-</span> [ formatWiki, this is ''em''phatic text, this
is &lt;em&gt;em&lt;/em&gt;phatic text ]

That's not cute enough. It's essentially a syntax highlighter for YAML. (And
as such, it missed the tags and lexically significant commas , .)

I need <table> output with cute <tr><td> tags around the arrays. To use
Ruby's magical extensiveness on Jamis Buck's Syntax::Convertors::HTML class,
I would also need the lexer to parse and , properly.

I might just spark up a TDD session and see how far I get with app-specific
code...

···

--
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces

Yes, it is not a complete YAML parser. A patch would be more than welcome, though. If you (or anyone else) improves an existing lexer or adds a new one, I would love to add your changes to the Syntax lib.

- Jamis

···

On Mar 26, 2005, at 10:14 AM, Phlip wrote:

Phlip wrote:

This has to have been on the YAML thought leader's Do List.

Is there a library, or a snippet, out there that converts YAML to

esthetic,

meaningful XHTML?

I don't want to load the document into Ruby variables then stream them

with

RedCloth because I'd lose the comments.

Can I load the comments, too, and stream everything?

Here's JB's Syntax module:

http://jamisbuck.org/jamis/blog.cgi/programming/ruby/Syntax%200.7_20050323235420.tx

Here's a sample output:

<span class="punct">-</span> [ formatWiki, this is ''em''phatic text, this
is &lt;em&gt;em&lt;/em&gt;phatic text ]

That's not cute enough. It's essentially a syntax highlighter for YAML. (And
as such, it missed the tags and lexically significant commas , .)

Jamis Buck wrote:

Yes, it is not a complete YAML parser. A patch would be more than
welcome, though.

Puh-lease. Patches are so Last Millenium.

We shall do this via the most obnoxious implementation technique yet
discovered: Pair Programming Via USENET.

Here:

  def test_list_of_lists
    tok =
    @yaml.tokenize( "- [ foo ]" ) { |t| tok << t }
    assert_equal [ :punct, "-" ], [ tok.first.group, tok.shift ]
    assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
    assert_equal [ :punct, "[" ], [ tok.first.group, tok.shift ]
    assert_equal [ :normal, " foo " ], [ tok.first.group, tok.shift ]
    assert_equal [ :punct, "]" ], [ tok.first.group, tok.shift ]
  end

I got each assertion working except the last, by adding this:

  class YAML < Tokenizer
....
          when scan(/:\w+/)
            start_group :symbol, matched

          when scan(/(\s*)\[/)
            start_group :normal, subgroup(1)
            start_group :punct, "["
....

However, now I can't find where to get the closing ] out of the :normal
string " foo ]".

After we do that, we need , working, and we need [ at BOL, without the -.

···

--
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces

[snip]

Thanks for the start on this, Philip. After taking what you did here and working a bit more on it, I'm beginning to think what really needs to happen is to rework the YAML lexer so that it uses a simple state machine. That would give much more granular output. Also, where I've been returning :normal (for "foo" in "bar: foo", for example), it should probably be :string.

We could continue with the existing lexer, but I fear it will rapidly become a case of plugging leaks and adding patch after patch...

I'll try to work on this some this afternoon, so the YAML lexer will be a lot more robust.

- Jamis

···

On Mar 26, 2005, at 12:39 PM, Phlip wrote:

Jamis Buck wrote:

Yes, it is not a complete YAML parser. A patch would be more than
welcome, though.

Puh-lease. Patches are so Last Millenium.

We shall do this via the most obnoxious implementation technique yet
discovered: Pair Programming Via USENET.

Here: