Coder Social home page Coder Social logo

Comments (3)

dougalcampbell avatar dougalcampbell commented on June 12, 2024

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.

dougalcampbell avatar dougalcampbell commented on June 12, 2024

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.

dougalcampbell@36223d5

from plates.

dougalcampbell avatar dougalcampbell commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.