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

Add language_map option #7

Merged
merged 5 commits into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lua/carbon-now.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
local types = require("types")
local carbon = {}

-- map some known filetypes to carbon.now.sh supported languages
--- list of supported languages: https://github.com/carbon-app/carbon/blob/2cbdcd0cc23d2d2f23736dd3cfbe94134b141191/lib/constants.js#L624-L1048
local language_map = {
typescriptreact = "typescript",
javascriptreact = "javascript",
}

-- default config
---@type cn.ConfigSchema
carbon.config = {
Expand Down Expand Up @@ -62,11 +69,12 @@ end
---validate config param values and create the query params table
local function get_carbon_now_snapshot_uri(code)
local opts = carbon.config.options
local ft = vim.bo.filetype

-- carbon.now.sh parameters
local params = {
t = opts.theme,
l = vim.bo.filetype,
l = language_map[ft] or ft,
wt = opts.window_theme,
fm = opts.font_family,
fs = opts.font_size,
Expand Down Expand Up @@ -146,4 +154,4 @@ carbon.setup = function(params)
create_commands()
end

return carbon
return carbon