Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riot.compile() troubles parsing HTML files #1116

Closed
nippur72 opened this issue Aug 9, 2015 · 6 comments
Closed

riot.compile() troubles parsing HTML files #1116

nippur72 opened this issue Aug 9, 2015 · 6 comments

Comments

@nippur72
Copy link
Contributor

nippur72 commented Aug 9, 2015

Working with the compiler, I noticed that it often fails to parse HTML correctly.

See for example this JsFiddle:

<my-tag>   
   <div>
      <child-tag data={data}></child-tag> 
   </div>    
</my-tag>

compiles into:

riot.tag('my-tag', '<div>', function(opts) {
     <child-tag data={data}></child-tag> 
  </div>    

});

Is this an expected beaviour? The docs say tags have to be indented (and they are) and tag definition must start at beginning of line (and it does). Also there are no tabs, just spaces and newlines.

@GianlucaGuarini
Copy link
Member

Riot is indentation sensitive, it seems your html string is not correctly indented, this is the correct one http://jsfiddle.net/jc2ywhfv/2/

@nippur72
Copy link
Contributor Author

nippur72 commented Aug 9, 2015

do you mean indented exactly by just two spaces? It seems a rather restrictive requirement.

At least I suggest to state it clearly in the docs, not everybody use this indentation rule on HTML.

@GianlucaGuarini
Copy link
Member

I mean that this:

<my-tag>   <!-- tralling spaces -->
   <div>
      <child-tag data={data}></child-tag> <!-- tralling spaces -->
   </div>    <!-- tralling spaces -->
</my-tag>

is not a valid riot markup, maybe @aMarCruz could fix this issue in the new upcoming compiler with riot 2.3.0

@GianlucaGuarini GianlucaGuarini added this to the 2.3.0 milestone Aug 9, 2015
@aMarCruz
Copy link
Contributor

Will be fixed in 2.3.0

@aMarCruz aMarCruz self-assigned this Aug 11, 2015
@GianlucaGuarini GianlucaGuarini modified the milestones: 2.3.1, 2.3.0 Nov 5, 2015
@aMarCruz
Copy link
Contributor

Ok, this was (partially) fixed in 2.3.0, but we have two different behaviors and one bug, depending on where the tag is defined.

Trailing comments and spaces inside custom tags are removed in both external .tag files and inlined tags.

Indentation is the problem. Beta versions of the compiler 2.3 worked with any indentation, but in the last phase this changed to support treeview-like constructions, such as in this file and now, again, zero indentation is a requirement.

Even more, in some parts of riot.compile I introduced a new bug: the inner unindent funcion (wich is fragile and limited, but functional) is not called for tags loaded by XHR (<script src="file" type="riot/tag">), so if the loaded tags does not start at column 0, the compiler can not find it.

Indentation inside the opening and closing html tags (internal) is irrelevant, except for the closing tag (</my-tag>). The compiler assume the first closing tag starting at column 0 is the desired closing tag.

Right now I'm reviewing the code of these routines. I will send a fix for riot.compile soon, and in the coming days I will try to solve the inconsistencies once and for all.

@GianlucaGuarini
Copy link
Member

this issue was fixed http://jsfiddle.net/x9sakras/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants