summaryrefslogtreecommitdiff
path: root/lua/rafta.lua
blob: b3483a48ccb3c44be2e13a199f17ed8b1fbe91c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local M = {}

M.setup = function()
  -- nothing
end

---@class rafta.Slides
---@fields slides string[]: The slides of the file

--- Takes some lines and parses them
---@param lines string[]: The lines in the buffer
---@return rafta.Slides
local parse_slides = function(lines)
  local current_slide = {}
  local sep = "^#"

  local slides = { slides = {} }
  for _, line in ipairs(lines) do
    print(line, "find:", line:find(sep), "|")
    if line:find(sep) then
      if #current_slide > 0 then
        table.insert(slides.slides, current_slide)
      end
      current_slide = {}
    end
    table.insert(current_slide, line)
  end
  table.insert(slides.slides, current_slide)
  return slides
end

vim.print(parse_slides({
  "# Hello",
  "this is something else",
  "# World",
  "this is another thing",
}))

return M