There is 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-bb2a1453-9000-4440-a5f6-0e9ebfdb5e81 XWIKI-24539 Open

Paged.js named strings are serialized with unmatched quotes in PDF Export (string-set content(text))

 
View issue   ยท   Add comment
 

1 comment

 
cid:jira-generated-image-avatar-f36540ae-4ada-48fe-8d55-488a4b7b04d0 James Wartell on 13/Aug/26 17:51
 
Adding this as a javascript extension on a template works as a workaround:


{code:java}
require(['xwiki-page-ready'], function(pageReady) {
  if (window.XWiki?.contextaction === 'export') {    

// ===== BEGIN PagedJS string-set quote patch =====
    // Workaround for Paged.js 0.4.3 bug where string-set variables are emitted like:
    //   --pagedjs-string-first-section-name: "Definitions;
    // instead of:
    //   --pagedjs-string-first-section-name: "Definitions";
    //
    // Do not directly require(['paged-polyfill']) here. XWiki.PDFExport.Sheet controls when
    // PagedJS is loaded. This wrapper only intercepts that later load.
    try {
      require.config({
        map: {
          '*': {
            'paged-polyfill': ' garney -paged-polyfill-patched'
          },
          ' garney -paged-polyfill-patched': {
            'paged-polyfill': 'paged-polyfill-patched'
          }
        }
      });      

define(' garney -paged-polyfill-patched', ['paged-polyfill'], function(PagedPolyfill) {
        if (!window. __garneyPagedStringSetPatchRegistered __PagedStringSetPatchRegistered ) {
          window. __garneyPagedStringSetPatchRegistered __PagedStringSetPatchRegistered = true;          

class FixStringSetQuotes extends Paged.Handler {
            afterPageLayout(pageFragment) {
              console.log(
                'afterPageLayout',
                pageFragment.id
              );
              const style = pageFragment.style;              

// Copy property names first because CSSStyleDeclaration is live.
              const properties = [];
              for (let i = 0; i < style.length; i++) {
                properties.push(style[i]);
              }              

properties.forEach(function(property) {
                if (!property.startsWith('--pagedjs-string-')) {
                  return;
                }                

const value = style.getPropertyValue(property).trim();                

const quoteCount = (value.match(/"/g) || []).length;                

if (value.startsWith('"') && quoteCount % 2 === 1) {
                  const fixed = value + '"';
                  style.setProperty(property, fixed);
                  console.log('Fixed PagedJS string-set variable:', property, value, '=>', fixed);
                }              

});              
           
              
}  

          }          
          Paged.registerHandlers(FixStringSetQuotes);
          console.log('PagedJS string-set quote patch registered.');
        }

        return PagedPolyfill;
      });
    } catch (e)
{
      console.log(e);
    }
    // ===== END PagedJS string-set quote patch =====
  }
});
{
code}