Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapsible Note custom editor component from the documentation not working #13

Open
nab-os opened this issue Dec 18, 2021 · 2 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@nab-os
Copy link

nab-os commented Dec 18, 2021

Describe the bug
I am trying to use Custom Editor Components and I cant get the markdown widget to behave properly
Just using the Collapsible Note example from the documentation results in an "undefined" displayed in the "details" part of the component.

To Reproduce

  1. Add the Collapsible Note example to your cms.js:
CMS.registerEditorComponent({
  // Internal id of the component
  id: "collapsible-note",
  // Visible label
  label: "Collapsible Note",
  // Fields the user need to fill out when adding an instance of the component
  fields: [
    {
      name: 'summary',
      label: 'Summary',
      widget: 'string'
    },
    {
      name: 'details',
      label: 'Details',
      widget: 'markdown'
    }
  ],
  // Regex pattern used to search for instances of this block in the markdown document.
  // Patterns are run in a multline environment (against the entire markdown document),
  // and so generally should make use of the multiline flag (`m`). If you need to capture
  // newlines in your capturing groups, you can either use something like
  // `([\S\s]*)`, or you can additionally enable the "dot all" flag (`s`),
  // which will cause `(.*)` to match newlines as well.
  //
  // Additionally, it's recommended that you use non-greedy capturing groups (e.g.
  // `(.*?)` vs `(.*)`), especially if matching against newline characters.
  pattern: /^<details>$\s*?<summary>(.*?)<\/summary>\n\n(.*?)\n^<\/details>$/ms,
  // Given a RegExp Match object
  // (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#return_value),
  // return an object with one property for each field defined in `fields`.
  //
  // This is used to populate the custom widget in the markdown editor in the CMS.
  fromBlock: function(match) {
    return {
      summary: match[1],
      detail: match[2]
    };
  },
  // Given an object with one property for each field defined in `fields`,
  // return the string you wish to be inserted into your markdown.
  //
  // This is used to serialize the data from the custom widget to the
  // markdown document
  toBlock: function(data) {
    return `
<details>
  <summary>${data.summary}</summary>

  ${data.detail}

</details>
`;
  },
  // Preview output for this component. Can either be a string or a React component
  // (component gives better render performance)
  toPreview: function(data) {
    return `
<details>
  <summary>${data.summary}</summary>

  ${data.detail}

</details>
`;
  }
});
  1. Going to your markdown editor and adding a Collapsible Note component
  2. Putting text in it
  3. Observing the "undefined" text on the preview

Expected behavior
Having a preview that displays the text in the "details" area

Screenshots
image

Applicable Versions:

  • netlify-cms-app 2.15.61
  • netlify-cms-core 2.54.2
  • OS: Fedora 35
  • Browser version: Firefox 95.0
  • Node.JS version: v12
@leo-petrucci
Copy link

leo-petrucci commented Dec 20, 2021

I stumbled across this as well.

    {
      name: 'details',
      label: 'Details',
      widget: 'markdown'
    }

This should be changed to detail, to fit with the other variables. I spent an embarrassing amount of time troubleshooting this.

@alianza
Copy link

alianza commented May 27, 2023

Still, preview in the editor doesn't work for markdown content in the details of the collapsible note custom editor component from the docs

@martinjagodic martinjagodic transferred this issue from decaporg/decap-cms Feb 2, 2024
@privatemaker privatemaker added bug Something isn't working documentation Improvements or additions to documentation labels Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants