From b8d72e6452e67e0657269333cf95df020e03ccf1 Mon Sep 17 00:00:00 2001 From: psychhim Date: Thu, 9 Oct 2025 17:28:45 +0530 Subject: [PATCH] Fix: HTML snippets of VSCode friendly snippets --- init.lua | 8 +- lua/custom_html_snippets.json | 783 ++++++++++++++++++++++++++++++++++ lua/replace_html_snippets.lua | 50 +++ 3 files changed, 837 insertions(+), 4 deletions(-) create mode 100644 lua/custom_html_snippets.json create mode 100644 lua/replace_html_snippets.lua diff --git a/init.lua b/init.lua index afc1f4a..bbbb535 100644 --- a/init.lua +++ b/init.lua @@ -271,6 +271,9 @@ require('lazy').setup({ -- custom/keymaps.lua file require 'keymaps' +-- HTML snippet fixer +require 'replace_html_snippets' + -- [[ Setting options ]] -- See `:help vim.o` @@ -522,10 +525,9 @@ mason_lspconfig.setup { -- See `:help cmp` local cmp = require 'cmp' local luasnip = require 'luasnip' ---require("luasnip.loaders.from_vscode").lazy_load() +require('luasnip.loaders.from_vscode').lazy_load() --require('luasnip.loaders.from_vscode').lazy_load({ paths = { "~/.config/nvim/my_snippets" } }) luasnip.config.setup {} - cmp.setup { snippet = { expand = function(args) @@ -570,8 +572,6 @@ cmp.setup { { name = 'path' }, }, } ---Load Luasnip.loaders -require('luasnip.loaders.from_vscode').lazy_load() -- Theme require('kanagawa').setup { transparent = true } diff --git a/lua/custom_html_snippets.json b/lua/custom_html_snippets.json new file mode 100644 index 0000000..7debe58 --- /dev/null +++ b/lua/custom_html_snippets.json @@ -0,0 +1,783 @@ +{ + "!": { + "prefix": "", + "", + "", + "\t", + "\t", + "\t${5:Document}", + "", + "", + "\t${6}", + "", + "" + ], + "description": "HTML - Defines a template for a html5 document", + "scope": "text.html" + }, + "doctype": { + "prefix": "", "$1"], + "description": "HTML - Defines the document type", + "scope": "text.html" + }, + "a": { + "prefix": "$2$3", + "description": "HTML - Defines a hyperlink", + "scope": "text.html" + }, + "abbr": { + "prefix": "$2$3", + "description": "HTML - Defines an abbreviation", + "scope": "text.html" + }, + "address": { + "prefix": "", "$1", ""], + "description": "HTML - Defines an address element", + "scope": "text.html" + }, + "area": { + "prefix": "$5", + "description": "HTML - Defines an area inside an image map", + "scope": "text.html" + }, + "article": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines an article", + "scope": "text.html" + }, + "aside": { + "prefix": "", "\t$1", "$2"], + "description": "HTML - Defines content aside from the page content", + "scope": "text.html" + }, + "audio": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines sounds content", + "scope": "text.html" + }, + "b": { + "prefix": "$1$2", + "description": "HTML - Defines bold text", + "scope": "text.html" + }, + "base": { + "prefix": "$3", + "description": "HTML - Defines a base URL for all the links in a page", + "scope": "text.html" + }, + "bdi": { + "prefix": "$1$2", + "description": "HTML - Used to isolate text that is of unknown directionality", + "scope": "text.html" + }, + "bdo": { + "prefix": "", "$2", ""], + "description": "HTML - Defines the direction of text display", + "scope": "text.html" + }, + "big": { + "prefix": "$1$2", + "description": "HTML - Used to make text bigger", + "scope": "text.html" + }, + "blockquote": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a long quotation", + "scope": "text.html" + }, + "body": { + "prefix": "", "\t$0", ""], + "description": "HTML - Defines the body element", + "scope": "text.html" + }, + "br": { + "prefix": "", + "description": "HTML - Inserts a single line break", + "scope": "text.html" + }, + "button": { + "prefix": "$2$3", + "description": "HTML - Defines a push button", + "scope": "text.html" + }, + "canvas": { + "prefix": "$2$3", + "description": "HTML - Defines graphics", + "scope": "text.html" + }, + "caption": { + "prefix": "$1$2", + "description": "HTML - Defines a table caption", + "scope": "text.html" + }, + "cite": { + "prefix": "$1$2", + "description": "HTML - Defines a citation", + "scope": "text.html" + }, + "code": { + "prefix": "$1$2", + "description": "HTML - Defines computer code text", + "scope": "text.html" + }, + "col": { + "prefix": "$2", + "description": "HTML - Defines attributes for table columns", + "scope": "text.html" + }, + "colgroup": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines group of table columns", + "scope": "text.html" + }, + "command": { + "prefix": "$1$2", + "description": "HTML - Defines a command button [not supported]", + "scope": "text.html" + }, + "datalist": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a dropdown list", + "scope": "text.html" + }, + "dd": { + "prefix": "$1$2", + "description": "HTML - Defines a definition description", + "scope": "text.html" + }, + "del": { + "prefix": "$1$2", + "description": "HTML - Defines deleted text", + "scope": "text.html" + }, + "details": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines details of an element", + "scope": "text.html" + }, + "dialog": { + "prefix": "$1$2", + "description": "HTML - Defines a dialog (conversation)", + "scope": "text.html" + }, + "dfn": { + "prefix": "$1$2", + "description": "HTML - Defines a definition term", + "scope": "text.html" + }, + "div": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a section in a document", + "scope": "text.html" + }, + "dl": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a definition list", + "scope": "text.html" + }, + "dt": { + "prefix": "$1$2", + "description": "HTML - Defines a definition term", + "scope": "text.html" + }, + "em": { + "prefix": "$1$2", + "description": "HTML - Defines emphasized text", + "scope": "text.html" + }, + "embed": { + "prefix": "$2", + "description": "HTML - Defines external interactive content ot plugin", + "scope": "text.html" + }, + "fieldset": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a fieldset", + "scope": "text.html" + }, + "figcaption": { + "prefix": "$1$2", + "description": "HTML - Defines a caption for a figure", + "scope": "text.html" + }, + "figure": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a group of media content, and their caption", + "scope": "text.html" + }, + "footer": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a footer for a section or page", + "scope": "text.html" + }, + "form": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a form", + "scope": "text.html" + }, + "h1": { + "prefix": "$1$2", + "description": "HTML - Defines header 1", + "scope": "text.html" + }, + "h2": { + "prefix": "$1$2", + "description": "HTML - Defines header 2", + "scope": "text.html" + }, + "h3": { + "prefix": "$1$2", + "description": "HTML - Defines header 3", + "scope": "text.html" + }, + "h4": { + "prefix": "$1$2", + "description": "HTML - Defines header 4", + "scope": "text.html" + }, + "h5": { + "prefix": "$1$2", + "description": "HTML - Defines header 5", + "scope": "text.html" + }, + "h6": { + "prefix": "$1$2", + "description": "HTML - Defines header 6", + "scope": "text.html" + }, + "head": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines information about the document", + "scope": "text.html" + }, + "header": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a header for a section of page", + "scope": "text.html" + }, + "hgroup": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines information about a section in a document", + "scope": "text.html" + }, + "hr": { + "prefix": "", + "description": "HTML - Defines a horizontal rule", + "scope": "text.html" + }, + "html": { + "prefix": "", "\t$0", ""], + "description": "HTML - Defines an html document", + "scope": "text.html" + }, + "html5": { + "prefix": "", + "", + "\t", + "\t\t", + "\t\t", + "\t\t$2", + "\t\t", + "\t", + "\t", + "\t$0", + "\t", + "" + ], + "description": "HTML - Defines a template for a html5 document", + "scope": "text.html" + }, + "i": { + "prefix": "$1$2", + "description": "HTML - Defines italic text", + "scope": "text.html" + }, + "iframe": { + "prefix": "$2$3", + "description": "HTML - Defines an inline sub window", + "scope": "text.html" + }, + "img": { + "prefix": "$3", + "description": "HTML - Defines an image", + "scope": "text.html" + }, + "input": { + "prefix": "$4", + "description": "HTML - Defines an input field", + "scope": "text.html" + }, + "ins": { + "prefix": "$1$2", + "description": "HTML - Defines inserted text", + "scope": "text.html" + }, + "keygen": { + "prefix": "$2", + "description": "HTML - Defines a generated key in a form", + "scope": "text.html" + }, + "kbd": { + "prefix": "$1$2", + "description": "HTML - Defines keyboard text", + "scope": "text.html" + }, + "label": { + "prefix": "$2$3", + "description": "HTML - Defines an inline window", + "scope": "text.html" + }, + "legend": { + "prefix": "$1$2", + "description": "HTML - Defines a title in a fieldset", + "scope": "text.html" + }, + "li": { + "prefix": "$1$2", + "description": "HTML - Defines a list item", + "scope": "text.html" + }, + "link": { + "prefix": "$4", + "description": "HTML - Defines a resource reference", + "scope": "text.html" + }, + "main": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines an image map", + "scope": "text.html" + }, + "map": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines an image map", + "scope": "text.html" + }, + "mark": { + "prefix": "$1$2", + "description": "HTML - Defines marked text", + "scope": "text.html" + }, + "menu": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a menu list", + "scope": "text.html" + }, + "menuitem": { + "prefix": "$1$2", + "description": "HTML - Defines a menu item [firefox only]", + "scope": "text.html" + }, + "meta": { + "prefix": "$3", + "description": "HTML - Defines meta information", + "scope": "text.html" + }, + "meter": { + "prefix": "$2$3", + "description": "HTML - Defines measurement within a predefined range", + "scope": "text.html" + }, + "nav": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines navigation links", + "scope": "text.html" + }, + "noscript": { + "prefix": "", "$1", ""], + "description": "HTML - Defines a noscript section", + "scope": "text.html" + }, + "object": { + "prefix": "$4$5", + "description": "HTML - Defines an embedded object", + "scope": "text.html" + }, + "ol": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines an ordered list", + "scope": "text.html" + }, + "optgroup": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines an option group", + "scope": "text.html" + }, + "option": { + "prefix": "$2$3", + "description": "HTML - Defines an option in a drop-down list", + "scope": "text.html" + }, + "output": { + "prefix": "$3$4", + "description": "HTML - Defines some types of output", + "scope": "text.html" + }, + "p": { + "prefix": "$1

$2", + "description": "HTML - Defines a paragraph", + "scope": "text.html" + }, + "param": { + "prefix": "$3", + "description": "HTML - Defines a parameter for an object", + "scope": "text.html" + }, + "pre": { + "prefix": "$1"], + "description": "HTML - Defines preformatted text", + "scope": "text.html" + }, + "progress": { + "prefix": "$3$4", + "description": "HTML - Defines progress of a task of any kind", + "scope": "text.html" + }, + "q": { + "prefix": "$1$2", + "description": "HTML - Defines a short quotation", + "scope": "text.html" + }, + "rp": { + "prefix": "$1$2", + "description": "HTML - Used in ruby annotations to define what to show browsers that do not support the ruby element", + "scope": "text.html" + }, + "rt": { + "prefix": "$1$2", + "description": "HTML - Defines explanation to ruby annotations", + "scope": "text.html" + }, + "ruby": { + "prefix": "", "$1", ""], + "description": "HTML - Defines ruby annotations", + "scope": "text.html" + }, + "s": { + "prefix": "$1$2", + "description": "HTML - Used to define strikethrough text", + "scope": "text.html" + }, + "samp": { + "prefix": "$1$2", + "description": "HTML - Defines sample computer code", + "scope": "text.html" + }, + "script": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a script", + "scope": "text.html" + }, + "section": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a section", + "scope": "text.html" + }, + "select": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a selectable list", + "scope": "text.html" + }, + "small": { + "prefix": "$1$2", + "description": "HTML - Defines small text", + "scope": "text.html" + }, + "source": { + "prefix": "$3", + "description": "HTML - Defines media resource", + "scope": "text.html" + }, + "span": { + "prefix": "$1$2", + "description": "HTML - Defines a section in a document", + "scope": "text.html" + }, + "strong": { + "prefix": "$1$2", + "description": "HTML - Defines strong text", + "scope": "text.html" + }, + "style": { + "prefix": "", "$1", ""], + "description": "HTML - Defines a style definition", + "scope": "text.html" + }, + "sub": { + "prefix": "$1$2", + "description": "HTML - Defines sub-scripted text", + "scope": "text.html" + }, + "sup": { + "prefix": "$1$2", + "description": "HTML - Defines super-scripted text", + "scope": "text.html" + }, + "summary": { + "prefix": "$1$2", + "description": "HTML - Defines a visible heading for the detail element [limited support]", + "scope": "text.html" + }, + "table": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a table", + "scope": "text.html" + }, + "tbody": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a table body", + "scope": "text.html" + }, + "td": { + "prefix": "$1$2", + "description": "HTML - Defines a table cell", + "scope": "text.html" + }, + "textarea": { + "prefix": "$3$4", + "description": "HTML - Defines a text area", + "scope": "text.html" + }, + "tfoot": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines a table footer", + "scope": "text.html" + }, + "thead": { + "prefix": "", "$1", ""], + "description": "HTML - Defines a table head", + "scope": "text.html" + }, + "th": { + "prefix": "$1$2", + "description": "HTML - Defines a table header", + "scope": "text.html" + }, + "time": { + "prefix": "$2$3", + "description": "HTML - Defines a date/time", + "scope": "text.html" + }, + "title": { + "prefix": "$1$2", + "description": "HTML - Defines the document title", + "scope": "text.html" + }, + "tr": { + "prefix": "$1$2", + "description": "HTML - Defines a table row", + "scope": "text.html" + }, + "track": { + "prefix": "$5", + "description": "HTML - Defines a table row", + "scope": "text.html" + }, + "u": { + "prefix": "$1$2", + "description": "HTML - Used to define underlined text", + "scope": "text.html" + }, + "ul": { + "prefix": "", "\t$1", ""], + "description": "HTML - Defines an unordered list", + "scope": "text.html" + }, + "var": { + "prefix": "$1$2", + "description": "HTML - Defines a variable", + "scope": "text.html" + }, + "video": { + "prefix": "", "\t$3", ""], + "description": "HTML - Defines a video", + "scope": "text.html" + }, + "div.": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines a section in a document", + "scope": "text.html" + }, + "div#": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines a section in a document", + "scope": "text.html" + }, + "div.#": { + "prefix": "", "\t$3", ""], + "description": "HTML - Defines a section in a document", + "scope": "text.html" + }, + "p.": { + "prefix": "$2

"], + "description": "HTML - Defines a paragraph", + "scope": "text.html" + }, + "p#": { + "prefix": "$2

"], + "description": "HTML - Defines a paragraph", + "scope": "text.html" + }, + "p.#": { + "prefix": "$3

"], + "description": "HTML - Defines a paragraph", + "scope": "text.html" + }, + "ul.": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines an unordered list", + "scope": "text.html" + }, + "ul#": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines an unordered list", + "scope": "text.html" + }, + "ul.#": { + "prefix": "", "\t$3", ""], + "description": "HTML - Defines an unordered list", + "scope": "text.html" + }, + "ol.": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines an ordered list", + "scope": "text.html" + }, + "ol#": { + "prefix": "", "\t$2", ""], + "description": "HTML - Defines an ordered list", + "scope": "text.html" + }, + "ol.#": { + "prefix": "", "\t$3", ""], + "description": "HTML - Defines an ordered list", + "scope": "text.html" + } +} diff --git a/lua/replace_html_snippets.lua b/lua/replace_html_snippets.lua new file mode 100644 index 0000000..05c8091 --- /dev/null +++ b/lua/replace_html_snippets.lua @@ -0,0 +1,50 @@ +local uv = vim.loop +local home = uv.os_homedir() +-- Detect OS and friendly-snippets path +local function get_friendly_snippets_html_path() + local os_name = uv.os_uname().sysname + if os_name == 'Windows_NT' then + return home .. '\\.local\\share\\nvim\\lazy\\friendly-snippets\\snippets\\html.json' + else + return home .. '/.local/share/nvim/lazy/friendly-snippets/snippets/html.json' + end +end +local target_path = get_friendly_snippets_html_path() +local source_path = vim.fn.stdpath 'config' .. '/lua/custom_html_snippets.json' +-- Read source file +local source_file = io.open(source_path, 'r') +if not source_file then + vim.notify('Custom html.json not found at ' .. source_path, vim.log.levels.ERROR) + return +end +local source_content = source_file:read '*a' +source_file:close() +-- Read target file +local target_content = '' +local target_file = io.open(target_path, 'r') +if target_file then + target_content = target_file:read '*a' + target_file:close() +end +-- Only update if the contents differ +if target_content ~= source_content then + -- Create backup only if it doesn't exist + local backup_path = target_path .. '.bak' + if not uv.fs_stat(backup_path) and target_content ~= '' then + local backup_file = io.open(backup_path, 'w') + if backup_file then + backup_file:write(target_content) + backup_file:close() + else + vim.notify('Failed to create backup: ' .. backup_path, vim.log.levels.ERROR) + end + end + -- Write custom file + local output = io.open(target_path, 'w') + if output then + output:write(source_content) + output:close() + else + vim.notify('Failed to write custom html.json to ' .. target_path, vim.log.levels.ERROR) + end +end