Git Product home page Git Product logo

Comments (3)

jonnygreenwald avatar jonnygreenwald commented on June 11, 2024 1

Okay, PR #16 is up, which will hopefully fix this issue. Let me know if you see any problem with what I've outlined in the request / caveats above. If not, I'll review and merge it.

from fountain-js.

jonnygreenwald avatar jonnygreenwald commented on June 11, 2024

(deleted my earlier comment because I understood what the issue was, sorry for any confusion) 🤦‍♀️

It's the this.inlineLex.reconstruct()method within to_html that's mutating the shallow copy of the token objects. You're right that a deep copy is the way to go and I can fix this with a JSON round-trip; however, it presents some issues that I do want to make you aware of.

I assume you're using the parse method to only retrieve the tokens and then are manipulating the tokens to render it into something else other than HTML, thus why having HTML embedded in the token text like <br /> is causing you issues. But I'm making some big assumptions here, so please correct me if I'm wrong.

The inlineLex.reconstruct() method doesn't just work on newlines but is the inline lexer for all inline objects e.g. emphasis, underlines, etc. So what that means is that if I make this change, is that you'll have to perform your own inline lexing to convert these to whatever you want.

For example, given the action:

Murtaugh, springing hell bent for leather -- and folks, 
grab your hats … because just then, a _BELL COBRA 
HELICOPTER_ crests the edge of the bluff.

Where you want the helicopter name to be underlined, will yield the token:

[
  ActionToken {
    type: 'action',
    text: 'Murtaugh, springing hell bent for leather -- and folks, \n' +
      'grab your hats … because just then, a _BELL COBRA \n' +
      'HELICOPTER_ crests the edge of the bluff.'
  }
]

^^ e.g. the underline markup is still unchanged since inlineLex.reconstruct() didn't mutate the text on the token. Also take note that this doesn't just happen in action but all tokens.

So, you'll probably have to run a version of your own inline lexer to solve this issue. I suggest using the code from the InlineLexer class and just replace the html with whatever you want like <underline>$2</underline> or whatever, but if you want something more complicated than strings like DOM or something then perhaps this won't work 🤔...

Anyway, thoughts are welcomed here. If this isn't an issue, I can push a fix for this.

from fountain-js.

cantrell avatar cantrell commented on June 11, 2024

Thanks for the additional context — and, of course, for the quick turnaround. I will update and test!

from fountain-js.

Related Issues (8)

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.