Skip to content

TemplateMark dingus preview is blank: browser bundle pulls browser-unsafe markdown-pdf code #655

@stevenobiajulu

Description

@stevenobiajulu

Summary

The live TemplateMark dingus is currently broken:

https://templatemark-dingus.netlify.app/

The right-hand preview pane stays blank. I found two issues in the historical v0.16.2 dingus build, one of which appears to be the main cause.

Main issue

The dingus imports ToPdfMake from the @accordproject/markdown-pdf package root:

https://github.com/accordproject/markdown-transform/blob/v0.16.2/packages/dingus/lib/index.js#L12

const ToPdfMake = require('@accordproject/markdown-pdf').ToPdfMake;

But the package root eagerly exports both PdfTransformer and ToPdfMake:

https://github.com/accordproject/markdown-transform/blob/v0.16.2/packages/markdown-pdf/index.js#L22-L23

module.exports.PdfTransformer = require('./lib/PdfTransformer');
module.exports.ToPdfMake = require('./lib/ToPdfMake');

That pulls in browser-unsafe PDF parsing code. In particular:

https://github.com/accordproject/markdown-transform/blob/v0.16.2/packages/markdown-pdf/src/ToCiceroMark.js#L17-L20

require('./domstubs.js').setStubs(global);
let pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js');

and then:

https://github.com/accordproject/markdown-transform/blob/v0.16.2/packages/markdown-pdf/src/domstubs.js#L267-L270

exports.setStubs = function (namespace) {
  exported_symbols.forEach(function (key) {
    console.assert(!(key in namespace), "property should not be set: " + key);
    namespace[key] = exports[key];
  });
};

In the browser bundle, global resolves to window, so this tries to assign window.document and crashes startup.

Console errors include:

  • Assertion failed: property should not be set: document
  • Uncaught TypeError: Cannot set property document of #<Window> which has only a getter

That appears to abort initialization before the initial preview render runs.

Secondary issue

The dingus template also hard-codes this script:

https://github.com/accordproject/markdown-transform/blob/v0.16.2/packages/dingus/lib/index.pug#L19

script(src='https://twemoji.maxcdn.com/twemoji.min.js')

That URL currently returns invalid content, causing:

  • Uncaught SyntaxError: Unexpected identifier 'World'

The Twemoji usage is here:

https://github.com/accordproject/markdown-transform/blob/v0.16.2/packages/dingus/lib/index.js#L178-L180

Expected behavior

The default sample input should render in the preview pane.

Actual behavior

The preview pane is blank.

Suggested fix

The main fix seems to be avoiding the @accordproject/markdown-pdf root import in the browser dingus bundle, or changing the package root so importing ToPdfMake does not also require PdfTransformer.

The Twemoji URL should also be updated or removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions