Fix LTR/RTL in URLs
516133
function(str){
    return str.replace(URL_LTR_RTL_RE, function(){
      if(arguments[1]) return arguments[0];
      return arguments[0].substr(0, arguments[0].length - 4)
               + (arguments[2] == 'ltr' ? 'rtl' : 'ltr')
               + arguments[0].slice(-1);
    });
  }
410668
def shorten_url(url, cols, shorten):
    
    cols = ((cols - 6) * .85)  # 6 cols for urlref and don't use while line
    if shorten is False or len(url) < cols:
        return url
    split = int(cols * .5)
    return url[:split] + "..." + url[-split:]
730296
def getPrevUrl(self, url, data):
        """"""
        mo = compile(r"index(\d+)\.html").search(url)
        num = int(mo.group(1)) - 1
        prefix = url.rsplit('/', 1)[0]
        return "%s/index%d.html" % (prefix, num)
911919
def substitute_ref_with_url(self, txt):
        

        # Find sphinx cross-references
        mi = re.finditer(r':([^:]+):`([^`]+)`', txt)
        if mi:
            # Iterate over match objects in iterator returned by re.finditer
            for mo in mi:
                # Initialize link label and url for substitution
                lbl = None
                url = None
                # Get components of current match: full matching text, the
                # role label in the reference, and the name of the
                # referenced type
                mtxt = mo.group(0)
                role = mo.group(1)
                name = mo.group(2)

                # If role is 'ref', the name component is in the form
                # label <name>
                if role == 'ref':
                    ma = re.match(r'\s*([^\s<]+)\s*<([^>]+)+>', name)
                    if ma:
                        name = ma.group(2)
                        lbl = ma.group(1)

                # Try to look up the current cross-reference. Issue a
                # warning if the lookup fails, and do the substitution
                # if it succeeds.
                try:
                    url = self.get_docs_url(role, name)
                    if role != 'ref':
                        lbl = self.get_docs_label(role, name)
                except KeyError as ex:
                    if len(ex.args) == 1 or ex.args[1] != 'role':
                        print('Warning: %s' % ex.args[0])
                else:
                    # If the cross-reference lookup was successful, replace
                    # it with an appropriate link to the online docs
                    rtxt = '[%s](%s)' % (lbl, url)
                    txt = re.sub(mtxt, rtxt, txt, flags=re.M)

        return txt
383793
def explicit_rel_links(self, rels=('homepage', 'download')):
        """"""
        for match in self._rel_re.finditer(self.content):
            found_rels = match.group(1).lower().split()
            for rel in rels:
                if rel in found_rels:
                    break
            else:
                continue
            match = self._href_re.search(match.group(0))
            if not match:
                continue
            url = match.group(1) or match.group(2) or match.group(3)
            url = self.clean_link(urlparse.urljoin(self.base_url, url))
            yield Link(url, self)
97928
function replaceLink(str, targets) {
  return str.replace(/\{@link\s+([^}]+)\}/g, function(full, link) {
    if (link in targets) {
      return util.format('[%s](%s)', link, targets[link]);
    } else if (link.match(/^(https?:)?\/\//)) {
      return util.format('[%s](%s)', link, link);
    }
    return link;
  });
}
878237
def fix_e502(self, result):
        """"""
        (line_index, _, target) = get_index_offset_contents(result,
                                                            self.source)
        self.source[line_index] = target.rstrip('\n\r \t\\') + '\n'
498180
def clean_text(self, url, **kwargs):
        """"""
        try:
            return normalize_url(url)
        except UnicodeDecodeError:
            log.warning("Invalid URL: %r", url)
71896
def url_fix(s, charset=None):
    
    if charset:
        warnings.warn("{}.url_fix() charset argument is deprecated".format(__name__), DeprecationWarning)

    scheme, netloc, path, querystring, fragment = urlsplit(s)
    path = quote(path, b'/%')
    querystring = quote_plus(querystring, b':&=')
    return urlunsplit((scheme, netloc, path, querystring, fragment))
1184695
function _convertUrlsToLinks(str) {
    return str.replace(URL_REG_EXP, function(match, url) {
      var punctuation = (url.match(TRAILING_CHAR_REG_EXP) || [])[1] || "",
          opening     = BRACKETS[punctuation];
      url = url.replace(TRAILING_CHAR_REG_EXP, "");

      if (url.split(opening).length > url.split(punctuation).length) {
        url = url + punctuation;
        punctuation = "";
      }
      var realUrl    = url,
          displayUrl = url;
      if (url.length > MAX_DISPLAY_LENGTH) {
        displayUrl = displayUrl.substr(0, MAX_DISPLAY_LENGTH) + "...";
      }
      // Add http prefix if necessary
      if (realUrl.substr(0, 4) === "www.") {
        realUrl = "http://" + realUrl;
      }

      return '<a href="' + realUrl + '">' + displayUrl + '</a>' + punctuation;
    });
  }
962317
def _fix_out_of_sentence_links( alignments, sent_start, sent_end ):
    ''' 
    ''' 
    sent_len = sent_end - sent_start
    j = sent_start
    while j < sent_start + sent_len:
        for rel_id, rel in enumerate( alignments[j][PARSER_OUT] ):
            if int( rel[1] ) >= sent_len:
                # If the link points out-of-the-sentence, fix
                # the link so that it points inside the sentence
                # boundaries:
                wid = j - sent_start
                if sent_len == 1:
                    # a single word becomes a root
                    rel[1] = -1
                elif wid-1 > -1:
                    # word at the middle/end is linked to the previous
                    rel[1] = wid - 1
                elif wid-1 == -1:
                    # word at the beginning is linked to the next
                    rel[1] = wid + 1
                alignments[j][PARSER_OUT][rel_id] = rel
        j += 1
283127
private function fixUriParts($url)
    {
        $position = Str::strpos($url, '?') ?: Str::strpos($url, '#');

        if ($position === false) {
            return $url;
        }

        return Str::substr($url, 0, $position) . '/' . Str::substr($url, $position);
    }
906160
def wrap_url(s, l):
    """"""
    parts = s.split('/')

    if len(parts) == 1:
        return parts[0]
    else:
        i = 0
        lines = []
        for j in range(i, len(parts) + 1):
            tv = '/'.join(parts[i:j])
            nv = '/'.join(parts[i:j + 1])

            if len(nv) > l or nv == tv:
                i = j
                lines.append(tv)

        return '/\n'.join(lines)
1369895
function linkToSrc(shortPath, lineNumber) {
    var splitPath = shortPath.split("/");
    return '<a href="{{srcroot}}' + shortPath+'">' + splitPath[splitPath.length - 1] + '</a>, <a href="{{srcroot}}' + shortPath+'#L'+lineNumber+'">' + lineNumber + '</a>';
    
}
301895
def text_to_url(self, text):
        """"""
        if text.startswith('/'):
            text = text[1:]
        return QUrl(self.home_url.toString()+text+'.html')
326978
function urlEmbed(str) {

                    var urlRegex = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+()&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;

                    var strReplaced = str.replace(urlRegex, function (match) {
                            return '<a href="' + match + '" target="' + options.linkTarget + '">' + match + '</a>';
                        }
                    );
                    return strReplaced;
                }
605773
function compareUrlRoute(currentURL, currentRoute) {
                var regex = /\{(.*)\}/i;
                var arraySize = currentRoute.length,
                    testValue = false;
                for (var i = 0; i < arraySize; i++) {
                    var dynamic = regex.exec(currentRoute[i]);
                    if (dynamic) {
                        document.routeParams[dynamic[1]] = currentURL[i];
                    } else {
                        if (currentRoute[i] === currentURL[i]) {
                            testValue = true;
                        }
                    }
                }

                return testValue;
            }