Comments (3)
Okay, I've tinkered with this off and on, and tracked down the source of the problem.
At the beginning of the iterate()
method, plates uses a naive way of balancing out the tags for the current block being mapped to a data object. It uses String.lastIndexOf()
without regard to whether unrelated html might exist at the end of the current segment.
When there is additional template text after where the current block should end (a common use-case -- think about footers after a data block), and the tagnames between the current block and the appended block match, this will grab too much text. For example. consider this template:
<div id='article'>
<div class='byline'></div>
<div class='content'></div>
</div>
<div id='footer'></div>
I've created a new gist (simpler than my previous one) to illustrate: https://gist.github.com/2595351
If plates was handling things as a DOM (even just a simplified one), it would be easier to handle. You could just count elements on the stack. But since it's doing pseudo-stream state-machine parsing, it's tricker to look ahead. I'm mulling it over to see if I can come up with a patch that's not too ugly.
from plates.
I've got a patch that seems to be working, though I haven't done extensive testing yet. One known flaw so far, is with dealing with html comments (or presumably other content) at the end of a sub-block being processed.
from plates.
Okay, my latest fix seems to work pretty well. The only niggle I have is that it doesn't perfectly preserve whitespace after processing a sub-object block for some reason. But none of the other test cases worry about whitespace, so I guess I won't either.
from plates.
Related Issues (20)
- Multiple clauses does not render correctly HOT 2
- Option to allow/disallow undefined attributes HOT 1
- Better common.js support HOT 1
- Provide a proper way to avoid XSS attacks
- Problem with function compileMappings, and how i (might have) fixed it.
- .append() or .partial doesn't work with inputs HOT 1
- Partials HOT 1
- Tests failing on latest Node.js HOT 1
- State of this library HOT 3
- Overrides elements with bad content HOT 2
- Plates (fork?) with some DSL HOT 1
- Collection iteration HOT 1
- Binding doesn't work as expected HOT 1
- Question, not Issue: Getting the innerHTML of a tag for multi-language support
- Not able to get the correct HTML output
- BUG: "Template" may not contain "Subtemplates" tag name HOT 1
- Old Version on Bower HOT 1
- Example project with template nesting HOT 1
- Mapping the same partial multiple times with collections example
- Map to a valueless attribute
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plates.