summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-14 17:18:39 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-14 17:18:39 +0200
commitb5ab9445882ece8bf0c384d7a9314753b9557bd7 (patch)
tree8a9615af22999ccc08dca5563d0ddbbd39558747 /rst_context.lua
parent77c44e11aab17795bc24cb7cb6950712c23049b5 (diff)
downloadcontext-rst-b5ab9445882ece8bf0c384d7a9314753b9557bd7.tar.gz
output formatting. includes paragraph reflowing
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua39
1 files changed, 22 insertions, 17 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 1c050f9..0c657df 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -92,7 +92,7 @@ function rst_context.addsetups(item)
end
do
- local w = S" \v\t\n"
+ local w = S" \v\t\n" / "_"
local wp = Cs((w + 1)^1)
function rst_context.whitespace_to_underscore(str)
return wp:match(str)
@@ -119,6 +119,7 @@ end
function rst_context.literal (str)
str = str:gsub([[\]], [[\\]]) -- evade escaping of backslashes
return [[\\type{]] .. str .. [[}]]
+ --return [[\\starttyping ]] .. str .. [[\\stoptyping]]
end
@@ -185,20 +186,12 @@ function rst_context.target (tab)
local target = tab[#tab] -- Ct + C could be clearer but who cares
tab[#tab] = nil
- local function resolve_indirect (r)
- if r and r:match(".*_$") then -- pointing elsewhere
- return resolve_indirect (refs[r:match("^`?([^`]*)`?_$")]) or "need another run!" -- TODO multiple runs && data collection
- end
- return r
- end
-
local function create_anonymous ()
rst_context.anonymous_targets = rst_context.anonymous_targets + 1
return "anon_" .. rst_context.anonymous_targets
end
- target = resolve_indirect (target)
- print(tab[1],target)
+ --target = resolve_indirect (target)
local insert = ""
@@ -412,7 +405,7 @@ function rst_context.paragraph (data)
if not data then
return ""
elseif type(data) == "table" then
- str = inline_parser:match(table.concat(data, " "))
+ str = helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65)
else
str = data
end
@@ -996,18 +989,30 @@ function optional_setups.footnotes ()
end
function optional_setups.references ()
- local refs = [[
+ local refs = rst_context.collected_references
+ local function resolve_indirect (r)
+ if r and r:match(".*_$") then -- pointing elsewhere
+ --print(">>"..r.."<<",">>"..r:match("^`?([^`]*)`?_$").."<<", refs[r:match("^`?([^`]*)`?_$")])
+ return resolve_indirect (refs[r:match("^`?([^`]*)`?_$")]) or "need another run!" -- TODO multiple runs && data collection
+ end
+ return r
+ end
+
+ local refsection = [[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
]]
- for ref, target in next, rst_context.collected_references do
- refs = refs .. string.format([[
-\useURL[__target_%s] [%s] [] [%s]
-]], rst_context.whitespace_to_underscore(ref), target, ref)
+ local references = {}
+ for ref, target in next, refs do
+ target = resolve_indirect(target)
+ references[#references+1] = string.format([[
+\useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), target, ref)
end
- return refs
+ refsection = refsection .. table.concat(references, "\n")
+ return refsection
end
return rst_context