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

Add an option to allow the char " in the value of some fields in the template #25

Open
LaurentOngaro opened this issue Sep 6, 2024 · 3 comments

Comments

@LaurentOngaro
Copy link

Could you add add an option to allow " in the value of some fields in the template.

This should be very useful for the "title" field in the frontmatter, because without it, the special chars (ex: '|' or '/'...) in title could produce an error when linting the markdown file.

For example, the following frontmatter template

{
 title: "file.basename",
}

could produce the following code:

---
title: "Overview | Odin Programming Language"
---

and introduce no error when linting the file with a markdown checker

Copy link

linear bot commented Sep 6, 2024

@LaurentOngaro
Copy link
Author

LaurentOngaro commented Sep 6, 2024

I've tested the following template:

{
 title: ( (titleStr) => {
  return " " + titleStr + " "
 })(file.basename)
}

and the result is:

---
title: " _README "
---

so the " are kept. Nice ! But there are extras spaces

if I change my template to :

{
 title: ( (titleStr) => {
  return "" + titleStr + ""
 })(file.basename)
}

the result is:

---
title: _README
---

The spaces are not present (of course !) BUT the " are also removed !

@LaurentOngaro
Copy link
Author

LaurentOngaro commented Sep 6, 2024

After investigating, it seems that the " are removed by some obscur javascript process that I could not identify in your code.

But , I've found an "ugly" work arround for my need:

in the main.js file of your plugin (once compiled and installed), I've replace the line #22856 (NOTE : This line corresponds to the line #89 of the src/utils/getNewTextFromFile.ts of your source repo)

return newText;

by the followings:

  var newText2 = newText.replaceAll('""', '"');
  newText2 = newText2.replaceAll('""', '"');
  //console.log("DEBUG newText2:", newText2);
  return newText2;

And I've also change my template to:

{
 title: ( (titleStr) => {
  return '"' + titleStr + '"'
 })(file.basename)
}

and now, the value of the title field is surrounded by " in the frontmatter !

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

1 participant