summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-21 23:55:18 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-21 23:55:18 +0200
commitf47e04a3723e3aa34a1092c23e1e823d6937fd10 (patch)
tree8bf6b0b57974d9c5d661418a58c9d257f8e713d2 /rst_context.lua
parent2d3bcf0b5c97ca7f8dc04b174762d0fc022dc44a (diff)
downloadcontext-rst-f47e04a3723e3aa34a1092c23e1e823d6937fd10.tar.gz
fixed link text in anonymous external links
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua34
1 files changed, 20 insertions, 14 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 92a584b..016ad5b 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -47,13 +47,16 @@ end
local rst_context = {}
-rst_context.collected_references = {}
rst_context.collected_adornments = {}
rst_context.last_section_level = 0
rst_context.anonymous_targets = 0
-rst_context.anonymous_links = 0
+rst_context.anonymous_links = {}
+
+rst_context.collected_references = {}
rst_context.context_references = {}
rst_context.structure_references = {}
+rst_context.anonymous_set = {}
+
rst_context.substitutions = {}
rst_context.lastitemnumber = 0 -- enumerations in RST allow arbitrary skips
@@ -160,9 +163,8 @@ end
function rst_context.anon_reference (str)
rst_context.addsetups("references")
str = str:match("^`?([^`]+)`?__$")
- rst_context.anonymous_links = rst_context.anonymous_links + 1
- link = "__target_anon_" .. rst_context.anonymous_links
- --return [[\\goto{]] .. str .. [[}[url(]] .. link .. [=[)]]=]
+ rst_context.anonymous_links[#rst_context.anonymous_links+1] = str
+ link = "__target_anon_" .. #rst_context.anonymous_links
return string.format([[\\RSTchoosegoto{%s}{%s}]], link, str)
end
@@ -173,20 +175,18 @@ local removewhitespace = Cs((nowhitespace^1 + Cs(whitespace / ""))^0)
function rst_context.target (tab)
rst_context.addsetups("references")
--local tab = { ... }
- local refs = rst_context.collected_references
+ local refs = rst_context.collected_references
+ local arefs = rst_context.anonymous_set
local target = tab[#tab] -- Ct + C could be clearer but who cares
tab[#tab] = nil
local function create_anonymous ()
rst_context.anonymous_targets = rst_context.anonymous_targets + 1
- return "anon_" .. rst_context.anonymous_targets
+ return { "anon_" .. rst_context.anonymous_targets, rst_context.anonymous_targets }
end
- --target = resolve_indirect (target)
-
local insert = ""
- --if removewhitespace:match(target) == "" then
if target == "" then -- links here
for _, id in next, tab do
insert = insert .. "\n\\reference[__target_" .. id .. "]{}"
@@ -195,7 +195,8 @@ function rst_context.target (tab)
for i=1,#tab do
local id = tab[i]
if id == "" then -- anonymous
- id = create_anonymous()
+ local anon = create_anonymous()
+ id, arefs[anon[1]] = anon[1], anon[2]
else
id = tab[i]:gsub("\\:",":"):match("`?([^`]+)`?") -- deescaping
end
@@ -1167,18 +1168,23 @@ function optional_setups.references ()
]]
local references = {}
- local ref_keys = {}
+ local ref_keys = {}
+ local arefs = rst_context.anonymous_set
for ref, target in next, refs do
ref_keys[#ref_keys+1] = [[__target_]] .. rst_context.whitespace_to_underscore(ref)
target = resolve_indirect(target)
if target ~= false then
+ ref_text = ref
+ if arefs[ref_text] then
+ ref_text = rst_context.anonymous_links[tonumber(arefs[ref_text])]
+ end
references[#references+1] = string.format([[
-\useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), target, ref)
+\useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), target, ref_text)
end
end
refsection = refsection .. table.concat(references, "\n")
-- this is needed in order to select the right reference command later
- refsection = refsection .. "\n\n" .. [[\def\RSTexternalreferences{]] .. table.concat(ref_keys, ",") .. [[}
+ refsection = refsection .. "\n\n" .. [[\def \RSTexternalreferences{]] .. table.concat(ref_keys, ",") .. [[}
% #1 target name, #2 link text
\def\RSTchoosegoto#1#2{%