Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#138): added configurable fts and exts #140

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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"),
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 or {})
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 or {})
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