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

beforeParse Issue : Modified content is not being reflected in preview. #169

Open
rohanrjohn opened this issue Oct 24, 2023 · 1 comment

Comments

@rohanrjohn
Copy link

rohanrjohn commented Oct 24, 2023

I am new to paged.js and I am having some blocking issues with an implementation.
Basically, I am using paged.js with prosemirror. I want to change content of the preview to add a TOC feature. I tried using beforeParsed hook but the content did not get changed. I tried using beforePreview hook also but it wasn't triggered (document did mention that issue, so maybe this won't work). I am sharing the code below for reference.

customHandler.ts:

import {Handler, registerHandlers} from 'pagedjs';
import createToc from './exportPdf';

export default class customHandler extends Handler {
  constructor(chunker, polisher, caller) {
    super(chunker, polisher, caller);
  }

  beforeParsed(content) {
    let abcd = 1;
   // Modify the content structure for the print preview
    const tocElement = createToc({
      content: content,
      tocElement: '.tocHead',
      titleElements: ['Chapter Header', 'Header 2'],
    });

   // Replace the content with the modified structure
    content = tocElement;
    return content;
}
}

In preview.tsx, I am registering the handlers:

  import {Previewer, registerHandlers} from 'pagedjs';
  import customHandler from './customHandler';

  componentDidMount(): void {
    const {editorView} = this.props;
    let divContainer = document.getElementById('holder');
    this.dataTrial = this.getContainer(editorView);
    let newDiv = document.createElement('div');
    newDiv.classList.add('tocHead');

    // 2. Get the dataTrial element
    let dataTrial = this.getContainer(editorView);

    dataTrial.insertBefore(newDiv, dataTrial.firstChild);

    registerHandlers(customHandler);

    let paged = new Previewer();
    paged
      .preview(dataTrial.outerHTML, [{cssPath: './ui/paged.css'}], divContainer)
      .then((flow) => {
        console.log('Rendered', flow.total, 'pages.');
      });
  }

Is there any issues with the code? Can anyone point me in the correct direction. Thanks!

@julientaq
Copy link
Collaborator

hi there.

i cleaned your issue to try and understand what you’re doing.

@fchasen will be able to answer you when he’s up.

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

No branches or pull requests

2 participants