From 2a44ddb4c5572451436ea59d702c507cf5de4739 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 14 Sep 2010 01:00:10 +0200 Subject: links to sections by their titles --- rst_context.lua | 12 ++++++++++-- 1 file 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 -- cgit v1.2.3