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

Add prop for custom text rendering #163

Merged
merged 4 commits into from
Mar 8, 2018

Conversation

juliakieserman
Copy link
Contributor

@juliakieserman juliakieserman commented Feb 28, 2018

Added optional prop customTextRenderer that allows user to pass in a function that will modify how text div is rendered within text layer. Possible use case includes the ability to highlight words.

(potentially addresses #160 as well)

@juliakieserman
Copy link
Contributor Author

hey @wojtekmaj! just want to add a little more context here - essentially I have implemented a search function (using js-worker-search) and want to use this added code as a way to indicate to the renderer which text items should be highlighted to indicate they match. So essentially I would implement a function to pass to customTextRenderer that would pass an element that has a <mark> wrapped around the text if it came back as a match. There are a lot of different possible ways to use this (crossed out text, bold text, etc.), as I tried to keep it as general as possible, but this is the use case I'm planning on using it for.

@wojtekmaj
Copy link
Owner

Thanks for all the information! I'm busy at the moment, but quickly approaching the moment in which I'll be able to focus on open source stuff :) I'll review it today!

@wojtekmaj
Copy link
Owner

Sweet! Thank you :)

@wojtekmaj wojtekmaj merged commit 4381638 into wojtekmaj:master Mar 8, 2018
@wojtekmaj
Copy link
Owner

Played with it a little bit... This is really super cool 😀

@juliakieserman
Copy link
Contributor Author

awesome! glad you like it :). Very cool library.

@wojtekmaj wojtekmaj added the enhancement New feature or request label Mar 15, 2018
@juliakieserman
Copy link
Contributor Author

hey @wojtekmaj when do you expect to next release?

@wojtekmaj
Copy link
Owner

wojtekmaj commented Mar 17, 2018

@juliakieserman, I'm preparing to release v3.0.0 sometime this month. The first feature complete beta was just released. I'm monitoring the opinions in #143 and if nothing super horrible appears after a short while of beta program, I think we'll be ready to go :)

@juliakieserman
Copy link
Contributor Author

got it, thanks! also @wojtekmaj - it looks like you made some changes that removed the index being passed back along with the text layer props...would you mind putting that back in? This allows a custom renderer function to do a check on an index in the text layer to decide what to do with it.

@wojtekmaj
Copy link
Owner

Missed that during refactoring. Adding the fix + tests to prevent that in the future right away.

@wojtekmaj
Copy link
Owner

3.0.1 is out! Sorry!

@juliakieserman
Copy link
Contributor Author

thanks for the quick response! looks like itemIndex is still coming back as undefined though...

@juliakieserman
Copy link
Contributor Author

ah - nevermind, I see you grouped it with the rest of the content. Thanks!

@juliakieserman
Copy link
Contributor Author

hey @wojtekmaj - sorry to keep bugging you with this, but I'm starting to wonder if passing back a page index would also be super helpful. That way you could say things like "for page 4, I want to edit the 8th index in the text content". Any chance we could throw that in there?

@wojtekmaj
Copy link
Owner

There will be no passing back like this for sure as this breaks the nice flow React makes. But!

<Document file={...} >
  <Page
    pageNumber={pageNumber}
    customTextRenderer={({ str, itemIndex }) =>
      (
        pageIndex === 4 && itemIndex === 8
          ? 'I am 8th string on page 4'
          : str
        )
      }
  />
</Document>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants