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

Could the user specify number of backticks to use in snippet code blocks? #537

Open
claremacrae opened this issue Nov 23, 2022 · 7 comments

Comments

@claremacrae
Copy link
Contributor

Is the feature request related to a problem

Yes.

Summary

Use of snippet files that are markdown code blocks generates invalid markdown. The generated snippet code block should use a larger number of backticks than the content being embedded.

Please could there be a way for the user to request a larger-than-3 number of backticks to be used in the generated code blocks.

Context

This is an example snippet - it's a whole file, which is a markdown language block.

file name:

DocsSamplesForExplain.test.explain_boolean combinations.approved.query.text

file content:

```tasks
explain
not done
(due before tomorrow) AND (is recurring)
```
Current behaviour

mdsnippets converts this line:

snippet: DocsSamplesForExplain.test.explain_boolean combinations.approved.query.text

to this:

```text
```tasks
explain
not done
(due before tomorrow) AND (is recurring)
```

```

This gives markdownlint warnings like:

docs/queries/explaining-queries.md:54 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
Requested behaviour

Somehow enable mdsnippets to wrap the snippet with one more backtick than the text that is being inserted:

````text
```tasks
explain
not done
(due before tomorrow) AND (is recurring)
```

````

The requested difference is:

-```text
+````text
```tasks
explain
not done
(due before tomorrow) AND (is recurring)
```

-```
+````

Describe the solution

Could the user have a way to specify the number of backticks to be used to delimit the inserted snippet code block please?

Ideas for the setting:

"BackticksCount": 4,
"BackticksLevel": 4,
"NumberOfBackticks": 4,

"Backticks": "````",
"BackticksForLanguage": "````",

I think that it would be unreasonable to expect mdsnippets to parse every snippet to detect code blocks...

But allowing the user to select a project-wide larger number of backticks would allow inserting of markdown language blocks via mdsnippets.

Describe alternatives considered

For now my files to embed look like this, without the language. But this is a lot less useful for its users.

explain
not done
(due before tomorrow) AND (is recurring)

Additional context

None.

@SimonCropp
Copy link
Owner

i think nested ticks should be escaped. thoughts?

@claremacrae
Copy link
Contributor Author

i think nested ticks should be escaped. thoughts?

Oh. Interesting idea.

I tried it, so that my snippet to embed now looks like:

\`\`\`tasks
explain
not done
(due before tomorrow) AND (is recurring)
\`\`\`

Is that what you meant?

When embedded this gets rendered as:

image

So not quite the effect that I am after... Also, even if it rendered OK, it makes the snippet file be a little less useful, as not copy-and-pastable, reusable for testing and similar.

@claremacrae
Copy link
Contributor Author

'n+1' backticks really is the convention:
https://yihui.org/en/2017/05/four-backticks-github/

@claremacrae
Copy link
Contributor Author

'n+1' backticks really is the convention:
https://yihui.org/en/2017/05/four-backticks-github/

Related, N+1 also works in Obsidian markdown editor, which is the tool I am writing this code for. So the lovely advantage of the generated markdown being consistent with GitHub markdown is that people who clone the repo will be able to read the docs directly.

The JetBrains IDEs also render the 4 back ticks as intended.

@SimonCropp
Copy link
Owner

@claremacrae can you submit a Pull Request for that change?

@claremacrae
Copy link
Contributor Author

Please leave the issue open for me to look at it, as I do really want it.

Unfortunately being on a Mac, JetBrains Rider is giving me a bunch of errors when I open the project. I don't have the details here, but it could be that a bunch of tools are just out of date, as it's 18 months since I did any C#.

@isidore
Copy link

isidore commented Dec 7, 2022

This would be great. I think it would be better if any snippet: text checked if it contained ``` and automatically changed itself to be ```` or rather `+1.
I have some time next week if you would like to pair on this.

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

3 participants