Ejemplo n.º 1
0
        /// <summary>
        /// Processes link markup into HTML
        /// </summary>
        /// <param name="markup">markup</param>
        /// <returns>markup with [[foo]] translated into <a href></a></returns>
        private string _processLinkCreole(string markup)
        {
            int iPos = _indexOfWithSkip(markup, "[[", 0);

            while (iPos >= 0)
            {
                int iEnd = _indexOfWithSkip(markup, "]]", iPos);
                if (iEnd > iPos)
                {
                    iPos += 2;
                    // get the contents of the cell
                    string cell = markup.Substring(iPos, iEnd - iPos);
                    string link = cell;
                    string href = cell; //default to assuming it's the href
                    string text = href; // as well as the text
                    LinkEventArgs.TargetEnum target = new LinkEventArgs.TargetEnum();
                    target = LinkEventArgs.TargetEnum.External;

                    int iSplit = cell.IndexOf('|'); // unless of course there is a splitter
                    if (iSplit > 0)
                    {
                        // href is the front
                        href = cell.Substring(0, iSplit);
                        link = href;

                        // text is the creole processed fragment left over
                        text = _processCreoleFragment(cell.Substring(iSplit + 1));
                    }

                    // handle interwiki links
                    iSplit = href.IndexOf(':');
                    if (iSplit > 0)
                    {
                        string scheme = href.Substring(0, iSplit);
                        if (InterWiki.ContainsKey(scheme))
                        {
                            href   = InterWiki[scheme] + href.Substring(iSplit + 1);
                            target = LinkEventArgs.TargetEnum.InterWiki;
                        }
                    }

                    // default to external
                    //AVelo: handle interwiki links, delegate internal links mgmt to OnLink custom handler
                    LinkEventArgs linkEventArgs = new LinkEventArgs(link, href, text, target);
                    if (OnLink != null)
                    {
                        OnLink(this, linkEventArgs);
                    }

                    //A.Velo: quotes,CssClass
                    markup = markup.Substring(0, iPos - 2)
                             + String.Format("<a href=\"{0}\" {2} {3} {4}>{1}</a>",
                                             linkEventArgs.Href,
                                             linkEventArgs.Text,
                                             (linkEventArgs.Target == LinkEventArgs.TargetEnum.External || linkEventArgs.Target == LinkEventArgs.TargetEnum.InterWiki) ? "target=\"_blank\" " : "",
                                             (linkEventArgs.Target == LinkEventArgs.TargetEnum.Unknown) ? "style='border-bottom:1px dashed #000000; text-decoration:none'" : "",
                                             (linkEventArgs.Target != LinkEventArgs.TargetEnum.Unknown) ? "class=\"" + linkEventArgs.CssClass + "\"" : "")
                             + markup.Substring(iEnd + 2);
                }
                else
                {
                    break;
                }
                iPos = _indexOfWithSkip(markup, "[[", iPos);
            }

            return(markup);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes link markup into HTML
        /// </summary>
        /// <param name="markup">markup</param>
        /// <returns>markup with [[foo]] translated into <a href></a></returns>
        private string _processLinkCreole(string markup)
        {
            int iPos = _indexOfWithSkip(markup, "[[", 0);
            while (iPos >= 0)
            {
                int iEnd = _indexOfWithSkip(markup, "]]", iPos);
                if (iEnd > iPos)
                {
                    iPos += 2;

                    // get the contents of the cell
                    string cell = markup.Substring(iPos, iEnd - iPos);
                    string link = cell;
                    string href = cell; //default to assuming it's the href
                    string text = href; // as well as the text
                    int iSplit = cell.IndexOf('|'); // unless of course there is a splitter
                    if (iSplit > 0)
                    {
                        // href is the front
                        href = cell.Substring(0, iSplit);
                        link = href;

                        // text is the creole processed fragment left over
                        text = _processCreoleFragment(cell.Substring(iSplit + 1));
                    }

                    // handle interwiki links
                    iSplit = href.IndexOf(':');
                    if (iSplit > 0)
                    {
                        string scheme = href.Substring(0, iSplit);
                        if (InterWiki.ContainsKey(scheme))
                        {
                            href = InterWiki[scheme] + href.Substring(iSplit + 1);
                        }
                    }

                    // default to external
                    LinkEventArgs linkEventArgs = new LinkEventArgs(link, href, text, LinkEventArgs.TargetEnum.External);
                    if (OnLink != null)
                        OnLink(this, linkEventArgs);

                    markup = markup.Substring(0, iPos - 2)
                        + String.Format("<a href='{0}' {2} {3}>{1}</a>",
                                            linkEventArgs.Href,
                                            linkEventArgs.Text,
                                            (linkEventArgs.Target == LinkEventArgs.TargetEnum.External) ? "target=_blank " : "",
                                            (linkEventArgs.Target == LinkEventArgs.TargetEnum.Unknown) ? "style='border-bottom:1px dashed #000000; text-decoration:none'" : "")
                            + markup.Substring(iEnd + 2);
                }
                else
                    break;
                iPos = _indexOfWithSkip(markup, "[[", iPos);
            }
            return markup;
        }