Skip to content

Commit

Permalink
Use iterlines in expandtabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Apr 9, 2021
1 parent 4c7a603 commit 84dbd4d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -15715,6 +15715,23 @@ function M.reader.new(writer, options)
% \par
% \begin{markdown}
%
% Define \luamdef{iterlines} as a function that iterates over the lines of
% the input string `s`, transforms them using an input function `f`, and
% reassembles them into a new string, which it returns.
%
% \end{markdown}
% \begin{macrocode}
local function iterlines(s, f)
rope = {}
for line in lpeg.match((parsers.line / f)^1, s) do
table.insert(rope, line)
end
return util.rope_to_string(rope)
end
% \end{macrocode}
% \par
% \begin{markdown}
%
% Define \luamdef{expandtabs} either as an identity function, when the
% \Opt{preserveTabs} Lua inrerface option is enabled, or to a function that
% expands tabs into spaces otherwise.
Expand All @@ -15727,7 +15744,7 @@ function M.reader.new(writer, options)
else
expandtabs = function(s)
if s:find("\t") then
return s:gsub("[^\n]*", util.expand_tabs_in_line)
return iterlines(s, util.expand_tabs_in_line)
else
return s
end
Expand All @@ -15737,23 +15754,6 @@ function M.reader.new(writer, options)
% \par
% \begin{markdown}
%
% Define \luamdef{iterlines} as a function that iterates over the lines of
% the input string `s`, transforms them using an input function `f`, and
% reassembles them into a new string, which it returns.
%
% \end{markdown}
% \begin{macrocode}
local function iterlines(s, f)
rope = {}
for line in lpeg.match((parsers.line / f)^1, s) do
table.insert(rope, line)
end
return util.rope_to_string(rope)
end
% \end{macrocode}
% \par
% \begin{markdown}
%
% The \luamdef{larsers} (as in ``local \luam{parsers}'') hash table stores
% \acro{peg} patterns that depend on the received `options`, which impedes
% their reuse between different \luam{reader} objects.
Expand Down

0 comments on commit 84dbd4d

Please sign in to comment.