|
1 | 1 | local callout = require('render-markdown.callout') |
| 2 | +local icons = require('render-markdown.icons') |
2 | 3 | local list = require('render-markdown.list') |
3 | 4 | local logger = require('render-markdown.logger') |
4 | 5 | local state = require('render-markdown.state') |
@@ -55,12 +56,39 @@ M.render_node = function(namespace, buf, capture, node) |
55 | 56 | virt_text_pos = 'overlay', |
56 | 57 | }) |
57 | 58 | elseif capture == 'code' then |
| 59 | + if state.config.code_style == 'none' then |
| 60 | + return |
| 61 | + end |
| 62 | + |
58 | 63 | vim.api.nvim_buf_set_extmark(buf, namespace, start_row, 0, { |
59 | 64 | end_row = end_row, |
60 | 65 | end_col = 0, |
61 | 66 | hl_group = highlights.code, |
62 | 67 | hl_eol = true, |
63 | 68 | }) |
| 69 | + |
| 70 | + if state.config.code_style ~= 'full' then |
| 71 | + return |
| 72 | + end |
| 73 | + |
| 74 | + local info = ts.child(node, 'info_string') |
| 75 | + if info == nil then |
| 76 | + return |
| 77 | + end |
| 78 | + local language = vim.treesitter.get_node_text(info, buf) |
| 79 | + local icon, icon_highlight = icons.get(language) |
| 80 | + if icon == nil or icon_highlight == nil then |
| 81 | + return |
| 82 | + end |
| 83 | + local icon_text = { icon .. ' ', { icon_highlight, highlights.code } } |
| 84 | + -- language takes care of info_string so padding needs to take care of code block start, i.e. ``` |
| 85 | + -- subtract space taken up by icon and pad the remainder |
| 86 | + local padding = string.rep(' ', 3 - vim.fn.strdisplaywidth(icon_text[1])) |
| 87 | + local language_text = { language .. padding, { 'Normal', highlights.code } } |
| 88 | + vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, { |
| 89 | + virt_text = { icon_text, language_text }, |
| 90 | + virt_text_pos = 'overlay', |
| 91 | + }) |
64 | 92 | elseif capture == 'list_marker' then |
65 | 93 | if ts.sibling(node, { 'task_list_marker_unchecked', 'task_list_marker_checked' }) ~= nil then |
66 | 94 | -- Hide the list marker for checkboxes rather than replacing with a bullet point |
@@ -145,7 +173,7 @@ M.render_node = function(namespace, buf, capture, node) |
145 | 173 | local delim_value = vim.treesitter.get_node_text(delim, buf) |
146 | 174 | local delim_width = get_table_row_width(delim_row, delim_value) |
147 | 175 |
|
148 | | - local lines = vim.api.nvim_buf_get_lines(buf, start_row, end_row, false) |
| 176 | + local lines = vim.api.nvim_buf_get_lines(buf, start_row, end_row, true) |
149 | 177 | local start_width = get_table_row_width(start_row, list.first(lines)) |
150 | 178 | local end_width = get_table_row_width(end_row - 1, list.last(lines)) |
151 | 179 |
|
|
0 commit comments