diff --git a/lua/gx/handler.lua b/lua/gx/handler.lua index 25f1311..8880cc7 100644 --- a/lua/gx/handler.lua +++ b/lua/gx/handler.lua @@ -8,6 +8,7 @@ local go_handler = require("gx.handlers.go") local commit_handler = require("gx.handlers.commit") local markdown_handler = require("gx.handlers.markdown") local cve_handler = require("gx.handlers.cve") +local python_pep_handler = require("gx.handlers.python-pep") local search_handler = require("gx.handlers.search") local M = {} @@ -48,6 +49,7 @@ local function resolve_handlers(handlers) add_handler(resolved, go_handler, handlers.go and exists.go == nil) add_handler(resolved, markdown_handler, handlers.markdown and exists.markdown == nil) add_handler(resolved, cve_handler, handlers.cve and exists.cve == nil) + add_handler(resolved, python_pep_handler, handlers.python_pep and exists.python_pep == nil) add_handler(resolved, url_handler, handlers.url and exists.url == nil) add_handler(resolved, search_handler, handlers.search and exists.search == nil) -- ### diff --git a/lua/gx/handlers/python-pep.lua b/lua/gx/handlers/python-pep.lua new file mode 100644 index 0000000..005dd65 --- /dev/null +++ b/lua/gx/handlers/python-pep.lua @@ -0,0 +1,18 @@ +local helper = require("gx.helper") + +---@type GxHandler +local M = { + name = "python-pep", + filetype = nil, + filename = nil, +} + +function M.handle(mode, line, _) + local id = helper.find(line, mode, "PEP%s?-?(%d+)") + if not id then + return + end + return "https://peps.python.org/" .. "pep-" .. id +end + +return M diff --git a/test/spec/gx/handlers/python-pep_spec.lua b/test/spec/gx/handlers/python-pep_spec.lua new file mode 100644 index 0000000..5861710 --- /dev/null +++ b/test/spec/gx/handlers/python-pep_spec.lua @@ -0,0 +1,13 @@ +local handler = require("gx.handlers.python-pep") + +describe("python-pep_handler_does_work", function() + it("python-pep", function() + assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP-484")) + end) + it("python-pep", function() + assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP484")) + end) + it("python-pep", function() + assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP 484")) + end) +end)