summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-21 23:00:20 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-21 23:00:20 +0200
commit2d3bcf0b5c97ca7f8dc04b174762d0fc022dc44a (patch)
tree7f0826e104ec1144876d94d0c05047b2803cc6b4 /rst_context.lua
parent6fca7b9582ac97d772152ad0bef822d37605b616 (diff)
downloadcontext-rst-2d3bcf0b5c97ca7f8dc04b174762d0fc022dc44a.tar.gz
fixed internal references to structure components
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua21
1 files changed, 18 insertions, 3 deletions
diff --git a/rst_context.lua b/rst_context.lua
index e5737e0..92a584b 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -53,6 +53,7 @@ rst_context.last_section_level = 0
rst_context.anonymous_targets = 0
rst_context.anonymous_links = 0
rst_context.context_references = {}
+rst_context.structure_references = {}
rst_context.substitutions = {}
rst_context.lastitemnumber = 0 -- enumerations in RST allow arbitrary skips
@@ -109,6 +110,8 @@ end
-- created.
local function get_context_reference (str)
local crefs = rst_context.context_references
+ local srefs = rst_context.structure_references
+ srefs[str] = true
refstring = "__target_" .. rst_context.whitespace_to_underscore(str)
crefs[#crefs + 1] = { refstring, str }
return refstring
@@ -1138,10 +1141,20 @@ function optional_setups.footnotes ()
end
function optional_setups.references ()
- local refs = rst_context.collected_references
+ local refs = rst_context.collected_references
+ local crefs = rst_context.context_references
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
+ local look_me_up = r:match("^`?([^`]*)`?_$")
+ local result = resolve_indirect (refs[look_me_up])
+ if result then
+ return result
+ else
+ if rst_context.structure_references[look_me_up] then
+ -- Internal link, no useURL etc.
+ return false
+ end
+ end
end
return r
end
@@ -1158,8 +1171,10 @@ function optional_setups.references ()
for ref, target in next, refs do
ref_keys[#ref_keys+1] = [[__target_]] .. rst_context.whitespace_to_underscore(ref)
target = resolve_indirect(target)
- references[#references+1] = string.format([[
+ if target ~= false then
+ references[#references+1] = string.format([[
\useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), target, ref)
+ end
end
refsection = refsection .. table.concat(references, "\n")
-- this is needed in order to select the right reference command later