Multi-line code blocks

This weekend I was working with code snippets and was trying to put them into dynalist. Other than a note field, which didn’t really suit my purpose, I had the same need as you describe here.

2 Likes

Actually, a note field is good for me but I would like to have ‘code field’ with code highlights and which can be handled separately (like search in code fields etc.). Maybe this is the way?

Just adding my +1 again for using code blocks, whether it’s in the note field or has syntax highlighting or not. I understand that it would be difficult to implement without fundamentally changing Dynalist in some way. I have been using Notion for taking notes, but am too used to the autoformatting of all the things into a flexible outline.

I’ve found that you can do code without syntax highlighting using the following procedure:

  1. Make a new bullet
  2. Immediately press shift-Enter
  3. Type three backticks and your first line of code
  4. Hit Enter
  5. Type your other code, continuing to use Enter
  6. When you’re done, type three more backticks

You end up with a code block hanging off a bullet with an empty line; not the greatest looking but still okay:

8 Likes

Great suggestion, only my results vary from yours:

See that blank link at the start of the comment, it’s where the ``` is at. You want it that way so I can more easily clip this code into a file.

It would be cool if

  • Devs implemented a code-mode like number-list mode, where any bullet items that are under Code mode would be mono-spaced.
  • Further, if a Paste-code function would magically recognize indentation (spaces or tabs) and format appropriately.
  • And further if Copy of multiple lines would also offer a plain-text with tab indentation. (from DL to source-code editor. This last bit would be equally good from DL to Wordprocessor.)
1 Like

You can also select all of the code (ctrl/cmd+A) and then use (ctrl/cmd+`) to format the code.

This requires an additional tool for doing the formatting, right?

To have proper code syntax highlighting based on the programming language, yes. That’s assuming one is available. The backticks simply convert the text to monospaced.

Oh, monospace is my default font anyway :slight_smile:

1 Like

As I understand it, the practice of using three backticks to start/stop a code block exists so that the code block can include backticks without terminating the block.

Based on my tinkering with dynalist, it looks like the three consequtive backticks just do this:

prose goes here
[start block][stop block][start block]
code goes here
[stop block][start block][stop_block]
more prose here

That is, if your code contains a backtick, it will terminate the formatting. As it stands, you might as well just use a single backtick.

What would be nice is if three backticks start a code block that can only be terminated with another three backticks, then you could do this:

```
echo first file: `ls | head -n 1`
```

…and the backticks in the code block wouldn’t interfere (markdown does it this way, so does slack). Ideally the first empty newline would also be ignored in this case, which makes it easy to triple-click-highlight the whole line and not also pick up the formatting indicator.

Additionally, it would be cool if the code blocks appeared in <pre> tags when exporting to html.

3 Likes

Using three backticks is fine, however, It will delete all indentation, I don’t want to manually indent every line in dynalist.
Any suggestions or advices? Thanks in advance.

1 Like

Guys, the only thing I miss in dynalist is multi-line code block out of the box.

5 Likes

Same here. Dynalist is the perfect match for my workflow but I need standalone multi-line code blocks with syntax highlighting. It shouldn’t be hard to implement. Please!

3 Likes

Ahem - yet another use case that could be easily solved by incorporating a comprehensive third-party markdown renderer.

1 Like

thanks, this markdown code block with triple backticks works!

Hi all! Does this work now? For me hitting enter or pasting something multiline always creates new item - either with triple backticks or without

a) Use shift-enter to add a note. you can use multiple lines in the note.

b) Or, use ctrl+shift+enter to add more lines to the item without advancing to the next bullet

c) If there’s a way to paste multiple lines into a single bullet, I don’t know it.

1 Like

I copy multiple lines into a single bullet by first pasting what I’m copying into a note (shift-enter). When I’m adding code, I put the triple-tick marks in front of the first line and after the last line. If you just want plain text in multiple lines, just don’t use the tick marks. I haven’t figured out a way to directly paste multiple lines into a single bullet.

Thanks you @Alan, @WebAlstrom ! ctrl-shift-enter is what I was looking for :+1:

By any chance, does the indentation change from tabs to spaces when saved as a snippet on Dynalist?

Asking because I never use spaces but pasted snippets have spaces. When I use tab, the IDE tells me I can’t mix tabs with spaces.

Reminds me of that episode in Silicon Valley :sweat_smile: