Skip to content

Commit

Permalink
feat(ellisonleao#138): added configurable fts and exts
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed May 3, 2024
1 parent 238070a commit 372eb7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</p>
<img src="https://img.shields.io/badge/Made%20with%20Lua-blueviolet.svg?style=for-the-badge&logo=lua" />
<img src="https://img.shields.io/github/actions/workflow/status/ellisonleao/glow.nvim/default.yml?style=for-the-badge" />

</div>

https://user-images.githubusercontent.com/178641/215353259-eb8688fb-5600-4b95-89a2-0f286e3b6441.mp4
<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**

Expand Down Expand Up @@ -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 = {},
}
```

Expand Down
12 changes: 10 additions & 2 deletions lua/glow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/glow/glow_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 372eb7e

Please sign in to comment.