jgm/djot.js

Djot CLI: Can not convert stand-alone documents via Pandoc

tbdalgaard opened this issue · 12 comments

If one tries to convert from docx or a stand-alone HTML-document via Pandoc to Djot it will not work at the moment. I presume that Djot can't handle the metadata blocks at the top of the HTML-files or those blocks stored somewhere in the docx container.

The interesting thing here is that Pandoc gladly converts from Djot to stand-alone HTML, but not the other way around.

jgm commented

When you say it "does not work," what do you mean?
This gives me a djot document as output:

pandoc MANUAL.txt -t json -s | djot -f pandoc -t djot

Are you doing something different from that?
The document won't contain metadata, because djot has no metadata yet.

jgm commented

This gave some interesting errors.

It's more helpful if you actually give the errors. I tried it and in this case it's

Error: TypeError: Cannot read properties of undefined (reading 'DefaultDelim')
TypeError: Cannot read properties of undefined (reading 'DefaultDelim')
    at PandocParser.fromPandocBlock (/opt/homebrew/lib/node_modules/@djot/djot/lib/pandoc.js:732:54)
    at /opt/homebrew/lib/node_modules/@djot/djot/lib/pandoc.js:605:33
    at Array.map (<anonymous>)
    at PandocParser.fromPandocBlock (/opt/homebrew/lib/node_modules/@djot/djot/lib/pandoc.js:604:43)
    at /opt/homebrew/lib/node_modules/@djot/djot/lib/pandoc.js:850:25
    at Array.map (<anonymous>)
    at PandocParser.fromPandoc (/opt/homebrew/lib/node_modules/@djot/djot/lib/pandoc.js:849:34)
    at fromPandoc (/opt/homebrew/lib/node_modules/@djot/djot/lib/pandoc.js:863:38)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/@djot/djot/lib/cli.js:175:43)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)% 

Is that what you saw? That points to a bug in djot's pandoc conversion, which should be rather easy to fix.

I had no trouble converting from docx, but if you did stumble across an error, please report it with full details and ideally a minimal docx we can use to reproduce it.

None of this has to do with metadata, I think.

jgm commented

I suspect the fix I just pushed will take care of this issue, but it's hard to tell unless you can give us a file that suffices to reproduce it.

If you have a git clone of this repository you can try

$ git pull
$ npm install -g .

and see if that helps.

jgm commented

A Danish version would be just fine.

jgm commented

This converted without errors using

pandoc ~/Downloads/vers1.html -t json -s | djot -f pandoc -t djot

If it doesn't work for you, then probably you aren't running the development version of djot.

jgm commented

I'm guessing you have a <section> with an id, and the first element of the section is a heading like <h2> with an id. Both are given here, but the second will take precedence. Sections are implicit in djot.