mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-07 21:15:03 +00:00

Some checks failed
tinymist::ci / Duplicate Actions Detection (push) Has been cancelled
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Has been cancelled
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Has been cancelled
tinymist::ci / prepare-build (push) Has been cancelled
tinymist::gh_pages / build-gh-pages (push) Has been cancelled
tinymist::ci / build-vsc-assets (push) Has been cancelled
tinymist::ci / build-vscode (push) Has been cancelled
tinymist::ci / build-vscode-others (push) Has been cancelled
tinymist::ci / publish-vscode (push) Has been cancelled
tinymist::ci / build-binary (push) Has been cancelled
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Has been cancelled
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Has been cancelled
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Has been cancelled
tinymist::ci / E2E Tests (win32-x64 on windows-2019) (push) Has been cancelled
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Has been cancelled
* fix: bad link * feat(neovim): init lsp * feat(neovim): add bootstrap script * build: add notice
29 lines
764 B
Lua
29 lines
764 B
Lua
local text = {}
|
|
|
|
local function max_common_indent(str)
|
|
local _, _, common_indent, rest = str:find '^(%s*)(.*)'
|
|
local common_indent_len = #common_indent
|
|
local len
|
|
for indent in rest:gmatch '\n( +)' do
|
|
len = #indent
|
|
if len < common_indent_len then
|
|
common_indent, common_indent_len = indent, len
|
|
end
|
|
end
|
|
return common_indent
|
|
end
|
|
|
|
---Dedent a multi-line string.
|
|
---@param str string
|
|
function text.dedent(str)
|
|
str = str:gsub('\n *$', '\n') -- trim leading/trailing space
|
|
local prefix = max_common_indent(str)
|
|
return str:gsub('^' .. prefix, ''):gsub('\n' .. prefix, '\n')
|
|
end
|
|
|
|
---Build a single-line string out a multiline one, replacing \n with spaces.
|
|
function text.s(str)
|
|
return text.dedent(str):gsub('\n', ' ')
|
|
end
|
|
|
|
return text
|