feat(block): normalize markdown code-fence aliases to Notion's enum#28
Merged
Conversation
Markdown / LLM output routinely uses short language labels (`ts`, `sh`,
`yml`, `py`, …) that the Notion API rejects because code.language is a
fixed enum. Previously every such fence hard-failed the whole PATCH with:
body.children[N].code.language should be "abap", ..., "typescript",
"yaml", or "java/c/c++/c#", instead was "ts".
Introduce `normalizeCodeLanguage`:
- passes through any value that's already in the Notion enum,
- maps ~50 common aliases (ts→typescript, sh→shell, yml→yaml, py→python,
cpp→c++, cs→c#, dockerfile→docker, md→markdown, proto→protobuf, …),
- for unknown values, falls back to 'plain text' and emits a one-line
stderr warning so a single unrecognized fence can't break a long doc.
Applied to both markdown parsing (`notion block append --file`) and the
`--lang` flag on inline append/insert, so CLI-typed aliases like
`--lang ts` also work.
Closes #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stop
notion block append --filefrom hard-failing on the common short language labels modern editors and LLMs emit (ts,sh,yml,py,dockerfile, …).Why
Tracked in #22. Notion's
code.languageis a fixed enum. Before this PR, a singletsfence in an otherwise-valid markdown file produced a ~10-line enum dump and rejected the entire PATCH.Changes
New file
cmd/code_lang.go:notionCodeLanguages— the full accepted enum.codeLangAliases— ~50 common labels mapped to their canonical form (ts→typescript,sh→shell,yml→yaml,cpp→c++,cs→c#,proto→protobuf,dockerfile→docker, etc.).normalizeCodeLanguage(raw):plain text+ one-line stderr warning for unknown values (so a single bad fence can't break a 150-block document).Wired into both markdown parsing and the
--langflag on inline append/insert.Test plan
ts/sh/ymlnow parses totypescript/shell/yaml.Closes #22