-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(commands/doc): fix title rendering, highlight codeblocks
- Loading branch information
1 parent
f3eac9f
commit 42d86f2
Showing
2 changed files
with
39 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local lunacolors = require 'lunacolors' | ||
|
||
local M = {} | ||
|
||
function M.highlight(text) | ||
return text:gsub('\'.-\'', lunacolors.yellow) | ||
--:gsub('%-%- .-', lunacolors.black) | ||
end | ||
|
||
function M.renderCodeBlock(text) | ||
local longest = 0 | ||
local lines = string.split(text:gsub('\t', ' '), '\n') | ||
|
||
for i, line in ipairs(lines) do | ||
local len = line:len() | ||
if len > longest then longest = len end | ||
end | ||
|
||
for i, line in ipairs(lines) do | ||
lines[i] = M.highlight(line:sub(0, longest)) | ||
.. string.rep(' ', longest - line:len()) | ||
end | ||
|
||
return '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n' | ||
end | ||
|
||
return M |