'pandoc exited with code 64' Solution

After I upgraded pandoc from 2.14.0.3 to 2.18, hexo-renderer-pandoc cannot render one of my post correctly. Everything works fine in 2.14.0.3. The error looks like:

INFO Start processing FATAL { err: Error: [ERROR][hexo-renderer-pandoc] On /home/finisky/source/_posts/test.md [ERROR][hexo-renderer-pandoc] pandoc exited with code 64: YAML parse exception at line 4, column 0, while scanning a simple key: could not find expected ':'

  at Hexo.pandocRenderer (/home/finisky/node_modules/hexo-renderer-pandoc/index.js:114:11)
  at Hexo.tryCatcher (/home/finisky/node_modules/bluebird/js/release/util.js:16:23)
  at Hexo.<anonymous> (/home/finisky/node_modules/bluebird/js/release/method.js:15:34)
  at /home/finisky/node_modules/hexo/lib/hexo/render.js:75:22
  at tryCatcher (/home/finisky/node_modules/bluebird/js/release/util.js:16:23)
  at Promise._settlePromiseFromHandler (/home/finisky/node_modules/bluebird/js/release/promise.js:547:31)
  at Promise._settlePromise (/home/finisky/node_modules/bluebird/js/release/promise.js:604:18)
  at Promise._settlePromiseCtx (/home/finisky/node_modules/bluebird/js/release/promise.js:641:10)
  at _drainQueueStep (/home/finisky/node_modules/bluebird/js/release/async.js:97:12)
  at _drainQueue (/home/finisky/node_modules/bluebird/js/release/async.js:86:9)
  at Async._drainQueues (/home/finisky/node_modules/bluebird/js/release/async.js:102:5)
  at Immediate.Async.drainQueues [as _onImmediate] (/home/finisky/node_modules/bluebird/js/release/async.js:15:14)
  at processImmediate (node:internal/timers:464:21)

} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

Reproduce and Debug

I use binary search to find which lines has bug.

Then I construct a minimum version a.md to reproduce the issue (I want to insert two separator lines before and after the code block):

begin.

---
first:
```
test
```

---

end

Run pandoc:

$ pandoc -f markdown -t html a.md
YAML parse exception at line 2, column 0,
while scanning for the next token:
found character that cannot start any token

Seems that the issue is around line 3~5: ---, : and triple backtick cannot be appeared at the same time.

There are several ways to bypass the issue:

  • Add a blank line after ---:
---

first:
```
  • Remove or replace the :
---
first.
```
  • Remove the trailing ---
begin.

---
first:
```
test
```

end

Root Cause

Refer to this github issue I submitted:

---
```
first:
```
test
```
```

The above is not a valid yaml. It's a markdown, why we talk about yaml?

Because the parser regards it as an inline yaml meta block.

Refer to PANDOC MANUAL:

A YAML metadata block is a valid YAML object, delimited by a line of three hyphens (---) at the top and a line of three hyphens (---) or three dots (...) at the bottom. A YAML metadata block may occur anywhere in the document, but if it is not at the beginning, it must be preceded by a blank line.

Solution

Solution: To avoid ambiguity, adding a blank line before and after --- if you want a separator line.

The interesting point is that both StackEdit and DILLINGER parse the markdown correctly as well as pandoc 2.14.

I use StackEdit to write posts and pandoc to generate Hexo posts. StackEdit and DILLNGER try their best to optimize the user experience but the gap hides the imprecise grammar. Actually, pandoc is the most strict parser I met as this is not the first time I encountered such grammar issue. The best solution is to use rigorous grammar as pandoc. :-)