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

Code Blocks #7

Closed
David-Kunz opened this issue Jul 12, 2021 · 4 comments
Closed

Code Blocks #7

David-Kunz opened this issue Jul 12, 2021 · 4 comments

Comments

@David-Kunz
Copy link

Hi,

This is a feature request to make code blocks a bit nicer to use.

Current State

@code javascript
  const foo = () => { console.log('hello world') }
@end

Proposal 1

Have the same identifiers as in GitHub markdown, e.g.

@code js
  const foo = () => { console.log('hello world') }
@end

Proposal 2

Also allow triple backticks, e.g.

| ```js
|   const foo = () => { console.log('hello world') }
| ```
@vhyrro
Copy link
Member

vhyrro commented Jul 12, 2021

Hm, this is where we hit a few roadblocks:
a) The js language is actually supported (it's available in the autocompletion menu as you type) however it's treesitter that actually handles injecting itself (and syntax highlighting) into code blocks. All I do is tell TreeSitter "hey, this part of the syntax tree is the name of the language to inject" and TS handles the rest. It seems that jsis not recognized by TreeSitter as a language to inject, but javascript is. I think there may be a way to change this behaviour with some special queries, I will see whether there's anything online, because from my current attempts an incredible 0 of them worked
b) Even though the first problem may be solvable, I don't think that the second one is possible. We actually purposefully decided against triple backticks for code blocks as a design choice. This is for two reasons. The first is that triple backticks would instantly break all defined rules regarding modifiers. Modifiers simply cannot span longer than a single paragraph, alongside a few other things. The second is because of the annoyances that come with triple backticks, like this:
Hello, this is a ```
code block
``` and here I keep writing.
Or:
- Here's some code that you should read: ```

``` - description

This hinders readability and just all round looks worse in my opinion. Even markdown itself doesn't know how to handle these situations at times, hah

I will look into the TreeSitter stuff when I get the time though and I'll let you know of any findings.

@David-Kunz
Copy link
Author

Hi @vhyrro ,

Thanks a lot for your extensive answer! Not supporting backticks is fine for me, it was just a suggestion as many people are already used to that.

Thanks and best regards,
David

@vhyrro
Copy link
Member

vhyrro commented Jul 12, 2021

Hey, I fixed the problem. The js shorthand now shows javascript syntax highlighting (at least from my tests). The issue is that this process will probably have to be done for a lot of different languages with their own shorthands. This is a message to all people: if a shorthand for your language doesn't work, then please let me know in an issue. Fixing the problem is rather trivial and requires little work.

@vhyrro vhyrro closed this as completed Jul 12, 2021
@David-Kunz
Copy link
Author

Awesome, thanks a lot for this quick fix @vhyrro !

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

2 participants