showdown icon indicating copy to clipboard operation
showdown copied to clipboard

Unable to use quoted values with colon in metadata

Open benc-uk opened this issue 6 years ago • 6 comments

I want to wrap a value in my metadata with quotes so it can contain a colon, e.g.

---
name: "foo: bar"
---

However this is not parsed correctly, what I get back from a call to getMetadata() is quite bizarre image

Trying to use HTML entities : in place of the colon only makes things worse image

benc-uk avatar Mar 30 '18 10:03 benc-uk

I've solved this by manually parsing with jsyaml and calling getMetadata(true) but would be good if showdown could return correctly parsed data back

benc-uk avatar Mar 30 '18 15:03 benc-uk

I will have to look into this carefully, since the metadata module is a very simplified version of yml.

tivie avatar May 07 '18 15:05 tivie

I confirm this issue and would like to get it fixed as well.

AramZS avatar Aug 02 '20 21:08 AramZS

same

qualityshepherd avatar Nov 26 '20 20:11 qualityshepherd

any updates?

Ibadichan avatar Sep 24 '23 07:09 Ibadichan

It looks like the regex used to parse metadata is greedily matching to the last colon when a non-greedy match should be used instead:

https://github.com/showdownjs/showdown/blob/95255984ad80acf745ed74605bd3ad8357dc9b33/src/subParsers/makehtml/metadata.js#L31

/^([\S ]+): +([\s\S]+?)$/gm.exec('title: Lorem: ipsum')

produces:

[
  'title: Lorem: ipsum',
  'title: Lorem',
  'ipsum',
  ...
]

Whereas

/^([\S ]+?): +([\s\S]+?)$/gm.exec('title: Lorem: ipsum')
//       ^

produces:

[
  'title: Lorem: ipsum',
  'title',
  'Lorem: ipsum',
  ...
]

zzzzBov avatar Apr 01 '24 03:04 zzzzBov