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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
-- html snippets
function Snippets(snipType, value)
snippet = ""
if snipType == "comment" then
snippet = [[<!-- -->]]
elseif snipType == "tag" then
snippet = string.format("<%s></%s>", value, value)
elseif snipType == "linebreak" then
snippet = [[</br>]]
elseif snipType == "hrline" then
snippet = [[<hr/>]]
elseif snipType == "link" then
snippet = string.format([[<a href="%s">%s</a>]],
value["url"], value["label"]
)
elseif snipType == "pieces" then
if value == "document" then
snippet = [[
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="StyleSheetName.css"/>
</head>
<body>
</body>
</html>
]]
elseif value == "paper" then
snippet = [[
<style>
html {
background: #ffffd7;
}
</style>
]]
end
end
return snippet
end
function JumpInTag()
vim.cmd("normal! f>l")
end
-- keymaps to insert snippets
vim.keymap.set('i', "<M-s><M-c>", function()
WriteText(Snippets("comment"))
end, {noremap=true})
vim.keymap.set('i', "<M-s><M-i>", function()
WriteText(Snippets("tag", "i"))
JumpInTag()
end, {noremap=true})
vim.keymap.set('i', "<M-s><M-b>", function()
WriteText(Snippets("tag", "b"))
JumpInTag()
end, {noremap=true})
vim.keymap.set('i', "<M-s><M-/>", function()
WriteText(Snippets("linebreak"))
end, {noremap=true})
vim.keymap.set('i', "<M-s><M-->", function()
WriteText(Snippets("hrline"))
end, {noremap=true})
vim.keymap.set('i', "<M-s><M-t>", function()
inp = vim.fn.input("Tag: ", "", "file")
WriteText(Snippets("tag", inp))
JumpInTag()
end, {remap=true})
vim.keymap.set('i', "<M-s><M-l>", function()
url = vim.fn.input("URL: ", "", "file")
label = vim.fn.input("label: ", "", "file")
value = {}
value.url = url
value.label = label
WriteText(
Snippets("link", value)
)
JumpInTag()
end, {remap=true})
vim.keymap.set('i', "<M-s><M-d>", function()
dt = os.date("%Y/%m/%d")
WriteText(dt)
end)
vim.keymap.set('i', "<M-s><M-p>", function()
name = vim.fn.input("name: ", "", "file")
WriteLines(
StrSplit(Snippets("pieces", name), '\n')
)
end)
|