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

Embedding Code Snippets in Text Notes. #196

Closed
JordyScript opened this issue Oct 18, 2018 · 9 comments
Closed

Embedding Code Snippets in Text Notes. #196

JordyScript opened this issue Oct 18, 2018 · 9 comments

Comments

@JordyScript
Copy link

A very useful feature to have implemented in Trilium would be the ability to embed code snippets with syntax highlighting into text notes. This would make annotating/documenting your code snippets much more convenient.

A visual example of what I mean is the following screenshot (this is a markdown note created in Boostnote)


boostnote_2018-10-18_11-40-12


Note also how there is a copy button which allows you to copy the entire contents of the code snippet embedded in the text in a single click without selecting it first. This would also be really useful as an additional feature.

The way this is currently done in Boostnote, is by writing three back ticks followed by the programming language you want to write. Then the code, then on the last line three more back ticks. (This even works in githubs comments if I don't escape the back ticks.)

``` python

[insert code here]

```

@zadam
Copy link
Owner

zadam commented Oct 19, 2018

Hi JordyScript, I'd love to have this feature as well, but this is actually a responsibility of CKEditor (which is our editing component). They have an issue for this, but I'm afraid there hasn't been much progress recently: ckeditor/ckeditor5#436 As soon as that feature lands in, we'll have it as well. Even though it's not perfect for now I use code subnote for larger code snippets and if it's really piece of code small I use blockquote inside text document.

@Fenwick17
Copy link

@zadam For code subnote, do you just create a child note? Issue I have there is a visual one.
If I have created one sentence which might be describing some code, and then I create a child note, theres a large gap for the layout.
My preference would be something like this
"Text block of content"
Code Child note
"Another text content block"
Not sure if this is just an issue with my structure though. Being able to choose the location of child notes on the view would be handy.

@zadam
Copy link
Owner

zadam commented Dec 1, 2018

Unfortunately what you want is not possible now - there's always just single note displayed. Instead of doing that I rather want to wait for CKEditor to implement proper code block feature (which they plan to do, it's just a matter of time).

For now whenever I need code block inside text note I use either blockquote or single line code. It's far from perfect, but works for me in the meantime.

@Fenwick17
Copy link

Cheers @zadam I will stick with single line code, it'll do the job

@gpanders
Copy link

It looks like this may be added to CKEditor soon: https://twitter.com/ckeditor/status/1138803157700624385

@zadam
Copy link
Owner

zadam commented Jun 20, 2019

Yes, I'm watching it closely and I'm ready to integrate as soon as it is available :-)

@zadam
Copy link
Owner

zadam commented Dec 4, 2019

Code block support is in 0.38.0-beta

@zadam zadam closed this as completed Dec 4, 2019
@dafmdev
Copy link

dafmdev commented Jun 12, 2021

Hello, I have been testing the software, but I see that they do not apply color syntax in the code blocks.

@zadam
Copy link
Owner

zadam commented Jun 12, 2021

Syntax highlighting is very difficult to apply in the code snippets in the text editor and I don't expect this to happen anytime soon. If you need highlighting then I recommend creating a "code note":

image

Nriver pushed a commit to Nriver/trilium that referenced this issue Jul 19, 2024
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

5 participants