summaryrefslogtreecommitdiff
path: root/mod/tex/context/third/rst
diff options
context:
space:
mode:
authorPhilipp Gesang <megas.kapaneus@gmail.com>2011-08-28 12:13:42 +0200
committerPhilipp Gesang <megas.kapaneus@gmail.com>2011-08-28 12:13:42 +0200
commit4d80cd680742e182b6d67798018ca8fcf8a15629 (patch)
tree21daed8d647583b236dce0f9b45549c7b6a389a0 /mod/tex/context/third/rst
parent0040a616d26d9974ada7abb8c49643c505ef7e91 (diff)
downloadcontext-rst-4d80cd680742e182b6d67798018ca8fcf8a15629.tar.gz
generalized tab expansion
Diffstat (limited to 'mod/tex/context/third/rst')
-rw-r--r--mod/tex/context/third/rst/rst_parser.lua34
1 files changed, 23 insertions, 11 deletions
diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua
index 8951542..4289941 100644
--- a/mod/tex/context/third/rst/rst_parser.lua
+++ b/mod/tex/context/third/rst/rst_parser.lua
@@ -76,8 +76,8 @@ state.lastbullets = {}
state.roman_cache = {} -- storing roman numerals that were already converted
state.currentindent = "" -- used in definition lists and elsewhere
state.previousindent = "" -- for literal blocks included in paragraphs to restore the paragraph indent
-state.currentwidth = 0 -- table layout
-state.currentlayout = {} -- table layout
+state.currentwidth = 0 -- table layout
+state.currentlayout = {} -- table layout
state.previousadorn = nil -- section underlining and overlining
state.footnotes = {}
@@ -1362,22 +1362,34 @@ function file_helpers.strip_BOM (raw)
return raw
end
+--- Tab expansion: feature request by Philipp A.
do
- local space = " "
- function file_helpers.expandtab (raw)
- local spaces = space:rep(rst.shiftwidth)
+ local shiftwidth = rst.shiftwidth
+ local stringrep = string.rep
+ local position = 1
+
+ local reset_position = function () position = 1 return "\n" end
+ local increment_position = function (c) position = position + 1 return c end
+ local expand_tab = function ()
+ local expand = (shiftwidth - position) % shiftwidth + 1
+ position = position + expand
+ return stringrep(" ", expand)
+ end
- local tab = P"\t" / spaces
- local eol = P"\n"
- local indent = eol * tab^1
- local detabber = Cs(tab^-1 * (indent + 1)^0)
+ local tab = S"\t\v" / expand_tab
+ local utfchar = utfchar / increment_position
+ local eol = P"\n" / reset_position
+ local p_expand = Cs((tab + eol + utfchar)^1)
- return detabber:match(raw)
+ function file_helpers.expandtab (raw)
+ position = 1
+ p_expand:match(raw)
end
end
+--- Spotted by Philipp A.
function file_helpers.insert_blank (raw)
- if not raw:match"\n%s$" then
+ if not raw:find"\n%s$" then
return raw .. "\n\n"
end
return raw