Ruby在尝试解析Jekyll项目中的YAML(前置内容)时出现问题。

huangapple go评论69阅读模式
英文:

Ruby has problem with single file trying to parse YAML (frontmatter) from Jekyll project

问题

在大多数文件中,我成功地使用以下代码解析了前置元数据:

YAML.load_file(stringForFilePath, permitted_classes: ['Date'])

但在一个文件上,我收到了以下错误:

控制字符不允许在第1行第1列 (Psych::SyntaxError)

我尝试过以下方法:

  1. 将前置元数据/YAML 放入验证器中检查错误。
  2. 删除整个前置元数据,然后放入一个基本的存根。
  3. 检查文件编码(UTF-8,与其他正常工作的文件相同)。
  4. 检查行结束符(CLRF,与其他正常工作的文件相同)。
  5. 从文件中删除所有非ASCII字符(例如HTML,在前置元数据中没有)。
英文:

So I am successfully parsing frontmatter with

YAML.load_file(stringForFilePath, permitted_classes: ['Date'])

on a whole bunch of files except on a single file I get this error:

control characters are not allowed at line 1 column 1 (Psych::SyntaxError)

Things I have tried:

  1. Putting the frontmatter / YAML in a validator to check for errors
  2. Deleting the entire frontmatter and put in a basic stub in its place.
  3. Checked the file encoding (UTF-8 same as other files that are working)
  4. Checked the line endings (CLRF same as other files that are working)
  5. Removing every non-ASCII character from the file (e.g. the HTML, there was none in frontmatter)

答案1

得分: 0

问题出在我的HTML正文中有一个不可打印/不可见的控制字符,非常难以追踪。我尝试了一些第三方工具,它们没有检测到它,直到我更新了我的文本编辑器,我才终于能够找到它。

英文:

Problem was with a non-printing/invisible control character in my HTML body that was very hard to track down. Some 3rd party tools I tried didn't pick it up and it wasn't until I updated my text editor was I finally able to find it.

huangapple
  • 本文由 发表于 2023年6月8日 01:28:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定