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

mdsf applies changes outside code snippet #138

Closed
ccoVeille opened this issue Apr 1, 2024 · 9 comments · Fixed by #142
Closed

mdsf applies changes outside code snippet #138

ccoVeille opened this issue Apr 1, 2024 · 9 comments · Fixed by #142
Assignees

Comments

@ccoVeille
Copy link
Contributor

ccoVeille commented Apr 1, 2024

I love your tool idea.

I can see you are actively working on it, so first of all, thank you !

Here are the kind of replacement I noticed

# title

Let's play!

Have some fun...

I like "mdsf"

| Field            | Description            |
|------------------|------------------------|
| foo              |   foo field            |
| bar              |   bar field            |

```shell
ls
```

will become

# title

Let’s play!

Have some fun…

I like “mdsf”

|Field|Description|
|-----|-----------|
|foo|foo field|
|bar|bar field|

```shell
ls
```

The table formatting is broken. It will render OK in markdown, but the text was altered.

You might not notice at first but it replaces:

  • ... (three consecutive dots) into U+2026 … HORIZONTAL ELLIPSIS
  • simple quote by U+2019 ’ RIGHT SINGLE QUOTATION MARK
  • double quoted text by text surrounded by:
    • U+201D ” RIGHT DOUBLE QUOTATION MARK
    • U+201C “ LEFT DOUBLE QUOTATION MARK

I would expect the code to only apply changes on the block quotes

@ccoVeille
Copy link
Contributor Author

I can confirm it only apply changes when the markdown code contains at least one code snippet

This won't be altered

# title

Let's play!

I like "mdsf"

| Field            | Description            |
|------------------|------------------------|
| foo              |   foo field            |
| bar              |   bar field            |

@ccoVeille ccoVeille changed the title mdsf apply changes outside code snippet mdsf applies changes outside code snippet Apr 1, 2024
hougesen added a commit that referenced this issue Apr 1, 2024
hougesen added a commit that referenced this issue Apr 1, 2024
@hougesen
Copy link
Owner

hougesen commented Apr 1, 2024

Hello @ccoVeille, glad to hear you like the idea! 😄

I just pushed a fix for the quote and ellipsis issue.

The table formatting is a bit trickier, since it is caused by the markdown parser used (pulldown-cmark), not taking into account unnecessary spaces and - in tables.

For now your best option would be to enable a markdown formatter in your mdsf.json.

{
  "markdown": {
    "enabled": true,
    "formatter": ["prettier"]
  }
}

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Apr 1, 2024

You are parsing the markdown files via a lib to identity each code snippet in the markdown.

But then, I assume you are replacing the markdown content in the parsed content, and generate the whole document from the parsed markdown. That's why it leads to changes.

Would it be possible to "simply" (™️) replace the snippet zones as text in the markdown content you opened.

Thanks for the setting, I'll try. Side note, I would have expected this setting to only apply on code snippet is markdown

So something like that

Here are how to make a document title in markdown
```markdown
# Title
```

All these put together, it could lead to have a way to format the markdown of the documents (so not the code snippets) only if requested (but it could be activated by default)

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Apr 1, 2024

Please note that current code also rewrite markdown such as

1. Foo
2. Bar

To

1. Foo
1. Bar

Or list from

* Foo
* Bar

To

- Foo
- Bar

And emphasis from

Foo *bar*

To

Foo _bar_

Everything will be rendered the same way but then in a folder with many markdown files. Only the one containing code snippets you reordered will have these formatting. It would be strange, I think.

@ccoVeille
Copy link
Contributor Author

Anyway, whatever you decide. I provided you some good content for unit tests 😅😁

@ccoVeille
Copy link
Contributor Author

I confirm the latest code fix the issue I raised, thanks a lot for taking into account

@hougesen
Copy link
Owner

hougesen commented Apr 1, 2024

Awesome! 😄

Thanks for the setting, I'll try. Side note, I would have expected this setting to only apply on code snippet is markdown

That is a very good point, I'll split it out to reduce any confusion 👍🏼

@ccoVeille
Copy link
Contributor Author

Awesome! 😄

Thanks for the setting, I'll try. Side note, I would have expected this setting to only apply on code snippet is markdown

That is a very good point, I'll split it out to reduce any confusion 👍🏼

For records, it was applied here #143

@ccoVeille
Copy link
Contributor Author

I'm impressed by the amount of changes in so little time.

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

Successfully merging a pull request may close this issue.

2 participants