summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-14 01:00:10 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-14 01:00:10 +0200
commit2a44ddb4c5572451436ea59d702c507cf5de4739 (patch)
tree2cbb91ec9a60d914644fb3b2ad39a7b31d10bc75
parent7d02de72030797a5829f23c0ba87ebd157f044a1 (diff)
downloadcontext-rst-2a44ddb4c5572451436ea59d702c507cf5de4739.tar.gz
links to sections by their titles
-rw-r--r--rst_context.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 7712934..5bd16bd 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -90,11 +90,19 @@ function rst_context.addsetups(item)
return 0
end
+do
+ local w = S" \v\t\n"
+ local wp = Cs((w + 1)^1)
+ function rst_context.whitespace_to_underscore(str)
+ return wp:match(str)
+ end
+end
+
-- So we can use crefs[n][2] to refer to the place where the reference was
-- created.
local function get_context_reference (str)
local crefs = rst_context.context_references
- refstring = "__contextref__" .. tostring(#crefs + 1)
+ refstring = "__target_" .. rst_context.whitespace_to_underscore(str)
crefs[#crefs + 1] = { refstring, str }
return refstring
end
@@ -140,7 +148,7 @@ end
function rst_context.reference (str)
str = str:match("[^_]*")
- local link = rst_context.collected_references[str]
+ 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