fix(tohtml): disable modeline #32822

Problem:
Running :TOhtml with a file containing modeline may generate an invalid modeline in the output.

Solution:
Add `<!-- vim: set nomodeline: -->` to the output.
Use vi-compatible modeline format ("set foo:"), to avoid the trailing `-->` being treated as part of the modeline.
This commit is contained in:
altermo
2025-03-10 17:15:41 +01:00
committed by GitHub
parent c9b5ac113a
commit 67c39f5eca
2 changed files with 3 additions and 0 deletions

View File

@@ -1372,6 +1372,7 @@ local function win_to_html(winid, opt)
state_generate_style(state)
local html = {}
table.insert(html, '<!-- vim: set nomodeline: -->')
extend_html(html, function()
extend_head(html, global_state)
extend_body(html, function()

View File

@@ -159,6 +159,7 @@ local function test_generates_html(guifont, expect_font)
local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf())
eq({
'<!-- vim: set nomodeline: -->',
'<!DOCTYPE html>',
'<html>',
'<head>',
@@ -212,6 +213,7 @@ describe(':TOhtml', function()
n.command('2,2TOhtml')
local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf())
eq({
'<!-- vim: set nomodeline: -->',
'<!DOCTYPE html>',
'<html>',
'<head>',