From 92547b14cfb101498e5f4200812c32eab3b84e43 Mon Sep 17 00:00:00 2001 From: Sam <30577766+Samasaur1@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:11:11 -0800 Subject: [PATCH 1/2] Allow opening files with \n (NOT literal newline) in them (closes #15) --- lua/jupytext/init.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/jupytext/init.lua b/lua/jupytext/init.lua index 81391f2..9f858b6 100644 --- a/lua/jupytext/init.lua +++ b/lua/jupytext/init.lua @@ -93,6 +93,13 @@ local read_from_ipynb = function(ipynb_filename) -- doesn't delete the first line of the actual input table.insert(jupytext_content, 1, "") + -- This allows opening files that have `\n` in lines + -- which is DISTINCT from a literal newline character + -- (think `\neq` in LaTeX) + for i,v in ipairs(jupytext_content) do + jupytext_content[i] = v:gsub("\n", "\\n") + end + -- Replace the buffer content with the jupytext content vim.api.nvim_buf_set_lines(0, 0, -1, false, jupytext_content) else From 8cae5d59b6b080f368363e1b1311ad51480b8c38 Mon Sep 17 00:00:00 2001 From: Sam <30577766+Samasaur1@users.noreply.github.com> Date: Fri, 16 Feb 2024 01:31:05 -0800 Subject: [PATCH 2/2] Correctly substitute with the null character --- lua/jupytext/init.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lua/jupytext/init.lua b/lua/jupytext/init.lua index 9f858b6..000e2bc 100644 --- a/lua/jupytext/init.lua +++ b/lua/jupytext/init.lua @@ -93,11 +93,10 @@ local read_from_ipynb = function(ipynb_filename) -- doesn't delete the first line of the actual input table.insert(jupytext_content, 1, "") - -- This allows opening files that have `\n` in lines - -- which is DISTINCT from a literal newline character - -- (think `\neq` in LaTeX) + -- This allows opening files that have the null character + -- in them (`\0`, the character represented by ASCII 0) for i,v in ipairs(jupytext_content) do - jupytext_content[i] = v:gsub("\n", "\\n") + jupytext_content[i] = v:gsub("\n", "\0") end -- Replace the buffer content with the jupytext content