|
1 |
| -local htmlEntities = require("html-entities.htmlEntities") |
| 1 | +local htmlEntities = require('html-entities.htmlEntities') |
2 | 2 |
|
3 | 3 | local he = {}
|
4 | 4 |
|
5 | 5 | -- This function is supposed to be called explicitly by users to configure this
|
6 | 6 | -- plugin
|
7 | 7 | function he.setup()
|
8 |
| - -- avoid setting global values outside of this function. Global state |
9 |
| - -- mutations are hard to debug and test, so having them in a single |
10 |
| - -- function/module makes it easier to reason about all possible changes |
11 |
| - -- he.options = with_defaults(options) |
12 |
| - |
13 |
| - -- do here any startup your plugin needs, like creating commands and |
14 |
| - -- mappings that depend on values passed in options |
15 |
| - vim.api.nvim_create_user_command("HtmlEncode", he.encode, {}) |
16 |
| - vim.api.nvim_create_user_command("HtmlDecode", he.decode, {}) |
| 8 | + -- avoid setting global values outside of this function. Global state |
| 9 | + -- mutations are hard to debug and test, so having them in a single |
| 10 | + -- function/module makes it easier to reason about all possible changes |
| 11 | + -- he.options = with_defaults(options) |
| 12 | + |
| 13 | + -- do here any startup your plugin needs, like creating commands and |
| 14 | + -- mappings that depend on values passed in options |
| 15 | + vim.api.nvim_create_user_command('HtmlEncode', he.encode, {}) |
| 16 | + vim.api.nvim_create_user_command('HtmlDecode', he.decode, {}) |
17 | 17 | end
|
18 | 18 |
|
19 | 19 | function he.encode()
|
20 |
| - local buf = vim.api.nvim_buf_get_lines(0, 0, -1, false) |
21 |
| - |
22 |
| - local encodedBuf = {} |
23 |
| - local eob = 0; |
24 |
| - for n,line in pairs(buf) do |
25 |
| - --encode |
26 |
| - if (line ~= nil and line ~= '' and line ~='\n') then |
27 |
| - local encodedLine = htmlEntities.encode(line) |
28 |
| - encodedBuf[n] = encodedLine |
29 |
| - else |
30 |
| - encodedBuf[n] = '' |
31 |
| - end |
32 |
| - eob = n |
33 |
| - end |
34 |
| - --update the buffer |
35 |
| - vim.api.nvim_buf_set_lines(0, 0, eob, false, encodedBuf) |
| 20 | + local buf = vim.api.nvim_buf_get_lines(0, 0, -1, false) |
| 21 | + |
| 22 | + local encodedBuf = {} |
| 23 | + local eob = 0 |
| 24 | + for n, line in pairs(buf) do |
| 25 | + --encode |
| 26 | + if line ~= nil and line ~= '' and line ~= '\n' then |
| 27 | + local encodedLine = htmlEntities.encode(line) |
| 28 | + encodedBuf[n] = encodedLine |
| 29 | + else |
| 30 | + encodedBuf[n] = '' |
| 31 | + end |
| 32 | + eob = n |
| 33 | + end |
| 34 | + --update the buffer |
| 35 | + vim.api.nvim_buf_set_lines(0, 0, eob, false, encodedBuf) |
36 | 36 | end
|
37 | 37 |
|
38 | 38 | function he.decode()
|
39 |
| - local buf = vim.api.nvim_buf_get_lines(0, 0, -1, false) |
40 |
| - |
41 |
| - local decodedBuf = {} |
42 |
| - local eob = 0; |
43 |
| - for n,line in pairs(buf) do |
44 |
| - --decode |
45 |
| - if (line ~= nil and line ~= '' and line ~='\n') then |
46 |
| - local decodedLine = htmlEntities.decode(line) |
47 |
| - decodedBuf[n] = decodedLine |
48 |
| - else |
49 |
| - decodedBuf[n] = '' |
50 |
| - end |
51 |
| - eob = n |
52 |
| - end |
53 |
| - --update the buffer |
54 |
| - vim.api.nvim_buf_set_lines(0, 0, eob, false, decodedBuf) |
| 39 | + local buf = vim.api.nvim_buf_get_lines(0, 0, -1, false) |
| 40 | + |
| 41 | + local decodedBuf = {} |
| 42 | + local eob = 0 |
| 43 | + for n, line in pairs(buf) do |
| 44 | + --decode |
| 45 | + if line ~= nil and line ~= '' and line ~= '\n' then |
| 46 | + local decodedLine = htmlEntities.decode(line) |
| 47 | + decodedBuf[n] = decodedLine |
| 48 | + else |
| 49 | + decodedBuf[n] = '' |
| 50 | + end |
| 51 | + eob = n |
| 52 | + end |
| 53 | + --update the buffer |
| 54 | + vim.api.nvim_buf_set_lines(0, 0, eob, false, decodedBuf) |
55 | 55 | end
|
56 | 56 |
|
57 | 57 | he.options = nil
|
|
0 commit comments