How to enable Prism on DT 3.5?

Super exciting to see DT 3.5 support the prism in the markdown file, while I have some trouble enabling it. Simply enable the prism support checkbox doesn’t have any effect. Is there any documentation on how to enable it?

Thanks in advance.

Your Markdown code has to specify the used language, e.g. like this:

<code class="language-applescript">
tell application id "DNtp"
end tell
</code>

```language-applescript
tell application id "DNtp"
end tell
```

This affects the rendered (Preview) view, not the source

My markdown file looks like:

Test

// @State Example
struct CounterView: View {
    @State var count = 0
    var body: some View {
        Button(action: {
            self.count += 1
        }, label:  {
            Text("\(self.count)")
        })
    }
}

and the preview is:

Does it work after using ```language-swift instead of ```swift?

It works after using language-swift! It would be more convenient if highlight can work without language- prefix.

1 Like

That’s now how prism.js works. You need to use the language-mylanguage for it to render properly.

1 Like

Thanks for adding native support for Prism in DT3.5!

Thanks go to @cgrunenberg and @aedwards for the heavy lifting in all things DEVONthink but thanks for the thanks :wink: :slight_smile:

1 Like

Additionally to enabling Prism.js in Markdown (Media tab in settings) you need to make sure that “Enable JavaScript” is checked in the Web tab in the settings.

Also I noted that for example language-sql doesn’t seem to work for me (while swift does). But sql is a supported tag by prism. Any idea why this is happening?

EDIT: Supported languages from the release notes:

Currently AppleScript, Objective-C, Swift, C, C++, Java, and JavaScript are supported.

Not all languages are supported, see release notes. Otherwise the embedded Prism files would be much larger and e.g. bloat the code after converting Markdown to HTML.

any chance bash/sh languages would be added in the future (bash is much used on the mac isn’t it?)

Z

Though optionally still available, bash is pre-Catalina. zsh is the default shell now.

gotcha, but zsh isn’t currently supported as well right? would be nice to add either to get CLI syntax in markdown documentation:)

thx

Z

Correct. And to reiterate Criss’ comment: “Not all languages are supported, see release notes. Otherwise the embedded Prism files would be much larger and e.g. bloat the code after converting Markdown to HTML.”

Devonthink team thanks for the 3.5 update. I feel there’s a need to outline how to use the custom Prism file since it helped me centralize my SQL, Visual Basic, Batch, Powershell, etc. code syntax, snippets and historical versions into DT as opposed to having them scattered across two other apps and Outlook folders. Code-block works on both Devonthink Mac and iOS as shown below using this method.

iOS Screenshot

One Time Setup on Mac

  • Go to prism website

  • Click the big download button at the top

  • Check off the theme and languages you will be using

  • (Optional) Check off plugins like Inline Color, Normalize Whitespace (for removing extra lines in rendered code), and Copy to Clipboard Button. Unfortunately, Line Numbers didn’t work for me at the time of this writting.

  • Download both the CSS and Javascript file using the big download buttons on the bottom of the page.

    • If you are using Normalize Whitespace and want your code to wrap around, insert the “break-line”: 80 line into the javascript file method Prism.plugins.NormalizeWhitespace as shown below.
	(Prism.plugins.NormalizeWhitespace=new e({"remove-trailing":!0,"remove-indent":!0,"left-trim":!0,"right-trim":!0,"break-lines": 80})

Be sure to check your quotes whenever you copy / paste as the open/close quotes can be copied instead of the general quote used in code

  • Place both files in your database
  • Copy the Item link for each file by left clicking on the file and paste the x-link between the quotes like shown below:

For CSS File

<link href=“x-devonthink-item://0A9B8CBC-D620-4257-B1A8-71E363C0EDBA” rel=“stylesheet”>

For Javascript file

<script src=“x-devonthink-item://96C2CDA1-86FE-4DE4-8924-92C7541A432C”></script>
  • using the devonthink item link allows you to move the files around the db without breaking the connection

  • place this at the top of every markdown document where you would like to use the code-block, I use a text expander to automatically insert it by typing .syntax

  • As mentioned above, prism uses the language-xxxx in the code-block to identify the language you are working with.

    • The language must be spelled out just like it is listed in the prism website otherwise it will not highlight ie. use language-excel-formula NOT language-excel
  • Be sure to save the document to see the code-block highlight or when changing from one language to another

    • Reboot Devonthink if necessary

:sunglasses:

2 Likes

Thanks for the comments.
They are find if someone wants to customize their prism experience. The 3.5 build allows use of prism without needing to explicitly link the css and js files, though it only supports a smaller number of all the supported languages.

@MosCool_Noel, any luck with getting line numbering to work?

best

Z

Question: I see that a generated prism.js is stored in the .app folder structure and that it seems to have the 4 prism defaults with a few extras. Is there a way that at some point in the future that could be in the Application Support (or similar) folder so that it could be overridden with a customer-generated prism.js?

I respect that you guys want to avoid bloat but I also personally don’t care about the bloat for my own purposes in previewing the files. I would love to have a way to generate and use my own customized prism.js that wouldn’t involved putting it in the .app folder and have it being overwritten by updates.

Why don’t you just disable it in the preferences, then link to your own local copy of it?