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 ++++++++++++++++++---------- rst_parser.lua | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 19 deletions(-) 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"), diff --git a/rst_parser.lua b/rst_parser.lua index 13f3a2d..bd59806 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -129,6 +129,30 @@ local parser = P{ --+ V"comment block" , +-------------------------------------------------------------------------------- +-- Explicit markup hyperlink target +-------------------------------------------------------------------------------- + + --hyperlink_target_block = V"hyperlink_target" + --* (V"blank_line"^-1 * V"hyperlink_target")^0 + --* V"end_block" + --, + + --hyperlink_target = V"hl_anonymous" + ----+ V"hl_named" + --, + + --hl_anonymous = V"hl_anonymous_start" + --* C(V"link_block") + --, + + --hl_anonymous_start = (V"double_underscore" + --+ V"double_dot" * V"space" * V"double_underscore" * V"colon") + --* V"whitespace" + --, + + --link_block = + -------------------------------------------------------------------------------- -- Explicit markup footnote block -------------------------------------------------------------------------------- @@ -911,7 +935,7 @@ local parser = P{ * C(1 - V"whitespace" - V"eol")^1)^0) * V"eol" * #(1 - V"whitespace" - "eol")) / rst.joinindented + C((1 - V"eol")^1) * V"eol" * #(V"double_dot" + V"eol") - + (1 - V"end_block")^0 * Cc("make me constant!"), + + (1 - V"end_block")^0 * Cc(""), target = Ct((V"target_name" * (V"space"^0 * V"eol" * V"target_name")^0) * V"space"^0 @@ -1177,8 +1201,11 @@ local function get_setups () %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setupcolors[state=start] -\setupinteraction[state=start,color=darkgreen,contrastcolor=darkgreen] +\setupinteraction[state=start,focus=standard,color=darkgreen,contrastcolor=darkgreen] \setupbodyfontenvironment [default] [em=italic] +\sethyphenatedurlnormal{:=?&} +\sethyphenatedurlbefore{?&} +\sethyphenatedurlafter {:=/-} ]] for item, _ in next, state.addme do @@ -1204,13 +1231,9 @@ local function main() return 1 end - for i,j in next, state.footnotes do - if type(j) == "table" then - for k,l in next, j do - print(k,l) - end - end - end + --for i,j in next, rst.anonymous_links do + --print(i,j) + --end --print(">>>Last used char>: " ..state.lastbullet.." <<<<") --print(">>>Max list nestin>: "..state.bullets.max .." <<<<") -- cgit v1.2.3