summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-15 02:21:29 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-15 02:21:29 +0200
commit60c242de9b6521db6c176c06738a88b9417b0dec (patch)
tree95d4b766f4b23e2a0b12a0711601062ff7ad1dbd /rst_context.lua
parentb5ab9445882ece8bf0c384d7a9314753b9557bd7 (diff)
downloadcontext-rst-60c242de9b6521db6c176c06738a88b9417b0dec.tar.gz
hyperlinks now work for both internal and external targets
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua46
1 files changed, 25 insertions, 21 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 0c657df..4f333a2 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -151,15 +151,10 @@ end
function rst_context.reference (str)
rst_context.addsetups("references")
str = str:match("^`?([^`]+)`?_$") -- LPEG could render this gibberish legible but not time
- local link = rst_context.collected_references[str] or rst_context.context_references[str]
- if not link then -- assume internal
- return [[\\goto{]] .. str .. [[}[__target_]] .. str .. "]"
- end
- return [[\\goto{]]
- .. str
- .. [[}[url(]]
- .. link
- .. [=[)]]=]
+ --local link = rst_context.collected_references[str] or rst_context.context_references[str]
+ --return [[\\goto{]] .. str .. [[}[__target_]] .. rst_context.whitespace_to_underscore(str) .. "]"
+ return [[\\RSTchoosegoto{__target_]] .. rst_context.whitespace_to_underscore(str) .. "}{"
+ .. str .. "}"
end
function rst_context.anon_reference (str)
@@ -167,11 +162,7 @@ function rst_context.anon_reference (str)
str = str:match("^`?([^`]+)`?__$")
rst_context.anonymous_links = rst_context.anonymous_links + 1
link = "__target_anon_" .. rst_context.anonymous_links
- return [[\\goto{]]
- .. str
- .. [[}[]]
- .. link
- .. [=[]]=]
+ return [[\\goto{]] .. str .. [[}[]] .. link .. [=[]]=]
end
local whitespace = S" \n\t\v"
@@ -198,13 +189,18 @@ function rst_context.target (tab)
--if removewhitespace:match(target) == "" then
if target == "" then -- links here
for _, id in next, tab do
+ print(id)
insert = insert .. "\n\\reference[__target_" .. id .. "]{}"
end
else
for i=1,#tab do
- local id = tab[i]:gsub("\\:",":"):match("`?([^`]+)`?") -- deescaping
+ local id = tab[i]
+ if id == "" then -- anonymous
+ id = create_anonymous()
+ else
+ id = tab[i]:gsub("\\:",":"):match("`?([^`]+)`?") -- deescaping
+ end
if id then
- id = id ~= "" and id or create_anonymous ()
refs[id] = refs[id] or target
end
end
@@ -434,16 +430,11 @@ function rst_context.section (...) -- TODO general cleanup; move validity
local section, str = true, ""
local adornchar
if #tab == 3 then -- TODO use unicode length with ConTeXt
- --print(">>"..tab[1].."<>"..tab[2].."<<")
adornchar = tab[1]:sub(1,1)
- -- overline == underline && len(overline) = len(sectionstring)
section = tab[1] == tab[3] and #tab[1] >= #tab[2]
- -- if overline consists only of one char then keep truth value else
- -- false
section = get_line_pattern(adornchar):match(tab[1]) ~= nil and section
str = string.strip(tab[2])
else -- no overline
- --print(">>"..tab[1].."<>"..tab[2].."<<")
adornchar = tab[2]:sub(1,1)
section = #tab[1] <= #tab[2]
section = get_line_pattern(adornchar):match(tab[2]) ~= nil and section
@@ -1006,12 +997,25 @@ function optional_setups.references ()
]]
local references = {}
+ local ref_keys = {}
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([[
\useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), target, ref)
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, ",") .. [[}
+
+% #1 target name, #2 link text
+\def\RSTchoosegoto#1#2{%
+ \rawdoifinsetelse{#1}{\RSTexternalreferences}
+ {\from[#1]}
+ {\goto{#2}[#1]}
+}
+]]
+
return refsection
end