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

Unable to use quoted values with colon in metadata #511

Open
benc-uk opened this issue Mar 30, 2018 · 6 comments
Open

Unable to use quoted values with colon in metadata #511

benc-uk opened this issue Mar 30, 2018 · 6 comments
Assignees

Comments

@benc-uk
Copy link

benc-uk commented Mar 30, 2018

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 benc-uk changed the title Quoted values in metadata Unable to use quoted values with colon in metadata Mar 30, 2018
@benc-uk
Copy link
Author

benc-uk commented Mar 30, 2018

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

@tivie tivie self-assigned this May 7, 2018
@tivie
Copy link
Member

tivie commented May 7, 2018

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

@AramZS
Copy link

AramZS commented Aug 2, 2020

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

@qualityshepherd
Copy link

same

@Ibadichan
Copy link

any updates?

@zzzzBov
Copy link

zzzzBov commented Apr 1, 2024

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:

content.replace(/^([\S ]+): +([\s\S]+?)$/gm, function (wm, key, value) {

/^([\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',
  ...
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants