Multi-line code blocks

It would be nice to have a way to paste multiline code blocks into single nodes (with syntax highlighting), so that tabs can be included too.

One alternative could be a code format for lists (like how there are checkboxes and numbered lists), but the format works well with code folding etc and monospace.

36 Likes

Are you looking to paste code around the length of a function or a class?

Iā€™m asking because code folding would be useful for the latter but not so much for the former.

It mostly depends on how most users would prefer it.

Personally though, Iā€™d like to put in entire files (so classes) and even snippets (functions, one liners, etc). So perhaps it doesnā€™t matter? Because even in a function you can fold loops or control statements. Basically a way to recreate the structure of code in Dynalist (indentations are sublists).

Wow, thatā€™s cool. I was still thinking of pasting the code blocks into a single items and formatting it as such.

With what you described, code folding could be free, and you can even zoom in on code (wow). The extra work is that it requires a deeper formatting. They need to use a monospace font and drop the bullet point, at the very least. It could be confusing to have both this option and the inline code formatting option (ā€œwhatā€™s the difference between these anyway?ā€ asks a new user).

Overall I really like this idea.

Random question: what type of code do you store in Dynalist? Itā€™s not executable anyway. Is it for reference purposes?

Personally, I like storing both snippets of code and just having the ability to store an entire fileā€™s worth of code without having to create a new file for it. So if Dynalist could do that on its end or simply provide me with a collapsible box in which I could place the code (and modify/copy), that would work for me.

2 Likes

I have a few ideas about how it could be done. Maybe Iā€™ll write up a mock up if you like.

I would use it for 3 main reasons: reference snippets for parts of a larger project or notes. Storage for my own code*. And editing as well if I feel that itā€™s good enough as opposed to say Sublime (now THAT would be amazing!).

*: Iā€™m basically putting all my documents into Dynalist, and if I can do that with code too, thenā€¦ yay.

3 Likes

Sounds great! Hopefully weā€™ll get closer and closer to what you described.

By the way, the fix to this bug could help a bit. No fancy syntax highlighting yet, but a little better than before. :slight_smile:

1 Like

I would really like this feature as well for codeblocks. Thats the only thing I feel thats missing from dynalist.io

4 Likes

Thanks for the input! Would love to hear more about how youā€™re using Dynalist right now if you donā€™t mind. Are you using it to organize code blocks?

1 Like

Iā€™m using Dynalist for notes and retrieval practice with Anki since it is easy to hide nested items. I would also be like to be able to easily type code blocks.

2 Likes

Iā€™m also using Dynalist codeblocks as well. It would be really awesome to use:

 ```python
 def main():
     print("Hello World")
 main()
 ```

and have it syntax-highlighted as Python code. Maybe you could use something like highlight.js?

13 Likes

I think it has low priority and we shouldnā€™t expect it too soon.
In the meantime you can use Tampermonkey to load highlight.js with whatever theme you want and load it on each $(ā€™.node-inline-codeā€™).
I have basic version which highlights each code block when document loads. It doesnā€™t highlight newly added code blocks, I need to refresh tab for that, but itā€™s nice anyway when I want to quickly review some code. It could be extended to highlight each time when some shortcut is pressed, instead of requiring tab refresh. And itā€™s possible to update it each time automatically, but I donā€™t want to waste more time on it as it isnā€™t really that much important.

piotr do u have the link to the tampermonkey file

Iā€™m curious to what it looks like

https://greasyfork.org/pl/scripts/29879-dynahighlight

Itā€™s configured to highlight only blocks with language specified in the first line. Common languages from We're not a CDN - highlight.js are recognised. If you want some other you need to manually add links to those languages from highlight.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers (put each as another @require under the link to highlight.min.js)
I added updating highlighting when shortcut is pressed, ā€˜ctrl + alt + hā€™, it can be changed in the code.
Example:

you can also play with https://greasyfork.org/pl/scripts/29819-focus-mode-for-dynalist Iā€™m testing it and will write a post listing features when it will be ready
ā€˜ctrl + alt + fā€™ to activate/deactivate, and there is also button on the right under search&filter icons

Itā€™s working as intended (on mac with chrome, vivaldi, safari, firefox) and donā€™t lags in any way, but Iā€™m not JavaScript developer so it may be done in stupid way

EDIT: if you want to test focus mode then disable those css styles which I gave you before

3 Likes

is there a white variant of this?

mine looks really weird if its not a dark theme

I really cannot tell what the general CSS theme of each highlight.js variant is either, on the highlight.js page. Arenā€™t some specifically for dark themes and some for light themes?

Also, if I wanted to import excel .VBS support (which isnā€™t on there), on the tamper monkey script would I just add the following line?

// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/languages/excel.min.js

on the first lines?

Are you sure itā€™s working @Vincent_Tang? On the default theme it should also have dark background and font should be monospaced.

Code block should look like that when you click on it:

and when you click somewhere else and press shortcut it should look like that:

in regards to themes, you can choose one of those styles (bottom column on the left) We're not a CDN - highlight.js , look for it here highlight.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers and change link in this line in the code to your favourite theme
$("head").append ('<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/styles/railscasts.min.css">');

about excel - yes, put this exactly like that under this line:
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/highlight.min.js

if you want more languages then add each one under another in the same way

also all other websites have this weird effect now

even after i disabled tamperscript

It has nothing to do with TM, or at least with this script, itā€™s limited to work on dynalist.io and for specific classes within this url.

Easiest (for me) in similar situation would be to open chrome dev tools and see how those colors are applied, there will be some hints.

oh okay I got it now

press ctrl+alt+h to disable the preview

looks really nice

Also what other style themes do you generally like? I was really used to Monokai sublime but I really like the railscast you have

Just wanted some suggestions on a default dynalist white theme

also could you enable code preview by default? Whenever I go on dynalist its not highlighted yet and I have to press CTRL+ALT+H.

Also when I click away I have to press CTRL+ALT+H. Isnā€™t there a javascript event handler to tell the script to rerun again (e.g. you move cursor on a note, then move away from it). Iā€™m not sure how that would be implemented though, i think we had a similar discussion on the ā€œfocusā€ mode CSS post last time.

Also @Erica should use this framework when implementing code support :slight_smile:

thanks @Piotr

1 Like

Happy to see it works for you :slight_smile:

It should HL your code when tab is reloaded, isnā€™t it working? I can make it works each time when you load documents from left pane, just like focus mode is updated each time, but with my current implementation when you have multiple scripts enabled then it will become laggy. Iā€™m doing other things with scripting DL right now and Iā€™m making some progress in understanding it in general, so I think in near future I will improve it to highlight code automatically each time.

My favourite theme is Twilight, but itā€™s not available in HL.js. Other than that, I can work with basically any theme with dark grey background, Monokai Sublime is pretty, Darcula too :slight_smile: Iā€™m using DL with dark theme, so I choose in HL.js also dark theme, but feel free to experiment what looks best in default for you :slight_smile: