在 Notepad++ 中將 .haml 轉換為 .html?

在 Notepad++ 中將 .haml 轉換為 .html?

如何設定 Notepad++ 在每次更新和儲存 .haml 檔案時自動執行控制台行「haml [filename.haml] [filename.html]」?

答案1

您可以使用 Python 腳本插件來完成此操作 - 只需添加一個新腳本即可

notepad.clearCallbacks([NOTIFICATION.FILESAVED])

# Define the function to call just after the file is saved
def runHaml(args):
    filename = notepad.getBufferFilename(args["bufferID"])
    if filename[-5:] == '.haml':
        cmd = r'cmd /c C:\path\to\haml "{0}" "{1}.html"'.format(filename, filename[:-5])
        console.write(cmd + "\n")
        console.run(cmd)


# ... and register the callback 
notepad.callback(runHaml, [NOTIFICATION.FILESAVED])

您可以將其新增至startup.py以使其在啟動時自動執行(也將Python腳本的配置變更為「ATSTARTUP」)。

答案2

使用類似的東西怎麼樣觀察者腳本?

就像是:

watch( '(.*)\.haml' ) do |md|
  system("haml #{md[0]} #{md[1]}.html")
end

每當來源 haml 發生變化時,應該自動重新編譯您的 html 檔案。

相關內容