From 7d02de72030797a5829f23c0ba87ebd157f044a1 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 14 Sep 2010 00:21:26 +0200 Subject: internal links now work --- rst_context.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'rst_context.lua') diff --git a/rst_context.lua b/rst_context.lua index c3ec323..7712934 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -141,8 +141,8 @@ end function rst_context.reference (str) str = str:match("[^_]*") local link = rst_context.collected_references[str] - if not link then -- TODO make warning instead - return([[{\\sc UNDEFINED REFERENCE ]] .. str .. [[}.]]) + if not link then -- assume internal + return [[\\goto{]] .. str .. [[}[__target_]] .. str .. "]" end return [[\\goto{]] .. str @@ -167,18 +167,26 @@ function rst_context.target (tab) local function create_anonymous () rst_context.anonymous_links = rst_context.anonymous_links + 1 - return "__anon__" .. rst_context.anonymous_links + return "__target_anon_" .. rst_context.anonymous_links end - target = resolve_indirect (target) - for i=1,#tab do - local id = tab[i]:gsub("\\:",":") -- deescaping - id = id ~= "" and id or create_anonymous () - refs[id] = refs[id] or target + local insert = "" + + if target == "" then -- links here + for _, id in next, tab do + insert = insert .. "\n\\reference[__target_" .. id .. "]{}" + end + else + for i=1,#tab do + local id = tab[i]:gsub("\\:",":") -- deescaping + id = id ~= "" and id or create_anonymous () + refs[id] = refs[id] or target + end end - return "" + + return insert end function rst_context.escape (str) @@ -202,7 +210,7 @@ local inline_parser = P{ + V"interpreted_text" -- + V"inline_internal_target" -- TODO + V"reference" - + V"footnote_reference" -- TODO + + V"footnote_reference" -- + V"substitution_reference" -- TODO + V"link_standalone") * V"succede_inline"), -- cgit v1.2.3