aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--README.md2
-rw-r--r--manifest.json4
-rw-r--r--plugins/ghmarkdown.lua29
3 files changed, 30 insertions, 5 deletions
diff --git a/README.md b/README.md
index 75d18b2..2b72b7e 100644
--- a/README.md
+++ b/README.md
@@ -89,7 +89,7 @@ but only with a `url` must provide a `checksum` that matches the existing plugin
| [`fontconfig`](plugins/fontconfig.lua?raw=1) | Allows users to load fonts with [fontconfig](https://www.freedesktop.org/software/fontconfig/fontconfig-user.html). |
| [`force_syntax`](plugins/force_syntax.lua?raw=1) | Change the syntax used for a file. |
| [`formatter`](https://github.com/vincens2005/lite-formatters)\* | formatters for various languages |
-| [`ghmarkdown`](plugins/ghmarkdown.lua?raw=1) | Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))* Note: the page content is generated by sending the markdown file to Github's markdown rendering [API](https://docs.github.com/en/rest/markdown?apiVersion=2022-11-28) |
+| [`ghmarkdown`](plugins/ghmarkdown.lua?raw=1) | Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))* Note: the page content is generated by sending the markdown file to Github's markdown rendering [API](https://docs.github.com/en/rest/markdown?apiVersion=2022-11-28). Requires a [GitHub token](https://docs.github.com/en/rest/markdown/markdown?apiVersion=2022-11-28#render-a-markdown-document-in-raw-mode) being provided |
| [`gitblame`](https://github.com/juliardi/lite-xl-gitblame)\* | Shows "git blame" information of a line *([screenshot](https://raw.githubusercontent.com/juliardi/lite-xl-gitblame/main/screenshot_1.png))* |
| [`gitdiff_highlight`](https://github.com/vincens2005/lite-xl-gitdiff-highlight)\* | highlight changed lines from git *([screenshot](https://raw.githubusercontent.com/vincens2005/lite-xl-gitdiff-highlight/master/screenshot.png))* |
| [`gitopen`](plugins/gitopen.lua?raw=1) | Open project files that are in a git commit (default=HEAD) |
diff --git a/manifest.json b/manifest.json
index cf8c9f5..f58c0ba 100644
--- a/manifest.json
+++ b/manifest.json
@@ -481,8 +481,8 @@
"id": "formatter"
},
{
- "description": "Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))* Note: the page content is generated by sending the markdown file to Github's markdown rendering [API](https://docs.github.com/en/rest/markdown?apiVersion=2022-11-28)",
- "version": "0.1",
+ "description": "Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))* Note: the page content is generated by sending the markdown file to Github's markdown rendering [API](https://docs.github.com/en/rest/markdown?apiVersion=2022-11-28). Requires a [GitHub token](https://docs.github.com/en/rest/markdown/markdown?apiVersion=2022-11-28#render-a-markdown-document-in-raw-mode) being provided",
+ "version": "0.2",
"path": "plugins/ghmarkdown.lua",
"id": "ghmarkdown",
"mod_version": "3"
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")