summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-14 12:35:58 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-14 12:35:58 +0200
commit77c44e11aab17795bc24cb7cb6950712c23049b5 (patch)
tree8c91baa7a47851a2291b8b2a7ab86b91cd677124
parent78df2a79804f4461456c3bc258c566b1c92ce4fd (diff)
downloadcontext-rst-77c44e11aab17795bc24cb7cb6950712c23049b5.tar.gz
anonymous link blocks fixed
-rw-r--r--rst_context.lua14
-rw-r--r--rst_parser.lua10
2 files changed, 18 insertions, 6 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 5bc1753..1c050f9 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -173,6 +173,10 @@ function rst_context.anon_reference (str)
.. [=[]]=]
end
+local whitespace = S" \n\t\v"
+local nowhitespace = 1 - whitespace
+local removewhitespace = Cs((nowhitespace^1 + Cs(whitespace / ""))^0)
+
function rst_context.target (tab)
rst_context.addsetups("references")
--print("GOT ONE!")
@@ -190,13 +194,15 @@ function rst_context.target (tab)
local function create_anonymous ()
rst_context.anonymous_targets = rst_context.anonymous_targets + 1
- return "__target_anon_" .. rst_context.anonymous_targets
+ return "anon_" .. rst_context.anonymous_targets
end
target = resolve_indirect (target)
+ print(tab[1],target)
local insert = ""
+ --if removewhitespace:match(target) == "" then
if target == "" then -- links here
for _, id in next, tab do
insert = insert .. "\n\\reference[__target_" .. id .. "]{}"
@@ -204,8 +210,10 @@ function rst_context.target (tab)
else
for i=1,#tab do
local id = tab[i]:gsub("\\:",":"):match("`?([^`]+)`?") -- deescaping
- id = id ~= "" and id or create_anonymous ()
- refs[id] = refs[id] or target
+ if id then
+ id = id ~= "" and id or create_anonymous ()
+ refs[id] = refs[id] or target
+ end
end
end
diff --git a/rst_parser.lua b/rst_parser.lua
index bd59806..3a87ea2 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -923,7 +923,9 @@ local parser = P{
* (V"tname_bareia" + V"tname_normal"),
target_firstindent = V"eol" * Cg(V"space"^1, "indent"),
+
target_nextindent = V"eol" * C(V"space"^1),
+
target_indentmatch = Cmt(V"target_nextindent" -- I ♡ LPEG!
* Cb("indent"), function (s, i, a, b)
return a == b
@@ -934,7 +936,7 @@ local parser = P{
* (V"target_indentmatch"
* 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")
+ + C((1 - V"eol")^1) * V"eol" * #(V"double_dot" + V"double_underscore" + V"eol")
+ (1 - V"end_block")^0 * Cc(""),
target = Ct((V"target_name" * (V"space"^0 * V"eol" * V"target_name")^0)
@@ -943,12 +945,14 @@ local parser = P{
/ rst.target,
anonymous_prefix = (V"double_dot" * V"space" * V"double_underscore" * V"colon")
- + (V"double_underscore"),
+ + (V"double_underscore")
+ ,
anonymous_target = V"anonymous_prefix"
* V"space"^0
* Ct(Cc"" * V"target_link")
- / rst.target,
+ / rst.target
+ ,
target_block = (V"anonymous_target" + V"target")^1
* V"end_block",