vendor/gems/BlueCloth-1.0.0/lib/bluecloth.rb
### Apply Markdown anchor transforms to a copy of the specified +str+ with
### the given render state +rs+ and return it.
Apply Markdown anchor transforms to a copy of the specified +str+ with
the given render state +rs+ and return it.
Apply Markdown anchor transforms to a copy of the specified + str + with the given render state + rs + and return it .
def transform_anchors( str, rs )
		@log.debug " Transforming anchors"
		@scanner.string = str.dup
		text = ''
		until @scanner.empty?
			if @scanner.scan( /\[/ )
				link = ''; linkid = ''
				depth = 1
				startpos = @scanner.pos
				@log.debug " Found a bracket-open at %d" % startpos
				while depth.nonzero?
					linktext = @scanner.scan_until( /\]|\[/ )
					if linktext
						@log.debug "  Found a bracket at depth %d: %p" % [ depth, linktext ]
						link += linktext
						depth += ( linktext[-1, 1] == ']' ? -1 : 1 )
						@log.debug "  Depth is now #{depth}"
					else
						@log.debug "  Missing closing brace, assuming non-link."
						link += @scanner.rest
						@scanner.terminate
						return text + '[' + link
					end
				end
				link.slice!( -1 ) 
				@log.debug " Found leading link %p" % link
				if @scanner.scan( RefLinkIdRegex )
					linkid = @scanner[1]
					linkid = link.dup if linkid.empty?
					linkid.downcase!
					@log.debug "  Found a linkid: %p" % linkid
					if rs.urls.key?( linkid )
						@log.debug "   Found link key in the link table: %p" % rs.urls[linkid]
						url = escape_md( rs.urls[linkid] )
						text += %{<a href="#{url}"}
						if rs.titles.key?(linkid)
							text += %{ title="%s"} % escape_md( rs.titles[linkid] )
						end
						text += %{>#{link}</a>}
					else
						@log.debug "  Linkid %p not found in link table" % linkid
						@log.debug "  Appending original string instead: "
						@log.debug "%p" % @scanner.string[ startpos-1 .. @scanner.pos-1 ]
						text += @scanner.string[ startpos-1 .. @scanner.pos-1 ]
					end
				elsif @scanner.scan( InlineLinkRegex )
					url = @scanner[1]
					title = @scanner[3]
					@log.debug "  Found an inline link to %p" % url
					text += %{<a href="%s"} % escape_md( url )
					if title
						title.gsub!( /"/, "&quot;" )
						text += %{ title="%s"} % escape_md( title )
					end
					text += %{>#{link}</a>}
				else
					@log.debug "No linkid, so no anchor. Appending literal text."
					text += @scanner.string[ startpos-1 .. @scanner.pos-1 ]
				end 
			else
				@log.debug " Scanning to the next link from %p" % @scanner.rest
				text += @scanner.scan( /[^\[]+/ )
			end
		end 
		return text
	end
def transform_anchors ( str , rs ) @log . debug " Transforming anchors" @scanner . string = str . dup text = '' until @scanner . empty? if @scanner . scan ( / \[ / ) link = '' ; linkid = '' depth = 1 startpos = @scanner . pos @log . debug " Found a bracket-open at %d" % startpos while depth . nonzero? linktext = @scanner . scan_until ( / \] | \[ / ) if linktext @log . debug "  Found a bracket at depth %d: %p" % [ depth , linktext ] link += linktext depth += ( linktext [ - 1 , 1 ] == ']' ? - 1 : 1 ) @log . debug "  Depth is now #{depth}" else @log . debug "  Missing closing brace, assuming non-link." link += @scanner . rest @scanner . terminate return text + '[' + link end end link . slice! ( - 1 ) @log . debug " Found leading link %p" % link if @scanner . scan ( RefLinkIdRegex ) linkid = @scanner [ 1 ] linkid = link . dup if linkid . empty? linkid . downcase! @log . debug "  Found a linkid: %p" % linkid if rs . urls . key? ( linkid ) @log . debug "   Found link key in the link table: %p" % rs . urls [ linkid ] url = escape_md ( rs . urls [ linkid ] ) text += %{<a href="#{url}"} if rs . titles . key? ( linkid ) text += %{ title="%s"} % escape_md ( rs . titles [ linkid ] ) end text += %{>#{link}</a>} else @log . debug "  Linkid %p not found in link table" % linkid @log . debug "  Appending original string instead: " @log . debug "%p" % @scanner . string [ startpos - 1 .. @scanner . pos - 1 ] text += @scanner . string [ startpos - 1 .. @scanner . pos - 1 ] end elsif @scanner . scan ( InlineLinkRegex ) url = @scanner [ 1 ] title = @scanner [ 3 ] @log . debug "  Found an inline link to %p" % url text += %{<a href="%s"} % escape_md ( url ) if title title . gsub! ( / " / , "&quot;" ) text += %{ title="%s"} % escape_md ( title ) end text += %{>#{link}</a>} else @log . debug "No linkid, so no anchor. Appending literal text." text += @scanner . string [ startpos - 1 .. @scanner . pos - 1 ] end else @log . debug " Scanning to the next link from %p" % @scanner . rest text += @scanner . scan ( / [^ \[ ]+ / ) end end return text end
Apply Markdown anchor transforms to a copy of the specified +str+ with
the given render state +rs+ and return it.
Apply Markdown anchor transforms to a copy of the specified + str + with the given render state + rs + and return it .
# Scan the whole string # Scan the rest of the tag, allowing unlimited nested []s. If # the scanner runs out of text before the opening bracket is # closed, append the text and return (wasn't a valid anchor). # Decrement depth for each closing bracket # If there's no more brackets, it must not be an anchor, so # just abort. # Trim final ']' # Look for a reference-style second part # If there's a matching link in the link table, build an # anchor tag for it. # If the link referred to doesn't exist, just append the raw # source to the result # ...or for an inline style second part # No linkid part: just append the first part as-is. # if linkid # Plain text # until @scanner.empty?
str
<not_specific>
rs
<not_specific>