lib/RichTextScanner.rb in taskjuggler-0.0.4 vs lib/RichTextScanner.rb in taskjuggler-0.0.5
- old
+ new
@@ -69,10 +69,12 @@
if @mode == :funcarg
return nextTokenFuncArg
elsif @mode == :href
return nextTokenHRef
+ elsif @mode == :ref
+ return nextTokenRef
end
if @beginOfLine && @mode == :wiki
if (res = nextTokenWikiBOL)
return res
end
@@ -157,16 +159,40 @@
end
end
token
end
+ def nextTokenRef
+ c = nextChar
+ return [ '.', '<END' ] if c.nil?
+
+ return [ 'LITERAL', '|' ] if c == '|'
+
+ if c == ']' && peek == ']'
+ nextChar
+ @mode = :wiki
+ return [ 'REFEND', ']]' ]
+ end
+
+ token = c
+ while (c = nextChar)
+ break if c.nil?
+ if c == '|' || (c == ']' && peek == ']')
+ returnChar
+ break
+ end
+ token << c
+ end
+ [ 'WORD', token ]
+ end
+
def nextTokenHRef
token = [ '.', '<END>' ]
while (c = nextChar)
if c.nil?
# We've reached the end of the text.
- return [ '.', '<END>' ]
+ return token
elsif c == ' ' || c == "\t" || c == "\n"
# Sequences of tabs, spaces and newlines are treated as token
# boundaries, but otherwise they are ignored.
readSequence(" \n\t")
return [ 'SPACE', ' ' ]
@@ -311,10 +337,11 @@
level = readSequenceMax('[', 2)
if level == 1
@mode = :href
[ 'HREF' , '[' ]
else
+ @mode = :ref
[ 'REF', '[[' ]
end
elsif c == ']' && peek == ']'
nextChar
[ 'REFEND', ']]' ]
@@ -362,11 +389,11 @@
# (INLINEFUNCSTART). Only for the first case the linebreak is real.
returnChar if c != "\n"
# The next character may be a control character.
@beginOfLine = true
[ 'LINEBREAK', "\n" ]
- elsif "\n*# =-".include?(c)
+ elsif "\n*#=-".include?(c)
# These characters correspond to the first characters of a block
# element. When they are found at the begin of the line, the newline
# was really a line break.
returnChar if c != "\n"
# The next character may be a control character.
@@ -412,16 +439,16 @@
str << c
# Now we can collect characters of a word until we hit a whitespace.
while (c = nextChar) && !" \n\t".include?(c)
case @mode
when :wiki
- # Or at least to ' characters in a row.
+ # Or at least two ' characters in a row.
break if c == "'" && peek == "'"
- # Or a -, ] or <
+ # Or a ] or <
break if ']<'.include?(c)
when :href
# Look for - of the end mark -> end ']'
- break if c == '-' || c == ']' || c == '<'
+ break if '-]<'.include?(c)
else
# Make sure we find the </nowiki> tag even within a word.
break if c == '<'
end
str << c