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": "$2"],
+ "description": "HTML - Defines content aside from the page content",
+ "scope": "text.html"
+ },
+ "audio": {
+ "prefix": ""],
+ "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": "$3",
+ "description": "HTML - Defines a push button",
+ "scope": "text.html"
+ },
+ "canvas": {
+ "prefix": "$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": ""],
+ "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": "$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": "
"],
+ "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": ""],
+ "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