From 372eb7e9754f3056d416dbd07797cdca95f60965 Mon Sep 17 00:00:00 2001 From: AlejandroSuero Date: Sat, 4 May 2024 00:25:32 +0200 Subject: [PATCH 1/2] feat(#138): added configurable `fts` and `exts` --- README.md | 8 ++++++-- lua/glow.lua | 12 ++++++++++-- tests/glow/glow_spec.lua | 8 ++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 798b338..b757b4a 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@

- + -https://user-images.githubusercontent.com/178641/215353259-eb8688fb-5600-4b95-89a2-0f286e3b6441.mp4 + **Breaking changes are now moved to a fixed topic in Discussions. [Click here](https://github.com/ellisonleao/glow.nvim/discussions/77) to see them** @@ -60,6 +60,10 @@ The script comes with the following defaults: height = 100, width_ratio = 0.7, -- maximum width of the Glow window compared to the nvim window size (overrides `width`) height_ratio = 0.7, + filetypes = { "markdown", "markdown.pandoc", "markdown.gfm", "wiki", "vimwiki", "telekasten" }, + extra_filetypes = {}, + extensions = { "md", "markdown", "mkd", "mkdn", "mdwn", "mdown", "mdtxt", "mdtext", "rmd", "wiki" }, + extra_extensions = {}, } ``` diff --git a/lua/glow.lua b/lua/glow.lua index a47fc42..63547bc 100644 --- a/lua/glow.lua +++ b/lua/glow.lua @@ -24,6 +24,10 @@ local glow = {} ---@field pager boolean display output in pager style ---@field width integer floating window width ---@field height integer floating window height +---@field filetypes table allowed filetypes +---@field extra_filetypes table aditional filetypes +---@field extensions table allowed extensions +---@field extra_extensions table aditional extensions -- default configurations local config = { glow_path = vim.fn.exepath("glow"), @@ -33,6 +37,10 @@ local config = { pager = false, width = 100, height = 100, + filetypes = { "markdown", "markdown.pandoc", "markdown.gfm", "wiki", "vimwiki", "telekasten" }, + extra_filetypes = {}, + extensions = { "md", "markdown", "mkd", "mkdn", "mdwn", "mdown", "mdtxt", "mdtext", "rmd", "wiki" }, + extra_extensions = {}, } -- default configs @@ -225,7 +233,7 @@ end ---@return boolean local function is_md_ft() - local allowed_fts = { "markdown", "markdown.pandoc", "markdown.gfm", "wiki", "vimwiki", "telekasten" } + local allowed_fts = vim.tbl_deep_extend("force", glow.config.filetypes, glow.config.extra_filetypes) if not vim.tbl_contains(allowed_fts, vim.bo.filetype) then return false end @@ -234,7 +242,7 @@ end ---@return boolean local function is_md_ext(ext) - local allowed_exts = { "md", "markdown", "mkd", "mkdn", "mdwn", "mdown", "mdtxt", "mdtext", "rmd", "wiki" } + local allowed_exts = vim.tbl_deep_extend("force", glow.config.extensions, glow.config.extra_extensions) if not vim.tbl_contains(allowed_exts, string.lower(ext)) then return false end diff --git a/tests/glow/glow_spec.lua b/tests/glow/glow_spec.lua index 77b7a49..c594fa8 100644 --- a/tests/glow/glow_spec.lua +++ b/tests/glow/glow_spec.lua @@ -11,6 +11,10 @@ describe("setup", function() pager = false, width = 100, height = 100, + filetypes = { "markdown", "markdown.pandoc", "markdown.gfm", "wiki", "vimwiki", "telekasten" }, + extra_filetypes = {}, + extensions = { "md", "markdown", "mkd", "mkdn", "mdwn", "mdown", "mdtxt", "mdtext", "rmd", "wiki" }, + extra_extensions = {}, } glow.setup() assert.are.same(glow.config, expected) @@ -25,6 +29,10 @@ describe("setup", function() pager = true, width = 200, height = 100, + filetypes = { "markdown", "markdown.pandoc" }, + extra_filetypes = { "wiki" }, + extensions = { "md", "markdown", "mkd", "mkdn" }, + extra_extensions = { "mdtext" }, } glow.setup(expected) assert.are.same(glow.config, expected) From f2ffd79c1917ebbbb486adf56c2857a6f13f202e Mon Sep 17 00:00:00 2001 From: AlejandroSuero Date: Tue, 14 May 2024 21:09:59 +0200 Subject: [PATCH 2/2] feat: added `nil` check for extra `fts` and `exts` --- lua/glow.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/glow.lua b/lua/glow.lua index 63547bc..9b5781a 100644 --- a/lua/glow.lua +++ b/lua/glow.lua @@ -24,10 +24,10 @@ local glow = {} ---@field pager boolean display output in pager style ---@field width integer floating window width ---@field height integer floating window height ----@field filetypes table allowed filetypes ----@field extra_filetypes table aditional filetypes ----@field extensions table allowed extensions ----@field extra_extensions table aditional extensions +---@field filetypes string[] allowed filetypes +---@field extra_filetypes string[]|nil aditional filetypes +---@field extensions string[] allowed extensions +---@field extra_extensions string[]|nil aditional extensions -- default configurations local config = { glow_path = vim.fn.exepath("glow"), @@ -233,7 +233,7 @@ end ---@return boolean local function is_md_ft() - local allowed_fts = vim.tbl_deep_extend("force", glow.config.filetypes, glow.config.extra_filetypes) + local allowed_fts = vim.tbl_deep_extend("force", {}, glow.config.filetypes, glow.config.extra_filetypes or {}) if not vim.tbl_contains(allowed_fts, vim.bo.filetype) then return false end @@ -242,7 +242,7 @@ end ---@return boolean local function is_md_ext(ext) - local allowed_exts = vim.tbl_deep_extend("force", glow.config.extensions, glow.config.extra_extensions) + local allowed_exts = vim.tbl_deep_extend("force", {}, glow.config.extensions, glow.config.extra_extensions or {}) if not vim.tbl_contains(allowed_exts, string.lower(ext)) then return false end