hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.19k stars 4.82k forks source link

When there is one "-----------------------" in document, it will occur "YAMLException" #4961

Closed longdafeng closed 2 years ago

longdafeng commented 2 years ago

Check List

Please check followings before submitting a new issue.

Promblem

I meet the problem "err: YAMLException: end of the stream or a document separator is expected"

I migration my markdown books from MkDocs to Hexo.

There is no Front-matter in my documents. There are more than 1000 markdown documents, so I can't add front-matter to every document.

If there is one ":" in my document, it will leading to this problem.

I found there are several template in the directory of scaffolds, "draft.md/page.md/post.md"

---
title: {{ title }}
tags: {{tags}}
categories: {{categories}}
​---

I want to :

  1. This error won't occur.
  2. I wish my markdown's file name will be the page's {{title}} and {{description}}

How to do?

^[[41mERROR^[[49m {
  err: YAMLException: end of the stream or a document separator is expected (4:77)

   1 |  ...
   2 |  ...
   3 |  ...
   4 |  ... r (ODC) consists of three parts:
  -----------------------------------------^
   5 |  ...
   6 |  ...
      at generateError (/Users/longda/work/longda/obcloud/obcloud/node_modules/js-yaml/lib/loader.js:183:10)
      at throwError (/Users/longda/work/longda/obcloud/obcloud/node_modules/js-yaml/lib/loader.js:187:9)
      at readDocument (/Users/longda/work/longda/obcloud/obcloud/node_modules/js-yaml/lib/loader.js:1645:5)
      at loadDocuments (/Users/longda/work/longda/obcloud/obcloud/node_modules/js-yaml/lib/loader.js:1688:5)
      at Object.load (/Users/longda/work/longda/obcloud/obcloud/node_modules/js-yaml/lib/loader.js:1714:19)
      at parseYAML (/Users/longda/work/longda/obcloud/obcloud/node_modules/hexo-front-matter/lib/front_matter.js:69:23)
      at parse (/Users/longda/work/longda/obcloud/obcloud/node_modules/hexo-front-matter/lib/front_matter.js:50:12)
      at /Users/longda/work/longda/obcloud/obcloud/node_modules/hexo/lib/plugins/processor/asset.js:55:18
      at tryCatcher (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:544:35)
      at Promise._settlePromise (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:673:18)
      at PromiseArray._resolve (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise_array.js:127:19)
      at PromiseArray._promiseFulfilled (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise_array.js:145:14)
      at PromiseArray._iterate (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise_array.js:115:31)
      at PromiseArray.init [as _init] (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise_array.js:79:10)
      at Promise._settlePromise (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:601:21)
      at Promise._settlePromise0 (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/longda/work/longda/obcloud/obcloud/node_modules/bluebird/js/release/promise.js:673:18) {
    reason: 'end of the stream or a document separator is expected',
    mark: {
      name: null,
      buffer: 'Architecture \n' +
        '=================================\n' +

Is the problem still there under "Safe mode"?

Safe mode works fine.

Environment & Settings

Node.js & npm version(node -v && npm -v)

node -v && npm -v
v14.15.5
8.1.4

hexo migrate --help
INFO  Validating config
INFO  ==================================
  ███╗   ██╗███████╗██╗  ██╗████████╗
  ████╗  ██║██╔════╝╚██╗██╔╝╚══██╔══╝
  ██╔██╗ ██║█████╗   ╚███╔╝    ██║
  ██║╚██╗██║██╔══╝   ██╔██╗    ██║
  ██║ ╚████║███████╗██╔╝ ██╗   ██║
  ╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝   ╚═╝
========================================
NexT version 8.11.0
Documentation: https://theme-next.js.org
========================================

package.json
{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server"
  },
  "hexo": {
    "version": "6.1.0"
  },
  "dependencies": {
    "hexo": "^6.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-feed": "^3.0.0",
    "hexo-generator-searchdb": "^1.4.0",
    "hexo-generator-sitemap": "^3.0.1",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-markdown-it": "^6.0.1",
    "hexo-renderer-stylus": "^2.0.0",
    "hexo-server": "^3.0.0",
    "hexo-theme-landscape": "^0.0.3",
    "hexo-theme-next": "^8.11.0",
    "markdown-it-checkbox": "^1.1.0",
    "markdown-it-expandable": "^1.0.2",
    "markdown-it-imsize": "^2.0.1"
  }
}
yoshinorin commented 2 years ago

@longdafeng

I assume your yaml file has extra space or tag. Please check them.

https://github.com/hexojs/hexo/issues/832#issuecomment-54764743

longdafeng commented 2 years ago

I don't think the problem is #832.

There is no Front-matter in my documents.

there are no section like this:

---
title: test
---

Some markdown documents are fine, but some occur probjem, which there are ":" in these document with problem.

@longdafeng

I assume your yaml file has extra space or tag. Please check them.

#832 (comment)

longdafeng commented 2 years ago

any help will be appreciated. @stevenjoezhang , do you have any idea to resolve it? Thanks in advance.

stevenjoezhang commented 2 years ago

You need to add a Front-matter section in the posts:

---
title: test
---

Otherwise ":" in the post content will be parsed as YAML Front-matter, causing syntax error

longdafeng commented 2 years ago

I want to migrate my markdown books from MkDocs to Hexo. There are more than 1000 markdown documents, this is an huge task for me (I can write a script do this task). what's more there are 2 document systems to display these documents, so I can't add "front-matter" to these documents.

In my oponion, there should be a method to skip render front-matter.

@stevenjoezhang, thanks in advance

longdafeng commented 2 years ago

Sorry for disturbing, @curbengh , @tommy351 , @SukkaW , @segayuu , @NoahDragon , may I ask how to resolve this problem? Any help are appreciated, thanks in advance.

longdafeng commented 2 years ago

@yoshinorin Do you have any ideas to resolve this problem, any help are appreciated.

yoshinorin commented 2 years ago

I don't know why your environment has a problem (YAMLException). Anyway, hexo 6.x.x can process a post without front-matter. I just tried it locally.

// create new hexo pj
$ hexo init issue4961
INFO  Validating config
INFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
INFO  Install dependencies

...

INFO  Start blogging with Hexo!

After creating a new project, I wrote a post without frontmatter.

// in _posts\test-no-front-matter.md

$ hexo new test-no-front-matter
INFO  Validating config
INFO  Created: ~\sandbox\issue4961\source\_posts\test-no-front-matter.md

And run hexo server I can see the content without Errors.

1

Also, hexo can generate HTML from it.

$ hexo g
INFO  Validating config
INFO  Start processing

....

INFO  Generated: 2022/05/12/test-no-front-matter/index.html
INFO  18 files generated in 357 ms

I assume you can use hexo API, if you want to add a title (or other metadata) to your posts without front-matter. I have been never tried to use them for update metadata, but may be effective.

https://hexo.io/api/generator#Generate-All-Posts https://hexo.io/api/#Execute-Commands

longdafeng commented 2 years ago

@yoshinorin Thanks

There is no : in your markdown, so it won't occur problem.

There is one or more colon in the document, at the same time, there is no front-matter, it will occur "YAMLException"

yoshinorin commented 2 years ago

This error does not happen only :. But, when I use --- with : the YAMLException sometimes happens.

I wrote some patterns below.

// OK (without ---)

This is a test for issue:4916
// Sometimes happens (not every time)

This is a test for issue:4916
---
// Sometimes happens (not every time)

This is a test for issue : 4916
---
// every time happen

---
This is a test for issue:4916
This is a test for issue : 4916
---
// OK

---
This is a test for issue:4916
---
// No-errors but nothing is rendered

---
This is a test for issue : 4916
---

Not sure but as far as I know, can not ignore parsing yaml.

IMHO, we will not implement ignore parsing yaml option, because this case (nothing front-matter) assumes a very rare case. But, we may implement it if we receive many requests from users.

Also, we may accept if someone submits PR about this.

longdafeng commented 2 years ago

@yoshinorin Today I debug my document, I found the root cause, what I found is the same as what you found.

The document doesn't allow '---'

For example:

Architecture 
=================================

The architecture of  Developer Center (ODC) consists of three parts:

* **[Basic features](#basic-features)**

* **[Core features](#core-features)**

* **[Advanced features](#advanced-features)**

Basic features 
-----------------------

* User Management: This feature provides services such as account creation, system logon, and password modification.

* Connection Management: This feature allows you to manage connections to  Database in MySQL and Oracle modes. You can create, save, copy, and delete database connections.

Event if there is one "-----------------------" between ``` and ``` , it will also exist problem

longdafeng commented 2 years ago

Due to "-----------------------" can be regcognize asone format of title in markdown,

For example

Title

so could we ignore "-----------------------", don't parse it as YAML.

longdafeng commented 2 years ago

@yoshinorin @stevenjoezhang @bkeepers @jjgod @NoahDragon @SukkaW

Do you have any idea about this issue, any help are appreciated.

longdafeng commented 2 years ago

I am disappointed at Hexo, one month past, no one give me an answer how to resolve it.

In my oponion, the label of this issue is wrong, it should be feature-request

longdafeng commented 2 years ago

close this issue, due to no one answer

stevenjoezhang commented 2 years ago

I have answered your question 2 months ago. I have no idea why you think no one give you an answer how to resolve it.