ALT-F4-LLC / ALT-F4-LLC/notion.nvim
Bug: 400 Validation Error on sync when markdown code block language has uppercase letters or trailing whitespace
- Dominant language
- Lua
- Stars
- 16
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
When syncing a Neovim buffer to Notion, if a code block contains capital letters or accidental trailing whitespace the plugin crashes with a `Failed to sync to Notion` message.
The error message return was
```
Notion API error: {"object":"error","status":400,"code":"validation_error","message":"body failed validation: body.children[16].code.language should be `\"abap\"`, `\"abc\"`, `\"agda\"`, `\"arduino\"`, `\"ascii art\"`, `\"assembly\"`, `\"bash\"`, `\"basic\"`, `\"bnf\"`, `\"c\"`, `\"c#\"`, `\"c++\"`, `\"clojure\"`, `\"coffeescript\"`, `\"coq\"`, `\"css\"`, `\"dart\"`, `\"dhall\"`, `\"diff\"`, `\"docker\"`, `\"ebnf\"`, `\"elixir\"`, `\"elm\"`, `\"erlang\"`, `\"f#\"`, `\"flow\"`, `\"fortran\"`, `\"gherkin\"`, `\"glsl\"`, `\"go\"`, `\"graphql\"`, `\"groovy\"`, `\"haskell\"`, `\"hcl\"`, `\"html\"`, `\"idris\"`, `\"java\"`, `\"javascript\"`, `\"json\"`, `\"julia\"`, `\"kotlin\"`, `\"latex\"`, `\"less\"`, `\"lisp\"`, `\"livescript\"`, `\"llvm ir\"`, `\"lua\"`, `\"makefile\"`, `\"markdown\"`, `\"markup\"`, `\"matlab\"`, `\"mathematica\"`, `\"mermaid\"`, `\"nix\"`, `\"notion formula\"`, `\"objective-c\"`, `\"ocaml\"`, `\"pascal\"`, `\"perl\"`, `\"php\"`, `\"plain text\"`, `\"powershell\"`, `\"prolog\"`, `\"protobuf\"`, `\"purescript\"`, `\"python\"`, `\"r\"`, `\"racket\"`, `\"reason\"`, `\"ruby\"`, `\"rust\"`, `\"sass\"`, `\"scala\"`, `\"scheme\"`, `\"scss\"`, `\"shell\"`, `\"smalltalk\"`, `\"solidity\"`, `\"sql\"`, `\"swift\"`, `\"toml\"`, `\"typescript\"`, `\"vb.net\"`, `\"verilog\"`, `\"vhdl\"`, `\"visual basic\"`, `\"webassembly\"`, `\"xml\"`, `\"yaml\"`, or `\"java/c/c++/c#\"`, instead was `\"lua \"`.","request_id":"3b27fd0a-2905-4e0e-ace6-2b5920a915ec"}
```
### to reproduce
Create a new test buffer
Create a code block Inside it
for the name/type of language start it with capital letters like Lua
### Expected
plugin should be able to automatically sanitize it as normal markdown parsers and preview accept them and is a bit of a hassle to debug
### Proposed Solution
In `lua/notion/api.lua`, when parsing the code block language, the string should be lowercased and trimmed.
Changing line 1310 inside the function markdown_to_blocks in api.lua:
```lua
code_language = line:sub(4) or ""
```
To this:
```lua
code_language = vim.trim(string.lower(line:sub(4) or ""))
```
resolves the issue for me
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.