From a19283c5fc4bf5b38aedb89b08cd36568c92c293 Mon Sep 17 00:00:00 2001 From: hector crispens Date: Sun, 26 Jan 2025 22:20:55 -0300 Subject: [PATCH 1/3] agrega opciones de pupperteer --- lua/diagram/renderers/mermaid.lua | 98 +++++++++++++++++-------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/lua/diagram/renderers/mermaid.lua b/lua/diagram/renderers/mermaid.lua index bda2b0f..bd72976 100644 --- a/lua/diagram/renderers/mermaid.lua +++ b/lua/diagram/renderers/mermaid.lua @@ -2,13 +2,14 @@ ---@field background? string ---@field theme? string ---@field scale? number +---@field pupperteer? string ---@type table local cache = {} -- session cache ---@class Renderer local M = { - id = "mermaid", + id = "mermaid", } -- fs cache @@ -19,54 +20,65 @@ vim.fn.mkdir(tmpdir, "p") ---@param options MermaidOptions ---@return string|nil M.render = function(source, options) - local hash = vim.fn.sha256(M.id .. ":" .. source) - if cache[hash] then return cache[hash] end + local hash = vim.fn.sha256(M.id .. ":" .. source) + if cache[hash] then + return cache[hash] + end - local path = vim.fn.resolve(tmpdir .. "/" .. hash .. ".png") - if vim.fn.filereadable(path) == 1 then return path end + local path = vim.fn.resolve(tmpdir .. "/" .. hash .. ".png") + if vim.fn.filereadable(path) == 1 then + return path + end - if not vim.fn.executable("mmdc") then error("diagram/mermaid: mmdc not found in PATH") end + if not vim.fn.executable("mmdc") then + error("diagram/mermaid: mmdc not found in PATH") + end - local tmpsource = vim.fn.tempname() - vim.fn.writefile(vim.split(source, "\n"), tmpsource) + local tmpsource = vim.fn.tempname() + vim.fn.writefile(vim.split(source, "\n"), tmpsource) - local command_parts = { - "mmdc", - "-i", - tmpsource, - "-o", - path, - } - if options.background then - table.insert(command_parts, "-b") - table.insert(command_parts, options.background) - end - if options.theme then - table.insert(command_parts, "-t") - table.insert(command_parts, options.theme) - end - if options.scale then - table.insert(command_parts, "-s") - table.insert(command_parts, options.scale) - end - if options.width then - table.insert(command_parts, "--width") - table.insert(command_parts, options.width) - end - if options.height then - table.insert(command_parts, "--height") - table.insert(command_parts, options.height) - end + local command_parts = { + "mmdc", + "-i", + tmpsource, + "-o", + path, + } + if options.background then + table.insert(command_parts, "-b") + table.insert(command_parts, options.background) + end + if options.theme then + table.insert(command_parts, "-t") + table.insert(command_parts, options.theme) + end + if options.scale then + table.insert(command_parts, "-s") + table.insert(command_parts, options.scale) + end + if options.width then + table.insert(command_parts, "--width") + table.insert(command_parts, options.width) + end + if options.height then + table.insert(command_parts, "--height") + table.insert(command_parts, options.height) + end + if options.pupperteer then + table.insert(command_parts, "-p") + table.insert(command_parts, options.pupperteer) + end - local command = table.concat(command_parts, " ") - vim.fn.system(command) - if vim.v.shell_error ~= 0 then - vim.notify("diagram/mermaid: mmdc failed to render diagram", vim.log.levels.ERROR) - return nil - end + local command = table.concat(command_parts, " ") + vim.notify(command) + vim.fn.system(command) + if vim.v.shell_error ~= 0 then + vim.notify("diagram/mermaid: mmdc failed to render diagram", vim.log.levels.ERROR) + return nil + end - cache[hash] = path - return path + cache[hash] = path + return path end return M From 7967cfc6a309f52f70b44b1a3cc61a973be02192 Mon Sep 17 00:00:00 2001 From: hector crispens Date: Sun, 26 Jan 2025 22:57:19 -0300 Subject: [PATCH 2/3] actualiza el readme con las opciones de pupperteer --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f65516c..9f2fbd6 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ With **lazy.nvim**: scale = 1, -- nil | 1 (default) | 2 | 3 | ... width = nil, -- nil | 800 | 400 | ... height = nil, -- nil | 600 | 300 | ... + pupperteer = "home//.config/puppeteer/puppeteer.config.json", --nil }, plantuml = { charset = nil, @@ -64,6 +65,16 @@ With **lazy.nvim**: }, }, ``` +#### puppeteer options +Puppeteer config file can be found in ~/.config/puppeteer/puppeteer.config.json and able to set chrome-headless-shell versión +```json +{ + "executablePath": "/home//.cache/puppeteer/chrome-headless-shell/linux-132.0.6834.110/chrome-headless-shell-linux64/chrome-headless-shell", + "puppeteer": { + "chromiumRevision": "132.0.6834.110" + } +} +``` ### Usage From 5d59447c90b8bc848a7c4221879ba49806bed0ee Mon Sep 17 00:00:00 2001 From: hector crispens Date: Mon, 3 Feb 2025 22:46:52 -0300 Subject: [PATCH 3/3] modify pupperteer option to pupperteer_path and update readme.md --- README.md | 7 +++++-- lua/diagram/renderers/mermaid.lua | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9f2fbd6..108b363 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ With **lazy.nvim**: scale = 1, -- nil | 1 (default) | 2 | 3 | ... width = nil, -- nil | 800 | 400 | ... height = nil, -- nil | 600 | 300 | ... - pupperteer = "home//.config/puppeteer/puppeteer.config.json", --nil + pupperteer_path = "home//.config/puppeteer/puppeteer.config.json", --nil }, plantuml = { charset = nil, @@ -65,8 +65,11 @@ With **lazy.nvim**: }, }, ``` +> [!info] +> pupperteer_path should be the path to your puppeteer.config.json, set the correct path and user. + #### puppeteer options -Puppeteer config file can be found in ~/.config/puppeteer/puppeteer.config.json and able to set chrome-headless-shell versión +Puppeteer config file can be found in ~/.config/puppeteer/puppeteer.config.json and able to set chrome-headless-shell versión, required by mermaid-cli. ```json { "executablePath": "/home//.cache/puppeteer/chrome-headless-shell/linux-132.0.6834.110/chrome-headless-shell-linux64/chrome-headless-shell", diff --git a/lua/diagram/renderers/mermaid.lua b/lua/diagram/renderers/mermaid.lua index bd72976..8467832 100644 --- a/lua/diagram/renderers/mermaid.lua +++ b/lua/diagram/renderers/mermaid.lua @@ -2,7 +2,7 @@ ---@field background? string ---@field theme? string ---@field scale? number ----@field pupperteer? string +---@field pupperteer_path? string ---@type table local cache = {} -- session cache @@ -64,13 +64,13 @@ M.render = function(source, options) table.insert(command_parts, "--height") table.insert(command_parts, options.height) end - if options.pupperteer then + if options.pupperteer_path then table.insert(command_parts, "-p") - table.insert(command_parts, options.pupperteer) + table.insert(command_parts, options.pupperteer_path) end local command = table.concat(command_parts, " ") - vim.notify(command) + -- vim.notify(command) vim.fn.system(command) if vim.v.shell_error ~= 0 then vim.notify("diagram/mermaid: mmdc failed to render diagram", vim.log.levels.ERROR)