Home
Support Forums

String fields have newlines added to Markdown metadata (front matter) which breaks Pelican

I am using Netlify CMS to manage content in a Pelican site. Pelican uses metadata at the top of markdown files for fields. When I allow users to add more than approx. 80 chars to a String field, Netlify CMS is adding a newline character to the content of the String field at about 80 chars in.

Pelican does not expect newlines in the metadata so it breaks and doesn’t generate the content.

I’ve added a character count limit using regexp pattern, but 80 chars is a lot fewer chars than I’d like for some fields. Can anyone help?

  - name: "news-articles" # Used in routes, ie.: /admin/collections/:slug/edit
label: "News & Articles" # Used in the UI, ie.: "New Post"
folder: "content/news-articles" # The path to the folder where the documents are stored
sort: "date:desc" # Default is title:asc
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
  - {label: "Title", name: "title", widget: "string", tagname: "h1", class: "entry-title"}
  - {label: "Image", name: "img_src", widget: "image"}
  - {label: "Image Alt Text", name: "img_alt", widget: string, hint: "Text shown to visually impaired users instead of image. 80 chars or less, no newlines", pattern: ["^[^\n\r].{3,80}$", "80 characters or less. No newlines."]}
  - {label: "Image Title", name: "img_title", widget: string, required: false, hint: "Title shows when mouse hovers on image", pattern: ["^[^\n\r].{3,80}$", "80 characters or less. No newlines."]}
  - {label: "Keywords", name: "keywords", widget: string, required: false, hint: "Separate keywords with commas, 80 chars or less, no newlines", pattern: ["^[^\n\r].{3,80}$", "80 characters or less. No newlines."]}
  - {label: "Summary", name: "summary", widget: string, required: true, hint: "Keep it short, 80 characters or less, no newlines", pattern: ["^[^\n\r].{3,80}$", "80 characters or less. No newlines."]}
  - {label: "Body", name: "body", widget: "markdown", class: "article-body"}
  - {label: "Publish Date", name: "date", widget: "datetime"}

Hi @Marcus_Clements and welcome to the community :slight_smile:

I’ve tried using the following config:

collections:
  - name: 'news-articles' # Used in routes, ie.: /admin/collections/:slug/edit
    label: 'News & Articles' # Used in the UI, ie.: "New Post"
    folder: 'content/news-articles' # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    fields: # The fields each document in this collection have
      - { label: 'Title', name: 'title', widget: 'string', class: 'entry-title' }

And was able to generate a file with a title of more than 80 chars with no line breaks.
This is the content of the file generated by the CMS:

---
title: testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
---

Can you make sure you’re using the latest version of the CMS?

If that doesn’t work can you please open an issue with a reproduction here:

Hi @erez,

I am having the same issue with Netlify CMS and Pelican but with the Markdown widget.

This is what I put under collections.

      - {label: "Intro text", name: "intro_text", widget: "markdown", required: false, class: 'entry-title'}

It worked when I used the long string you used in your example but when I write a paragraph of text it creates a markdown file with line breaks, which subsequently doesn’t work in Pelican. Hence, I think it has something to do with the number of spaces rather than the number of characters. I think this can be fixed by implementing a custom markdown reader in Pelican, but it would be nice if the output from the Netlify CMS worked with pelican automatically. Is there anything in the Netlify CMS configuration setting that can be used to remove the backspaces in the string returned by the widget?

Many thanks,

Jake

Hi @JakeCarbone, welcome to the community and sorry for the delayed response.

Can you open an issue with a reproduction on our repo?
That would make it easier to understand the issue you’re having.
I think it might be related to https://github.com/netlify/netlify-cms/issues/512 but I can’t be sure at the moment.

Hi @erez, I’m experiencing the same issue as OP and I’ve searched the forums, Slack, and elsewhere with no mention of this.

I would show my own config but I did replicate the problem with your own config, using the same string of 83 characters (including spaces):

Associate Partner, Banking & Capital Markets Insight Lead, Behaviour Science Expert

This is the output, which breaks my Hugo build. Note that this kinda looks like line wrapping but with line numbers showing, it’s on two separate lines:

---
title: Associate Partner, Banking & Capital Markets Insight Lead, Behaviour
  Science Expert
---

When I add a single space to your test string, I get the same result:

---
title: testtesttesttestt
  esttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
---

Possibly related, I noticed that none of my frontmatter values are wrapped in quotes, even though I have seen many others’ code snippets showing values wrapped in quotes.

Hi @TimTorres,

Thank you for sharing that, it makes sense now.
Looks like the default line width for the yaml library the CMS uses is 80.
It’s configurable (see Allow disabling automatic line wrapping. · Issue #58 · eemeli/yaml · GitHub). I would rather not change the default as it will impact existing content for other users.

I suggest opening a feature request to allow configuring it.

@erez Thanks! I never would’ve found that. Opened an issue here.

2 Likes