Can we configure the Markdown editor to automatically open this file when creating a new article?

When I used Hexo previously, I could launch Typora to open the newly created post by customizing a JS script.
I wonder if Hugo has a corresponding API that can achieve the same functionality, because it’s a bit cumbersome for me to manually locate and open the file in my editor every time I create a new post.

https://gohugo.io/configuration/all/#newcontenteditor

You’ll also need to add the exec name to the allowlist:
https://gohugo.io/configuration/security/

You can also use the --editor CLI flag. See hugo new content --help.

1 Like

Hello, I haven’t succeeded yet. I’ve already added the Typora editor to the Windows environment variables. My Hugo.toml configuration is:

newContentEditor = "Typora"
[security.exec]
    allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^npx$', '^postcss$', '^tailwindcss$','^Typora$']

I’ve pasted my execution log below. As you can see, without the CLI flag, there’s no prompt message automatically opening the file with Typora.

D:\Blog
➜  where typora
C:\Program Files\Typora\Typora.exe


D:\Blog
➜  where Typora
C:\Program Files\Typora\Typora.exe


D:\Blog
➜  hugo new "posts/test10.md" --editor Typora
Content "D:\\Blog\\content\\posts\\test10.md" created
Editing "D:\\Blog\\content\\posts\\test10.md" with "Typora" ...


D:\Blog
➜  hugo new "posts/test11.md"
Content "D:\\Blog\\content\\posts\\test11.md" created

newContentEditor is a root level setting which as per TOML spec have to be listed before any table.

educated guess you just added these two line at the end …

move the newContentEditor anywhere before the first array [arrayname]

baseURL = '...'
title   = '...'
...
newContentEditor = "Typora"
...
defaultContentLanguage = '...'

[languages]  <- first array (you might have another one first)
...
[security.exec]
  allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^npx$', '^postcss$', '^tailwindcss$', '^Typora$']


p.s. the security settings is case sensitive so make sure that these use the same capitalization

  • allow list
  • commandline --editor
  • newContentEditor

or use '^[Tt]ypora$' as pattern so you can use --editor Typora and --editor typora on windows

2 Likes

Yes, I’ve added them to the end. Thank you very much.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.