gray-matter icon indicating copy to clipboard operation
gray-matter copied to clipboard

use opts.excerpt_separator

Open gcoda opened this issue 6 years ago • 3 comments

Trying to stringify with same options as parsed failed. Does this looks like a fix?

gcoda avatar Jan 12 '19 09:01 gcoda

Tests can pass with const sep = opts.excerpt_separator || opts.delimiters[0]; But it looks like it should be inside default.js

  if (opts.excerpt) {
    opts.excerpt_separator = opts.excerpt_separator || opts.delimiters[0];
  }

Then another one fails,

  .stringify
    1) should stringify an excerpt

So default.js: opts.sep = opts.excerpt_separator || opts.delimiters[0]; and stringify.js: const sep = opts.sep; seems even more wrong.

lib/excerpt.js: sep || opts.delimiters[0]

so maybe stringify.js should not use default separator too, i am really not sure

or test for stringify maybe should use {excerpt: true} ?

gcoda avatar Jan 12 '19 10:01 gcoda

I'm on vacation for the next few days but can you provide an example of what you did and what you expected to happen vs what did happen? Your fix suggestion seems to be a breaking change at a glance.

I'll respond properly at the end of the week.

robertmassaioli avatar Jan 12 '19 22:01 robertmassaioli

i am trying to stringify with custom excerpt_separator

var source = '---\nDATA: 1\n---\nEXCERPT\n<!-- -->\nBODY\n'
var options = { excerpt: true, excerpt_separator: '<!-- -->' }
var parsed = matter(source, options)

var file = {
  excerpt: parsed.excerpt,
  content: 'Something new',
  data: parsed.data,
}

var string = matter.stringify(file, {}, options)

i am confused why stringify uses opts.delimiters[1] as separator but lib/excerpt.js using opts.delimiters[0]

gcoda avatar Jan 13 '19 06:01 gcoda