summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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