[blis-cvs] blis/cgi-bin blis.cgi,1.63,1.64
Status: Beta
Brought to you by:
cstroie
From: Costin S. <cs...@us...> - 2007-03-21 22:50:50
|
Update of /cvsroot/blis/blis/cgi-bin In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13795/cgi-bin Modified Files: blis.cgi Log Message: Improved the support for inline anchors. Index: blis.cgi =================================================================== RCS file: /cvsroot/blis/blis/cgi-bin/blis.cgi,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- blis.cgi 26 Feb 2007 15:29:48 -0000 1.63 +++ blis.cgi 21 Mar 2007 22:50:46 -0000 1.64 @@ -675,7 +675,7 @@ # # The Parser # -# The parser is a multi-layered structure with multiple enter points and a +# The parser is a multi-layered structure with multiple enter points and a # single exit point: the parsed object. # @@ -1079,10 +1079,10 @@ } # Parse the inline markups representing anchors -function parse_inline_anchors(line, result, mch, field, title, attrs, extra_query) +function parse_inline_anchors(line, result, mch, field, title, attrs, extra_query, url, content) { # Find all matching internal anchors - while (match(line, /\[\[ *([^\]\|]+) *([^\]]*)\]\]/, mch)) + while (match(line, /\[ *([^\]\|]+) *([^\]]*)\]/, mch)) { # The first segment: the string before the match result = result substr(line, 1, mch[0, "start"] - 1) @@ -1090,12 +1090,8 @@ # Clear the extra query array delete extra_query - # Reset the title - title = "" - - # Check whether the anchor points to the current page - if (page_to_file(page) == page_to_file(mch[1])) - attrs = "class=\"current\" " + # Reset the title and attributes + title = content = attrs = "" # The extra data, as string with fields separated by "|" if (split(mch[2], field, "|")) @@ -1109,23 +1105,50 @@ # Show the raw page extra_query["mode"] = "raw" } - else if ((!title) && (field[f])) + else if (field[f] ~ /blank/) + { + # Open in new window + attrs = attrs "target=\"_blank\" " + } + else if ((!content) && (field[f])) { # Set the anchor title - title = trim(field[f]) + content = trim(field[f]) } } } - # If there is no title, use the anchor instead - if (!title) - title = file_to_page(mch[1]) + # The main part of the link, check if we recognize something + if (mch[1] ~ /^http:\/\/.+|^ftp:\/\/.+/) + { + # The HTTP and FTP methods + url = trim(mch[1]) + title = "External link: " url + content = content ? content : url + } + else if (mch[1] ~ /^mailto:.+/) + { + # Email + url = trim(mch[1]) + title = "Email to " substr(url, 8) + content = content ? content : substr(url, 8) + } + else + { + # Usual Blis page + url = page_to_url(mch[1], extra_query) + title = "Blis page: " page_to_file(mch[1]) + content = content ? content : file_to_page(mch[1]) + # Check whether the anchor points to the current page + if (page_to_file(page) == page_to_file(mch[1])) + attrs = "class=\"current\" " + } # Add the 'title' attribute attrs = attrs "title=\"" title "\" " # The matched segment replaced by the anchor tag - result = result sprintf("<a %s href=\"%s\">%s</a>", trim(attrs), page_to_url(mch[1], extra_query), title) + result = result sprintf("<a %s href=\"%s\">%s</a>", trim(attrs), url, content) # The last segment: the string after the match line = substr(line, mch[0, "start"] + mch[0, "length"]) @@ -1169,55 +1192,10 @@ # Re-create the line to start searching for external anchors line = result line - result = "" - } - - # Find all matching external anchors - while (match(line, /\[ *([^\[\]\|]+) *([^\]]*)\]/, mch)) - { - # The first segment: the string before the match - result = result substr(line, 1, mch[0, "start"] - 1) - - # Reset the title and atttributes - title = attrs = "" - - # The extra data, as string with fields separated by "|" - if (split(mch[2], field, "|")) - { - # Check all fields if they exist and contains some keywords - for (f in field) - { - # Check if the fields match some keywords - if (field[f] ~ /blank/) - { - # Open in new window - attrs = attrs "target=\"_blank\" " - } - else if ((!title) && (field[f])) - { - # Set the anchor title - title = trim(field[f]) - } - } - } - - # If there is no title, use the anchor instead - if (!title) - title = file_to_page(mch[1]) - - # Add the 'title' attribute - attrs = attrs "title=\"" title "\" " - - # The matched segment replaced by the anchor tag - result = result sprintf("<a %s href=\"%s\">%s</a>", trim(attrs), trim(mch[1]), title) - - # The last segment: the string after the match - line = substr(line, mch[0, "start"] + mch[0, "length"]) } # The final result - result = result line - return result + return line } |