Multi-line code blocks

Are you going to merge Piotorā€™s script in the master branch or come with another solution?

Thereā€™s lineNumber options on PowerPack2 that piotr incorporated in

No, it will be difficult to incorporate Powerpackā€™s code.

If we were going to do it, weā€™re do it ourselves (not necessarily a dramatically different way, just a way thatā€™s consistent with our current code).

I use Powerpack2 code highlighting - great tool BTW, but Iā€™d also like to modify CSS for inline codes that donā€™t have any language specified (think poor manā€™s highlight)

I added the following to Stylish :

.node-inline-code {
    color: #f0f0f0;
    background-color: #c7254e;}

However this messed with with PowerPackā€™s code highlight, anyone know a trick to make this work; such that my css will only work on codes where no language is specified?

ā€˜print [i for i in range(10)]ā€™ -> use Stylish CSS
ā€™python print [i for i in range(10)]ā€™ -> use PowerPack

Thanks.

Hi, try this .node-inline-code:not(.hljs) { ... }

2 Likes

Thank you @Piotr

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:

https://imgur.com/a/byndkU1

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