aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Sokianos <walkero@gmail.com>2024-03-10 20:45:50 +0000
committerGitHub <noreply@github.com>2024-03-10 21:45:50 +0100
commit67349dcc4270d76641c0a2edbaa614781ed885ed (patch)
treea0a5d38fb563483168f1f59b3f895df8918be676 /plugins
parent90567c64fd7e0dac23c99054f25cfd2d084ede7d (diff)
downloadlite-xl-plugins-67349dcc4270d76641c0a2edbaa614781ed885ed.tar.gz
lite-xl-plugins-67349dcc4270d76641c0a2edbaa614781ed885ed.zip
Fixing ghmarkdown adding the ability to use a GitHub token (#380)
* Fixing ghmarkdown adding the ability to use a GitHub token * Updated the manifest.json file
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ghmarkdown.lua29
1 files changed, 27 insertions, 2 deletions
diff --git a/plugins/ghmarkdown.lua b/plugins/ghmarkdown.lua
index c7fabdd..03ed08a 100644
--- a/plugins/ghmarkdown.lua
+++ b/plugins/ghmarkdown.lua
@@ -1,8 +1,25 @@
-- mod-version:3
local core = require "core"
local command = require "core.command"
+local common = require "core.common"
+local config = require "core.config"
local keymap = require "core.keymap"
+config.plugins.ghmarkdown = common.merge({
+ -- Find information on how to generate your own token at
+ -- https://docs.github.com/en/rest/markdown/markdown?apiVersion=2022-11-28#render-a-markdown-document-in-raw-mode
+ github_token = "",
+ config_spec = {
+ name = "GHMarkdown",
+ {
+ label = "GitHub token",
+ description = "Enter your personal GitHub token",
+ path = "github_token",
+ type = "string",
+ default = ""
+ }
+ }
+}, config.plugins.ghmarkdown)
local html = [[
<html>
@@ -31,7 +48,9 @@ local html = [[
<script>
var xhr = new XMLHttpRequest;
xhr.open("POST", "https://api.github.com/markdown/raw");
- xhr.setRequestHeader("Content-Type", "text/plain");
+ xhr.setRequestHeader("content-type", "text/plain");
+ xhr.setRequestHeader("authorization", "Bearer ${token}");
+ xhr.setRequestHeader("x-github-api-version", "2022-11-28");
xhr.onload = function() { document.body.innerHTML = xhr.responseText; };
xhr.send("${content}");
</script>
@@ -42,11 +61,17 @@ local html = [[
command.add("core.docview!", {
["ghmarkdown:show-preview"] = function(dv)
+ if config.plugins.ghmarkdown.github_token == "" then
+ core.error "You need to provide your own GitHub token"
+ return
+ end
+
local content = dv.doc:get_text(1, 1, math.huge, math.huge)
local esc = { ['"'] = '\\"', ["\n"] = '\\n' }
local text = html:gsub("${(.-)}", {
title = dv:get_name(),
- content = content:gsub(".", esc)
+ content = content:gsub(".", esc),
+ token = config.plugins.ghmarkdown.github_token
})
local htmlfile = core.temp_filename(".html")