Return reference ID from href or text content.
509924
def _parse_reference(self, el):
        """"""
        if '#' in el.get('href', ''):
            return [el.get('href').split('#', 1)[1]]
        elif 'rid' in el.attrib:
            return [el.attrib['rid']]
        elif 'idref' in el.attrib:
            return [el.attrib['idref']]
        else:
            return [''.join(el.itertext()).strip()]
1357864
def get_ref(self, reftype, index):
        """"""
        try:
            got_reftype, data = self.refs[int(index)]
        except (IndexError, ValueError):
            raise CoconutInternalException("no reference at invalid index", index)
        internal_assert(got_reftype == reftype, "wanted " + reftype + " reference; got " + got_reftype + " reference")
        return data
787173
def _get_id(self):
        """"""
        ret = None
        row = self.row
        if row:
            ret = row["id"]
        return ret
448165
def getreference(self, validate=True):
        """"""

        if self.offset is None: return None #nothing to test
        if self.ref:
            ref = self.doc[self.ref]
        else:
            ref = self.finddefaultreference()

        if not ref:
            raise UnresolvableTextContent("Default reference for phonetic content not found!")
        elif not ref.hasphon(self.cls):
            raise UnresolvableTextContent("Reference has no such phonetic content (class=" + self.cls+")")
        elif validate and self.phon() != ref.textcontent(self.cls).phon()[self.offset:self.offset+len(self.data[0])]:
            raise UnresolvableTextContent("Reference (class=" + self.cls+") found but no phonetic match at specified offset ("+str(self.offset)+")! Expected '" + self.text() + "', got '" + ref.textcontent(self.cls).text()[self.offset:self.offset+len(self.data[0])] +"'")
        else:
            #finally, we made it!
            return ref
553091
def _target_id_from_htm(self, line):
        
        # Detecting modern mbed.htm file format
        m = re.search("\\?code=([a-fA-F0-9]+)", line)
        if m:
            result = m.groups()[0]
            return result
        # Last resort, we can try to see if old mbed.htm format is there
        m = re.search("\\?auth=([a-fA-F0-9]+)", line)
        if m:
            result = m.groups()[0]
            return result

        return None
794513
def get_sentence_id(self, element):
        """"""
        try:
            sentence_elem = element.iterancestors('sentence').next()
        except StopIteration as e:
            warnings.warn("<{}> element is not a descendant of a <sentence> "
                          "We'll try to extract the sentence ID from the "
                          "prefix of the element ID".format(element.tag))
            return self.get_element_id(element).split('_')[0]
        return self.get_element_id(sentence_elem)
1261882
function idFromReference(url) {
  var m = url.toString().match(SVG.regex.reference)

  if (m) return m[1]
}
364072
def links(cls, page):
    """"""
    for match in cls.HREF_RE.finditer(page):
      yield cls.href_match_to_url(match)
1115556
def replace_references(self, node):
        
        href = node.getAttribute('href')
        if href is None:
            return
        id = href.getValue()
        ref = self.catalog.get(id)
        if ref is None:
            log.error('soap multiref: %s, not-resolved', id)
            return
        node.append(ref.children)
        node.setText(ref.getText())
        for a in ref.attributes:
            if a.name != 'id':
                node.append(a)
        node.remove(href)
395305
def _parse_references(xml):
    """"""
    references = []
    ref_finder = HTMLReferenceFinder(xml)
    for elm, uri_attr in ref_finder:
        type_ = _discover_uri_type(elm.get(uri_attr))
        references.append(Reference(elm, type_, uri_attr))
    return references
1273844
function extractReferencedId(value) {
  var v = value.replace(/[\s]/g, '');
  if(v.indexOf('url') !== 0) {
    return false;
  }
  return value.replace(/[\s]/g, '').slice(4, -1).replace(/["']/g, '');
}
94365
def link(self, link, title, text):
        
        if self.anonymous_references:
            underscore = '__'
        else:
            underscore = '_'
        if title:
            return self._raw_html(
                '<a href="{link}" title="{title}">{text}</a>'.format(
                    link=link, title=title, text=text
                )
            )
        if not self.parse_relative_links:
            return '\ `{text} <{target}>`{underscore}\ '.format(
                target=link,
                text=text,
                underscore=underscore
            )
        else:
            url_info = urlparse(link)
            if url_info.scheme:
                return '\ `{text} <{target}>`{underscore}\ '.format(
                    target=link,
                    text=text,
                    underscore=underscore
                )
            else:
                link_type = 'doc'
                anchor = url_info.fragment
                if url_info.fragment:
                    if url_info.path:
                        # Can't link to anchors via doc directive.
                        anchor = ''
                    else:
                        # Example: [text](#anchor)
                        link_type = 'ref'
                doc_link = '{doc_name}{anchor}'.format(
                    # splittext approach works whether or not path is set. It
                    # will return an empty string if unset, which leads to
                    # anchor only ref.
                    doc_name=os.path.splitext(url_info.path)[0],
                    anchor=anchor
                )
                return '\ :{link_type}:`{text} <{doc_link}>`\ '.format(
                    link_type=link_type,
                    doc_link=doc_link,
                    text=text
                )
1214807
private int extractValidIndex(ElementReference ref) {
        Reference<E> iRef = asIndexedRef(ref);
        int idx = iRef.index;
        if (idx < 0 || idx >= size) {
            throw new InvalidReferenceException(
                    "Index " + idx + " is not valid for collection with size " + size + ".");
        }
        return idx;
    }
674578
def reference_id(self, index):
        """"""
        # TODO Include ISBN and ISSN?
        doi = self.reference_doi(index)
        if doi:
            return doi
        else:
            pmid = self.reference_pmid(index)
            if pmid:
                return "PMID_" + pmid
            else:
                unpublished_id = self.reference_unpublished_id(index)
                if unpublished_id:
                    return "UNPUBLISHED_" + unpublished_id
        return ""
479763
def get_page_from_string_or_id(page_string, lang=None):
    """"""
    if type(page_string) == int:
        return Page.objects.get(pk=int(page_string))
    # if we have a string coming from some templates templates
    if (isinstance(page_string, SafeText) or
            isinstance(page_string, str)):
        if page_string.isdigit():
            return Page.objects.get(pk=int(page_string))
        return Page.objects.from_path(page_string, lang)
    # in any other case we return the input becasue it's probably
    # a Page object.
    return page_string
1316399
def reference_text(ref):
    '''
    '''

    ref_wrap = textwrap.TextWrapper(initial_indent='', subsequent_indent=' ' * 8)

    s = ''
    if ref['type'] == 'unpublished':
        s += ref_wrap.fill(', '.join(ref['authors'])) + '\n'
        s += ref_wrap.fill(ref['title']) + '\n'
        s += ref_wrap.fill(ref['note']) + '\n'
    elif ref['type'] == 'article':
        s += ref_wrap.fill(', '.join(ref['authors'])) + '\n'
        s += ref_wrap.fill(ref['title']) + '\n'
        s += '{}, {}, {} ({})'.format(ref['journal'], ref['volume'], ref['page'], ref['year'])
        s += '\n' + ref['doi']
    elif ref['type'] == 'incollection':
        s += ref_wrap.fill(', '.join(ref['authors']))
        s += ref_wrap.fill('\n{}'.format(ref['title']))
        s += ref_wrap.fill('\nin \'{}\''.format(ref['booktitle']))
        if 'editors' in ref:
            s += ref_wrap.fill('\ned. ' + ', '.join(ref['editors']))
        if 'series' in ref:
            s += '\n{}, {}, {} ({})'.format(ref['series'], ref['volume'], ref['page'], ref['year'])
        if 'doi' in ref:
            s += '\n' + ref['doi']
    elif ref['type'] == 'techreport':
        s += ref_wrap.fill(', '.join(ref['authors']))
        s += ref_wrap.fill('\n{}'.format(ref['title']))
        s += '\n\'{}\''.format(ref['institution'])
        s += '\nTechnical Report {}'.format(ref['number'])
        s += '\n{}'.format(ref['year'])
        if 'doi' in ref:
            s += '\n' + ref['doi']
    elif ref['type'] == 'misc':
        s += ref_wrap.fill(', '.join(ref['authors'])) + '\n'
        s += ref_wrap.fill(ref['title'])
        if 'note' in ref:
            s += '\n' + ref['note']
        if 'doi' in ref:
            s += '\n' + ref['doi']
    else:
        raise RuntimeError('Cannot handle reference type {}'.format(ref['type']))
    return s
602604
def get_obj(ref):
    """"""
    oid = int(ref)
    return server.id2ref.get(oid) or server.id2obj[oid]