nimib-land / nimiBoost

Highlight Markdown in Nimib files and preview the result in a separate panel.
https://marketplace.visualstudio.com/items?itemName=hugogranstrom.nimiboost
MIT License
2 stars 0 forks source link

highlight inside generalized string literals #1

Closed pietroppeter closed 2 years ago

pietroppeter commented 3 years ago

If I am seeing this correctly you are highlighting markdown now when you see string preceded by nbText, correct?

What about providing a mechanism to highlight when provided with a md string literal that is just a marker.

For example:

template md(s: string): string = s

echo md"# a title with [link](#somehwere)"
echo md"""## another smaller title

with some content written in **markdown**

So that link to [stuff] is easy to add.

[stuff]: https://stuff.org
"""

of course the template md should be provided externally (and if you want to use formatted string you would have to do stuff like &(md"hi **{name}**") or defined a fmd template that is md + fmt). The same mechanism could apply to html to highlight it (not necessarily relevant for nimib, but it could be useful in general).

HugoGranstrom commented 3 years ago

If I am seeing this correctly you are highlighting markdown now when you see string preceded by nbText, correct?

Yes correct, it begins the match when it sees nbText: """ and ends it at the next """.

What about providing a mechanism to highlight when provided with a md string literal that is just a marker.

It would work equally nice and be more general. :) Just start at md"{1,3} and end at "{1,3} and we should be good to go, even easier than before 😄

of course the template md should be provided externally

I may be reading to much into this but what do you mean externally? Just that Nimib exports it? Or even more general so people doesn't neccecarily have to use Nimib to get access to md, like in nim-markdown?

(and if you want to use formatted string you would have to do stuff like &(md"hi **{name}**") or defined a fmd template that is md + fmt)

For ease of use, couldn't we just make md have & built-in by default? It would be a bit cumbersome if one wanted to write a lot of { and } though to escape them all the time :/ fmd perhaps isn't a bad idea after all. The regex would just be f?md"{1,3} instead.

The same mechanism could apply to html to highlight it (not necessarily relevant for nimib, but it could be useful in general).

That is certainly true! html"<a></a>" would be really easy to implement as well. This is growing on me more the more I think about it 😄

HugoGranstrom commented 3 years ago

of course the template md should be provided externally

Ok, think I've figured out what you meant now a day later. 🙃
Externally == Not in NimiBoost?

pietroppeter commented 3 years ago

ah yes 😊

HugoGranstrom commented 3 years ago

I've been sitting all evening now trying to get md"# something on one line" and md"""# something on one line""" to work but VSCode refuses to obey me. If the ending """ is on a separate line it works fine but if it isn't it ruins the syntax highlighting of everything below it. Do you think that is acceptable behavior as long as I clearly state the limitation in the README?

pietroppeter commented 3 years ago

for a first version to try out it is ok. It would need to be fix though at some point. unfortunately I have very limited knowledge of this to help (you might want to try and ask saem in the chat).

HugoGranstrom commented 3 years ago

Yes that makes sense. Found this issue though which seems to perhaps be relevant in this case: https://github.com/microsoft/vscode-textmate/issues/139 It could be that the injected markdown grammar eats up the ending """ and then it's nothing I can do about it :/

HugoGranstrom commented 3 years ago

@pietroppeter Where do you think such md and fmd templates should be placed? In nimib itself or should I create a companion nimble package nimiboost where I put stuff like this? (Templates to boost productivity further for example could be placed in a nimiboost package as well)

pietroppeter commented 3 years ago

Mmh, both options are fine. If you want to put them in a nimib / boost (We would need to export it in nimib) that would be fine for me.

HugoGranstrom commented 3 years ago

I'm a bit torn actually. Having it in nimib / boost would make it much easier to use (no additional packages) but having a separate package allows for adding more stuff in the future and we wouldn't clutter the nimib package. But I think I'll go the nimib / boost route with your permission and keep it to functionality strictly required for NimiBoost to work. Additional helper templates and such could then be published in their own package (not necessarily afflicted with NimiBoost) in the future. How does that sound? Anything more than md and fmd you would like to see added then? :)

pietroppeter commented 3 years ago

Sounds fine. I guess we could start with md and fmd for the moment.

HugoGranstrom commented 3 years ago

Ok great! 👍 I'll spin up a PR for it immediately