Пример #1
0
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the titles of a record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    titles = []

    title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    edition_statement = bfo.field('250__a')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')

    if len(title) > 0:
        if title_remainder:
            title += ': ' + title_remainder
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
        titles.append(title)

    title = bfo.field('246__a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__b')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246_1a')
    if len(title) > 0:
        titles.append(title)

    if len(titles) > 0:
        #Display 'Conference' title only if other titles were not found
        title = bfo.field('111__a')
        if len(title) > 0:
            titles.append(title)

    titles = [cgi.escape(x) for x in titles]

    if highlight == 'yes':
        from invenio.modules.formatter import utils as bibformat_utils
        titles = [
            bibformat_utils.highlight(x, bfo.search_pattern) for x in titles
        ]

    if len(edition_statement) > 0:
        return separator.join(titles) + "; " + edition_statement
    else:
        return separator.join(titles)
Пример #2
0
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the titles of a record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    titles = []

    title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    edition_statement = bfo.field('250__a')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')

    if len(title) > 0:
        if title_remainder:
            title += ': ' + title_remainder
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
        titles.append( title )

    title = bfo.field('246__a')
    if len(title) > 0:
        titles.append( title )

    title = bfo.field('246__b')
    if len(title) > 0:
        titles.append( title )

    title = bfo.field('246_1a')
    if len(title) > 0:
        titles.append( title )

    if len(titles) > 0:
        #Display 'Conference' title only if other titles were not found
        title = bfo.field('111__a')
        if len(title) > 0:
            titles.append( title )

    titles = [cgi.escape(x) for x in titles]

    if highlight == 'yes':
        from invenio.modules.formatter import utils as bibformat_utils
        titles = [bibformat_utils.highlight(x, bfo.search_pattern) for x in titles]

    if len(edition_statement) > 0:
        return separator.join(titles) + "; " + edition_statement
    else:
        return separator.join(titles)
def format_element(bfo, highlight="no", force_title_case="no", brief="no", esctitle='0', oldtitles="no"):
    """
    Print a title, with optional subtitles, and optional highlighting.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    @param force_title_case caps First Letter of Each World if set to 'yes'
    @param brief If yes, skip printing subtitles; if no, print complete title:subtitle
    @param esctitle How should escaping of titles in the database be handled?
    @param oldtitles Whether to show old titles in output
    """
    out = ''
    esctitle = int(esctitle)

    titles = bfo.fields('245__', esctitle)
    old_titles = bfo.fields('246__', esctitle)

    # Concatenate all the regular titles (a) and (optionally) subtitles (b)
    for title in titles:
        out += title.get('a', '')
        if brief == "no" and 'b' in title:
            out += ' : ' + title['b']

    # Concatenate any old titles (a) and subtitles(b)
    if oldtitles == "yes":
        for old_title in old_titles:
            out += "<br /><b><i>" + old_title.get('a') + '</i></b>'
            if brief == "no" and 'b' in old_title:
                out += ' : ' + old_title['b']

    # Hilight matching words if requested
    if highlight == 'yes':
        from invenio.modules.formatter import utils
        out = utils.highlight(out, bfo.search_pattern,
                              prefix_tag="<span style='font-weight: bolder'>",
                              suffix_tag='</span>')

    # Force title casing if requested and check if title is allcaps
    if force_title_case.lower() == "yes" and (out.upper() == out or out.find('THE ') >= 0):
        # .title() too dumb; don't cap 1 letter words
        out = ' '.join([word.capitalize() for word in out.split(' ')])

    return out
Пример #4
0
def format_element(bfo, highlight="no", multilang='no'):
    """
    Prints a short title, suitable for brief format.

    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    if multilang == 'yes':
        if bfo.lang == 'fr':
            title = bfo.field('246_1a')
        else:
            title = bfo.field('245__a')
    else:
        title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')
    edition_statement = bfo.field('250__a')

    out = title
    if len(title_remainder) > 0:
        out += ": " + title_remainder
    if len(edition_statement) > 0:
        out += "; " + edition_statement
    if len(title_tome) > 0:
        out += ", " + title_tome
    if len(title_part) > 0:
        out += ": " + title_part

    #Try to display 'Conference' title if other titles were not found
    if out == '':
        out += bfo.field('111__a')

    if highlight == 'yes':
        from invenio.modules.formatter import utils as bibformat_utils
        out = bibformat_utils.highlight(
            out,
            bfo.search_pattern,
            prefix_tag="<span style='font-weight: bolder'>",
            suffix_tag='</style>')

    return out
Пример #5
0
def format_element(bfo, highlight="no", multilang='no'):
    """
    Prints a short title, suitable for brief format.

    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    if multilang == 'yes':
        if bfo.lang == 'fr':
            title = bfo.field('246_1a')
        else:
            title = bfo.field('245__a')
    else:
        title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')
    edition_statement = bfo.field('250__a')

    out = title
    if len(title_remainder) > 0:
        out += ": " + title_remainder
    if len(edition_statement) > 0:
        out += "; " + edition_statement
    if len(title_tome) > 0:
        out += ", " + title_tome
    if len(title_part) > 0:
        out += ": " + title_part

    #Try to display 'Conference' title if other titles were not found
    if out == '':
        out += bfo.field('111__a')

    if highlight == 'yes':
        from invenio.modules.formatter import utils as bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</style>')

    return out
Пример #6
0
def format_element(bfo, limit, separator='; ',
                   extension='[...]',
                   print_links="yes",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   print_affiliation_first='no',
                   interactive="no",
                   highlight="no",
                   affiliations_separator=" ; ",
                   name_last_first="yes",
                   collaboration="yes",
                   id_links="no",
                   markup="html",
                   link_extension="no",
                   suffix=''
                   ):
    """
    Print the list of authors of a record.

    @param limit the maximum number of authors to display
    @param separator the separator between authors.
    @param extension a text printed if more authors than 'limit' exist
    @param print_links if yes, prints the authors as HTML link to their publications
    @param print_affiliations if yes, make each author name followed by its affiliation
    @param affiliation_prefix prefix printed before each affiliation
    @param affiliation_suffix suffix printed after each affiliation
    @param print_affiliation_first if 'yes', affiliation is printed before the author
    @param interactive if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight highlights authors corresponding to search query if set to 'yes'
    @param affiliations_separator separates affiliation groups
    @param name_last_first if yes (default) print last, first  otherwise first last
    @param collaboration if yes (default) uses collaboration name in place of long author list, if available
    @param id_links if yes (default = no) prints link based on INSPIRE IDs if available - only used if print_links = yes
    @param markup html (default) or latex controls small markup differences
    @param link_extension if 'yes' link the extension to the detailed
    record page

    """
    from urllib import quote
    from cgi import escape
    import re
    from invenio.base.i18n import gettext_set_language
    from invenio.base.globals import cfg

    if cfg.get('CFG_BASE_URL'):
        CFG_BASE_URL = cfg.get('CFG_BASE_URL')
    else:
        CFG_BASE_URL = cfg.get('CFG_SITE_URL')

    _ = gettext_set_language(bfo.lang)    # load the right message language

    # regex for parsing last and first names and initials
    re_last_first = re.compile('^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
    re_initials = re.compile(r'(?P<initial>\w)([\w`\']+)?.?\s*', re.UNICODE)
    re_tildehyph = re.compile(ur'(?<=\.)~(?P<hyphen>[\u002D\u00AD\u2010-\u2014-])(?=\w)', re.UNICODE)
    re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)

    bibrec_id = bfo.control_field("001")
    authors = []
    lastauthor = ''
    only_corporate_author = False
    authors = bfo.fields('100__', repeatable_subfields_p=True)
    authors.extend(bfo.fields('700__', repeatable_subfields_p=True))

    # If there are no author check for corporate author in 110__a field
    if len(authors) == 0:
        authors = bfo.fields('110__', repeatable_subfields_p=True)
        if len(authors) > 0:
            only_corporate_author = True
        # For corporate authors we don't want to reverse names order
        name_last_first = 'yes'
        # And we don't want to create links
        print_links = 'no'

    # Keep real num of authors. fix + affiliations_separator.join(author['u']) + \
    nb_authors = len(authors)

    # Limit num of authors, so that we do not process
    # the authors that will not be shown. This can only
    # be done in non-interactive mode, as interactive mode
    # allows to show all of them.
    if limit.isdigit() and nb_authors > int(limit) \
       and interactive != "yes":
        if bfo.field('710g'):   # check for colln note
            authors = authors[:1]
        else:

            authors = authors[:int(limit)]

    # Process authors to add link, affiliation and highlight
    for author in authors:

        if 'a' in author:
            # There should not be repeatable subfields here.
            author['a'] = author['a'][0]
            if highlight == 'yes':
                from invenio.modules.formatter import utils
                author['a'] = utils.highlight(author['a'],
                                              bfo.search_pattern)

            # check if we need to reverse last, first we don't try to reverse
            # it if it isn't stored with a comma.
            first_last_match = re_last_first.search(author['a'])
            author['display'] = author['a']

            if name_last_first.lower() == "no":
                if first_last_match:
                    author['display'] = first_last_match.group('first_names') + \
                                        ' ' + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')

            # for latex we do initials only  (asn assume first last)
            if markup == 'latex':
                if first_last_match:
                    first = re_initials.sub('\g<initial>.~',
                                            unicode(first_last_match.group('first_names'), 'utf8'))
                    first = re_tildehyph.sub('\g<hyphen>', first)
                    author['display'] = (first +
                                         first_last_match.group('last') +
                                         first_last_match.group('extension'))

            if print_links.lower() == "yes":

                # if there is an ID, search using that.
                id_link = ''
                if id_links == "yes" and 'i' in author:
                    # possible to have more IDs?
                    author['i'] = author['i'][0]
                    id_link = ('<a class="authoridlink" href="' +
                               CFG_BASE_URL +
                               '/search?' +
                               'ln=' + bfo.lag +
                               '&amp;p=100__' + escape(':' + author['i']) +
                               '+or+700__i' + escape(':' + author['i']) +
                               '">'+escape("(ID Search)") + '</a> ')

                author['display'] = ('<a class="authorlink" href="' +
                                     CFG_BASE_URL +
                                     '/author/profile/' + quote(author['a']) +
                                     '?recid=' + bibrec_id +
                                     '&amp;ln=' + bfo.lang +
                                     '">' + escape(author['display'])+'</a>' +
                                     id_link)

        if print_affiliations == "yes":
            if 'e' in author:
                author['e'] = (affiliation_prefix +
                               affiliations_separator.join(author['e']) +
                               affiliation_suffix)

            if 'u' in author:
                author['ilink'] = (['<a class="afflink" href="' +
                                    CFG_BASE_URL +
                                    '/search?cc=Institutions&amp;p=institution:' +
                                    quote('"' + string + '"') +
                                    '&amp;ln=' + bfo.lang +
                                    '">' +
                                    string.lstrip() +
                                    '</a>' for string in author['u']])
                author['u'] = (affiliation_prefix +
                               affiliations_separator.join(author['ilink']) +
                               affiliation_suffix)

#
#  Consolidate repeated affiliations
#
    last = ''
    authors.reverse()
    for author in authors:
        if 'u' not in author:
            author['u'] = ''
        # print 'this->'+ author['a']+'\n'
        if last == author['u']:
            author['u'] = ''
        else:
            last = author['u']

    authors.reverse()

    # Flatten author instances
    if print_affiliations == 'yes':
        # 100__a (100__e)  700__a (100__e) (100__u)
        if print_affiliation_first.lower() != 'yes':
            authors = [author.get('display', '') + author.get('e', '') + author.get('u', '')
                       for author in authors]

        else:
            authors = [author.get('u', '') + author.get('display', '')
                       for author in authors]

    else:
        authors = [author.get('display', '')
                   for author in authors]

    # link the extension to detailed record
    if link_extension == 'yes' and interactive != 'yes':
        extension = '<a class="authorlink" href="' +  \
                    CFG_BASE_URL + '/' + cfg.get('CFG_SITE_RECORD') + '/' + str(bfo.recID) + '">' + \
                    extension + '</a>'

    # Detect Collaborations:
    if collaboration == "yes":
        colls = []
        for coll in bfo.fields("710__g"):
            if coll not in colls:
                colls.append(coll)
    else:
        colls = []
    if colls:
        short_coll = False
        colls = [re_coll.sub('', coll) for coll in colls]
        if print_links.lower() == "yes":
            colls = ['<a class="authorlink" href="' +
                     CFG_BASE_URL + '/search' +
                     '?p=collaboration:' + quote("'" + coll + "'") +
                     '&amp;ln=' + bfo.lang +
                     '">'+escape(coll)+'</a>' for coll in colls]

        coll_display = " and ".join(colls)
        if not coll_display.endswith("aboration"):
            coll_display += " Collaboration"
            if len(colls) > 1:
                coll_display += 's'
        if nb_authors > 1:
            if markup == 'latex':
                coll_display = authors[0] + extension + "  [" + \
                               coll_display + "]"
            elif interactive == "yes":
                coll_display += " (" + authors[0] + " "
                extension += ")"
            else:
                # html
                coll_display += " (" + authors[0] + extension + ")"
        elif nb_authors == 1:
            short_coll = True
            if markup == 'latex':
                coll_display = authors[0] + " [" + coll_display + "]"
            else:
                # html
                if not only_corporate_author:
                    coll_display += " (" + authors[0] + " for the collaboration)"
        elif nb_authors == 0:
            short_coll = True
            if markup == 'latex':
                coll_display = "[" + coll_display + "]"

    # Start outputting, depending on options and number of authors
    if colls and (interactive != "yes" or short_coll):
        return coll_display

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        if markup == 'latex':
            lastauthor = authors.pop()
            lastauthor = ' and ' + lastauthor
            limit = int(limit) - 1

        return separator.join(authors[:int(limit)]) + lastauthor + extension

    elif interactive == "yes" and ((colls and not short_coll) or (limit.isdigit() and nb_authors > int(limit))):
        out = '''
        <script>
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = '%(extension)s';
            toggle_authors_visibility();
        }

        </script>
        ''' % {'show_less': _("Hide"),
               'show_more': _("Show all %i authors") % nb_authors,
               'extension': extension}

        # out += '<a name="show_hide" />'
        if colls:
            show = coll_display
            more = separator + separator.join(authors[1:]) + ')'
        else:
            show = separator.join(authors[:int(limit)])
            more = separator.join(authors[int(limit):len(authors)])

        out += show
        out += ' <span id="more" style="">' + more + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#"' + \
               ' style="color:green;background:white;" onclick="toggle_authors_visibility()" ' + \
               ' style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script>set_up()</script>'
        return out
    elif nb_authors > 0:
        if markup == 'latex' and nb_authors > 1:
            lastauthor = authors.pop()
            lastauthor = ' and ' + lastauthor
        output = separator.join(authors) + lastauthor
        # remove the dot from the end of authors list when the suffix starts with dot
        # (to avoid two consecutive dots)
        if suffix and output and output[-1] == suffix[0] == '.':
            output = output[:-1]
        return output
Пример #7
0
def format_element(bfo, limit, separator='; ',
           extension='[...]',
           print_links="yes",
           print_affiliations='no',
           affiliation_prefix=' (',
           affiliation_suffix=')',
           print_affiliation_first='no',
           interactive="no",
           highlight="no",
           affiliations_separator=" ; ",
           name_last_first="yes",
           collaboration="yes",
           id_links="no",
           markup="html",
           link_extension="no",
           ):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param print_affiliation_first: if 'yes', affiliation is printed before the author
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param affiliations_separator: separates affiliation groups
    @param name_last_first: if yes (default) print last, first  otherwise first last
    @param collaboration: if yes (default) uses collaboration name in place of long author list, if available
    @param id_links: if yes (default = no) prints link based on INSPIRE IDs if available - only used if print_links = yes
    @param markup: html (default) or latex controls small markup differences
    @param link_extension: if 'yes' link the extension to the detailed
    record page

    """
    from urllib import quote
    from cgi import escape
    import re
    from invenio.config import CFG_BASE_URL, CFG_SITE_RECORD, CFG_SITE_URL

    #regex for parsing last and first names and initials
    re_last_first = re.compile('^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
    re_initials = re.compile(r'(?P<initial>\w)(\w+|\.)\s*')
    re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)

    from invenio.base.i18n import gettext_set_language

    _ = gettext_set_language(bfo.lang)    # load the right message language

    bibrec_id = bfo.control_field("001")
    authors = []
    authors = bfo.fields('100__', repeatable_subfields_p=True)
    authors.extend(bfo.fields('700__', repeatable_subfields_p=True))

    # Keep real num of authorsfix + affiliations_separator.join(author['u']) + \
    nb_authors = len(authors)

    # Limit num of authors, so that we do not process
    # the authors that will not be shown. This can only
    # be done in non-interactive mode, as interactive mode
    # allows to show all of them.
    if limit.isdigit() and nb_authors > int(limit) \
           and interactive != "yes":
        if bfo.field('710g'):   #check for colln note
            authors = authors[:1]
        else:
            authors = authors[:int(limit)]

    # Process authors to add link, affiliation and highlight
    for author in authors:

        if 'a' in author:
            author['a'] = author['a'][0] # There should not be
            if highlight == 'yes':
                from invenio.modules.formatter import utils as bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            #check if we need to reverse last, first
            #we don't try to reverse it if it isn't stored with a comma.
            first_last_match = re_last_first.search(author['a'])
            author['display'] = author['a']

            if name_last_first.lower() == "no":
                if first_last_match:
                    author['display'] = first_last_match.group('first_names') + \
                                        ' ' + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')

            #for latex we do initials only  (asn assume first last)
            if markup == 'latex':
                if first_last_match:
                    first = re_initials.sub('\g<initial>.~', \
                                        first_last_match.group('first_names'))
                    author['display'] = first + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')


            if print_links.lower() == "yes":

                # if there is an ID, search using that.
                id_link = ''
                if id_links == "yes" and 'i' in author:
                    author['i'] = author['i'][0]  #possible to have more IDs?
                    id_link = '<a class="authoridlink" href="' + \
                              CFG_BASE_URL + \
                              '/search?' + \
                              'ln=' + bfo.lang + \
                              '&amp;p=100__i' + escape(':' + author['i']) + \
                              '+or+700__i' + escape(':' + author['i']) + \
                              '">' + escape("(ID Search)") + '</a> '


                author['display'] = '<a class="authorlink" target="_blank" ' + \
                                    'href="' + \
                                    CFG_SITE_URL + \
                                    '/author/search?q=' + bibrec_id + ':' + \
                                    quote(author['a']) + \
                                    '&ln=' + bfo.lang + \
                                    '">' + escape(author['display']) + '</a>' + \
                                    id_link

        if print_affiliations == "yes":
            if 'e' in author:
                author['e'] = affiliation_prefix + \
                              affiliations_separator.join(author['e']) + \
                              affiliation_suffix



            if 'u' in author:
                author['ilink'] = ['%s' % string.lstrip()
                                   for string in author['u']]
                author['u'] = affiliation_prefix + \
                              affiliations_separator.join(author['ilink']) + \
                              affiliation_suffix



#
#  Consolidate repeated affiliations
#

    last = ''
    authors.reverse()
    for author in authors:
        if 'u' not in author:
            author['u'] = ''
        #print 'this->'+ author['a']+'\n'
        if last == author['u']:
            author['u'] = ''
        else:
            last = author['u']

    authors.reverse()

    # Flatten author instances
    if print_affiliations == 'yes':
#      100__a (100__e)  700__a (100__e) (100__u)
        if print_affiliation_first.lower() != 'yes':
            authors = [author.get('display', '') + author.get('u', '') \
                       for author in authors]

        else:
            authors = [author.get('u', '') + author.get('display', '')  \
                       for author in authors]


    else:
        authors = [author.get('display', '')
                   for author in authors]

    # link the extension to detailed record
    if link_extension == 'yes' and interactive != 'yes':
        extension = '<a class="authorlink" href="' + \
                    CFG_BASE_URL + '/' + CFG_SITE_RECORD + '∕' + str(bfo.recID) + '">' + \
                    extension + '</a>'

    # Detect Collaborations:
    if collaboration == "yes":
        colls = bfo.fields("710__g")
    else:
        colls = []
    if colls:
        short_coll = False
        colls = [re_coll.sub('', coll) for coll in colls]
        if print_links.lower() == "yes":
            colls = ['<a class="authorlink" href="' + \
                     CFG_BASE_URL + '/search' + \
                     '?p=' + quote(coll) + \
                     '&amp;ln=' + bfo.lang + \
                     '&amp;f=collaboration' + \
                     '">' + escape(coll) + '</a>' for coll in colls]

        coll_display = " and ".join(colls)
        if not coll_display.endswith("aboration"):
            coll_display += " Collaboration"
            if len(colls) > 1:
                coll_display += 's'
        if nb_authors > 1:
            if markup == 'latex':
                coll_display = authors[0] + extension + " [ " + \
                               coll_display + " ]"
            elif interactive == "yes":
                coll_display += " (" + authors[0] + " "
                extension += ")"
            else:  #html
                coll_display += " (" + authors[0] + extension + ")"
        elif nb_authors == 1:
            short_coll = True
            if markup == 'latex':
                coll_display = authors[0] + " [ " + coll_display + " ]"
            else:  #html
                coll_display += " (" + authors[0] + " for the collaboration)"
        elif nb_authors == 0:
            short_coll = True
            if markup == 'latex':
                coll_display = "[ " + coll_display + " ]"



    # Start outputting, depending on options and number of authors
    if colls and (interactive != "yes" or short_coll):
        return coll_display

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:len(authors)]) + \
               extension


    elif interactive == "yes" and  ((colls and not short_coll) or (limit.isdigit() and nb_authors > int(limit))):
        out = '''
        <script>
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = '%(extension)s';
            toggle_authors_visibility();
        }

        </script>
        ''' % {'show_less':_("Hide"),
               'show_more':_("Show all %(x_num)i authors", x_num=nb_authors),
               'extension':extension}

#        out += '<a name="show_hide" />'
        if colls:
            show = coll_display
            more = separator + separator.join(authors[1:]) + ')'
        else:
            show = separator.join(authors[:int(limit)])
            more = separator.join(authors[int(limit):len(authors)])

        out += show
        out += ' <span id="more" style="">' + more + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#"' + \
               ' onclick="toggle_authors_visibility()" ' + \
               ' style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script>set_up()</script>'
        return out
    elif nb_authors > 0:
        return separator.join(authors)
Пример #8
0
def format_element(bfo,
                   prefix_en,
                   prefix_fr,
                   suffix_en,
                   suffix_fr,
                   limit,
                   max_chars,
                   extension_en="[...] ",
                   extension_fr="[...] ",
                   contextual="no",
                   highlight='no',
                   print_lang='en,fr',
                   escape="3",
                   separator_en="<br/>",
                   separator_fr="<br/>",
                   latex_to_html='no'):
    """ Prints the abstract of a record in HTML. By default prints
    English and French versions.

    Printed languages can be chosen with the 'print_lang' parameter.

    @param prefix_en: a prefix for english abstract (printed only if english abstract exists)
    @param prefix_fr: a prefix for french abstract (printed only if french abstract exists)
    @param limit: the maximum number of sentences of the abstract to display (for each language)
    @param max_chars: the maximum number of chars of the abstract to display (for each language)
    @param extension_en: a text printed after english abstracts longer than parameter 'limit'
    @param extension_fr: a text printed after french abstracts longer than parameter 'limit'
    @param suffix_en: a suffix for english abstract(printed only if english abstract exists)
    @param suffix_fr: a suffix for french abstract(printed only if french abstract exists)
    @parmm contextual if 'yes' prints sentences the most relative to user search keyword (if limit < abstract)
    @param highlight: if 'yes' highlights words from user search keyword
    @param print_lang: the comma-separated list of languages to print. Now restricted to 'en' and 'fr'
    @param escape: escaping method (overrides default escape parameter to not escape separators)
    @param separator_en: a separator between each english abstract
    @param separator_fr: a separator between each french abstract
    @param latex_to_html: if 'yes', interpret as LaTeX abstract
    """
    out = ''

    if print_lang == 'auto':
        print_lang = bfo.lang
    languages = print_lang.split(',')

    try:
        escape_mode_int = int(escape)
    except ValueError as e:
        escape_mode_int = 0

    abstract_en = bfo.fields('520__a', escape=escape_mode_int)
    abstract_en.extend(bfo.fields('520__b', escape=escape_mode_int))
    abstract_en = separator_en.join(abstract_en)

    abstract_fr = bfo.fields('590__a', escape=escape_mode_int)
    abstract_fr.extend(bfo.fields('590__b', escape=escape_mode_int))
    abstract_fr = separator_fr.join(abstract_fr)

    if contextual == 'yes' and limit != "" and \
           limit.isdigit() and int(limit) > 0:
        context_en = bibformat_utils.get_contextual_content(
            abstract_en, bfo.search_pattern, max_lines=int(limit))
        #FIXME add something like [...] before and after
        #contextual sentences when not at beginning/end of abstract
        #if not abstract_en.strip().startswith(context_en[0].strip()):
        #    out += '[...]'
        abstract_en = "<br/>".join(context_en)

        context_fr = bibformat_utils.get_contextual_content(
            abstract_fr, bfo.search_pattern, max_lines=int(limit))
        abstract_fr = "<br/>".join(context_fr)

    if len(abstract_en) > 0 and 'en' in languages:

        out += prefix_en
        print_extension = False

        if max_chars != "" and max_chars.isdigit() and \
               int(max_chars) < len(abstract_en):
            print_extension = True
            abstract_en = abstract_en[:int(max_chars)]

        if limit != "" and limit.isdigit():
            s_abstract = abstract_en.split(". ")  # Split around
            # DOTSPACE so that we
            # don't split html
            # links

            if int(limit) < len(s_abstract):
                print_extension = True
                s_abstract = s_abstract[:int(limit)]

            #for sentence in s_abstract:
            #    out += sentence + "."
            out = '. '.join(s_abstract)

            # Add final dot if needed
            if abstract_en.endswith('.'):
                out += '.'

            if print_extension:
                out += " " + extension_en

        else:
            out += abstract_en

        out += suffix_en

    if len(abstract_fr) > 0 and 'fr' in languages:

        out += prefix_fr

        print_extension = False

        if max_chars != "" and max_chars.isdigit() and \
               int(max_chars) < len(abstract_fr):
            print_extension = True
            abstract_fr = abstract_fr[:int(max_chars)]

        if limit != "" and limit.isdigit():
            s_abstract = abstract_fr.split(". ")  # Split around
            # DOTSPACE so that we
            # don't split html
            # links

            if int(limit) < len(s_abstract):
                print_extension = True
                s_abstract = s_abstract[:int(limit)]

            #for sentence in s_abstract:
            #    out += sentence + "."
            out += '. '.join(s_abstract)

            # Add final dot if needed
            if abstract_fr.endswith('.'):
                out += '.'

            if print_extension:
                out += " " + extension_fr

        else:
            out += abstract_fr

        out += suffix_fr

    if highlight == 'yes':
        out = bibformat_utils.highlight(out, bfo.search_pattern)

    if latex_to_html == 'yes':
        out = bibformat_utils.latex_to_html(out)

    return out
Пример #9
0
def format_element(bfo, limit, separator=' ; ',
                   extension='[...]',
                   print_links="yes",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   interactive="no",
                   highlight="no",
                   link_author_pages="no",
                   link_mobile_pages="no",
                   relator_code_pattern=None,
                   multiple_affiliations="no",
                   print_orcid="no",
                   orcid_type="text",
                   orcid_text="no",
                   orcid_prefix="[",
                   orcid_postfix="]"):
    """
    Print the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param link_author_pages: should we link to author pages if print_links in on?
    @param link_mobile_pages: should we link to mobile app pages if print_links in on?
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    @param multiple_affiliations: whether all affiliations should be displayed
    @param print_orcid: if yes, make each author name followed by its ORCID
    @param orcid_type: the type of ORCID to be displayed. Accepted values: logo link, text
    @param orcid_text: text to put in a link, if left blank it will use an ORCID
    @param orcid_prefix: prefix for link and plain text
    @param orcid_postfix: postfix for link and plain text
    """
    CFG_BASE_URL = cfg['CFG_BASE_URL'].encode('utf-8')
    CFG_SITE_RECORD = cfg['CFG_BASE_URL'].encode('utf-8')

    from invenio.legacy.bibauthority.config import \
        CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME, \
        CFG_BIBAUTHORITY_TYPE_NAMES, \
        CFG_BIBAUTHORITY_PREFIX_SEP

    _ = gettext_set_language(bfo.lang)    # load the right message language

    authors = []
    authors_1 = bfo.fields('100__', repeatable_subfields_p=True)
    authors_2 = bfo.fields('700__', repeatable_subfields_p=True)

    authors.extend(authors_1)
    authors.extend(authors_2)

    # make unique string per key
    for author in authors:
        if 'a' in author:
            author['a'] = author['a'][0]
        if 'u' in author and multiple_affiliations == 'no':
            author['u'] = author['u'][0]
        if 'v' in author and multiple_affiliations == 'no':
            author['v'] = author['v'][0]
        pattern = '%s' + CFG_BIBAUTHORITY_PREFIX_SEP + "("
        for control_no in author.get('0', []):
            if pattern % (CFG_BIBAUTHORITY_TYPE_NAMES["INSTITUTE"]) in control_no:
                author['u0'] = control_no  # overwrite if multiples
            elif pattern % (CFG_BIBAUTHORITY_TYPE_NAMES["AUTHOR"]) in control_no:
                author['a0'] = control_no  # overwrite if multiples

    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get('4', '')), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add orcid, link, highlight and format affiliation
    for author in authors:

        if 'a' in author:
            if highlight == 'yes':
                from invenio.modules.formatter import utils as bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "yes":
                    author['a'] = '<a rel="author" href="' + CFG_BASE_URL + \
                                  '/author/profile/' + quote(author['a']) + \
                                  '?recid=' + bibrec_id + \
                                  '&ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'
                elif link_mobile_pages == 'yes':
                    author['a'] = '<a rel="external" href="#page=search' + \
                                  '&amp;f=author&amp;p=' + quote(author['a']) + \
                                  '">' + escape(author['a']) + '</a>'
                else:
                    auth_coll_param = ''
                    if 'a0' in author:
                        recIDs = get_low_level_recIDs_from_control_no(
                            author['a0'])
                        if len(recIDs):
                            auth_coll_param = '&amp;c=' + \
                                CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME
                        author['a'] = '<a href="' + CFG_BASE_URL + \
                        '/record/' + str(recIDs[0]) + \
                        '?ln=' + bfo.lang + \
                        '">' + escape(author['a']) + '</a>'
                    else:
                        author['a'] = '<a href="' + CFG_BASE_URL + \
                                  '/search?f=author&amp;p=' + quote(author['a']) + \
                        auth_coll_param + \
                                  '&amp;ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'

        if 'u' in author or 'v' in author:
            if print_affiliations == "yes":
                if 'u0' in author:
                    recIDs = get_low_level_recIDs_from_control_no(author['u0'])
                    # if there is more than 1 recID, clicking on link and
                    # thus displaying the authority record's page should
                    # contain a warning that there are multiple authority
                    # records with the same control number
                    if isinstance(author['u'], (list, tuple)):
                        author['u'] = author['u'][0]
                    if len(recIDs):
                        author['u'] = '<a href="' + CFG_BASE_URL + '/' + CFG_SITE_RECORD + '/' + \
                                      str(recIDs[0]) + \
                                      '?ln=' + bfo.lang + \
                                      '">' + author['u'] + '</a>'
                if 'u' not in author and 'v' in author:
                    author['u'] = author['v']
                if isinstance(author['u'], (list, tuple)):
                    author['u'] = ' '.join([affiliation_prefix + aff +
                                            affiliation_suffix for aff in author['u']])
                else:
                    author['u'] = affiliation_prefix + author['u'] + \
                        affiliation_suffix

        if 'j' in author:
            if print_orcid == "yes":
                orcid = author.get('j', "")
                if orcid[0]:
                    orcid = orcid[0].split(':')[1]
                    if orcid_type == 'logo':
                        author['j'] = '<a href="http://orcid.org/%s" target="_blank" class="author_orcid_image_link" title="%s">&nbsp;</a>' % (orcid, orcid)
                    elif orcid_type == 'link':
                        if orcid_text == "no":
                            author['j'] = '%s<a href="http://orcid.org/%s" target="_blank">%s</a>%s' % (orcid_prefix, orcid, orcid, orcid_postfix)
                        else:
                            author['j'] = '%s<a href="http://orcid.org/%s" target="_blank">%s</a>%s' % (orcid_prefix, orcid, orcid_text, orcid_postfix)
                    else:
                        author['j'] = '%s%s%s' % (orcid_prefix, orcid, orcid_postfix)
                else:
                    author['j'] = ""

    # Flatten author instances
    new_authors = []
    for author in authors:
        auth = author.get('a', '')
        if print_orcid == 'yes':
            auth = auth + author.get('j', '')
        if print_affiliations == 'yes':
            auth = auth + author.get('u', '')
        new_authors.append(auth)
    authors = new_authors

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more_%s" style="">' % bibrec_id + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += '''
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        ''' % {'show_less': _("Hide"),
               'show_more': _("Show all %(x_num)i authors", x_num=nb_authors),
               'extension': extension,
               'recid': bibrec_id}
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
Пример #10
0
def format_element(bfo, limit, separator=' ; ',
           extension='[...]',
           print_links="yes",
           print_affiliations='no',
           affiliation_prefix=' (',
           affiliation_suffix=')',
           interactive="no",
           highlight="no",
           link_author_pages="no",
           link_mobile_pages="no",
           relator_code_pattern=None):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param link_author_pages: should we link to author pages if print_links in on?
    @param link_mobile_pages: should we link to mobile app pages if print_links in on?
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    """
    CFG_SITE_URL = cfg['CFG_SITE_URL']
    if isinstance(CFG_SITE_URL, six.text_type):
        CFG_SITE_URL = CFG_SITE_URL.encode('utf8')

    _ = gettext_set_language(bfo.lang)    # load the right message language

    authors = []
    authors_1 = bfo.fields('100__', repeatable_subfields_p=True)
    authors_2 = bfo.fields('700__', repeatable_subfields_p=True)

    authors.extend(authors_1)
    authors.extend(authors_2)

    # make unique string per key
    for author in authors:
        if 'a' in author:
            author['a'] = author['a'][0]
        if 'u' in author:
            author['u'] = author['u'][0]
        pattern = '%s' + CFG_BIBAUTHORITY_PREFIX_SEP + "("
        for control_no in author.get('0', []):
            if pattern % (CFG_BIBAUTHORITY_TYPE_NAMES["INSTITUTION"]) in control_no:
                author['u0'] = control_no # overwrite if multiples
            elif pattern % (CFG_BIBAUTHORITY_TYPE_NAMES["AUTHOR"]) in control_no:
                author['a0'] = control_no # overwrite if multiples


    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get('4', '')), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if 'a' in author:
            if highlight == 'yes':
                from invenio.modules.formatter import utils as bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "yes":
                    author['a'] = '<a rel="author" href="/author/' + quote(author['a']) + \
                                  '?recid=' +  bibrec_id + \
                                  '&ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'
                elif link_mobile_pages == 'yes':
                    author['a'] = '<a rel="external" href="#page=search' + \
                                  '&amp;f=author&amp;p=' + quote(author['a']) + \
                                  '">' + escape(author['a']) + '</a>'
                else:
                    auth_coll_param = ''
                    if 'a0' in author:
                        recIDs = get_low_level_recIDs_from_control_no(author['a0'])
                        if len(recIDs):
                            auth_coll_param = '&amp;c=' + \
                                              CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME
                    author['a'] = '<a href="/search?f=author&amp;p=' + quote(author['a']) + \
                                   auth_coll_param + \
                                  '&amp;ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'

        if 'u' in author:
            if print_affiliations == "yes":
                if 'u0' in author:
                    recIDs = get_low_level_recIDs_from_control_no(author['u0'])
                    # if there is more than 1 recID, clicking on link and
                    # thus displaying the authority record's page should
                    # contain a warning that there are multiple authority
                    # records with the same control number
                    if len(recIDs):
                        author['u'] = '<a href="/record/' + \
                                      str(recIDs[0]) + \
                                      '?ln=' + bfo.lang + \
                                      '">' + author['u'] + '</a>'
                author['u'] = affiliation_prefix + author['u'] + \
                              affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [author.get('a', '') + author.get('u', '')
                   for author in authors]
    else:
        authors = [author.get('a', '')
                   for author in authors]

    if limit.isdigit() and  nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more_%s" style="">' % bibrec_id + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += '''
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        ''' % {'show_less':_("Hide"),
             'show_more':_("Show all %(x_num)i authors", x_num=nb_authors),
             'extension':extension,
             'recid': bibrec_id}
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
Пример #11
0
def format_element(bfo, prefix_en, prefix_fr, suffix_en, suffix_fr, limit, max_chars,
           extension_en="[...] ",extension_fr="[...] ", contextual="no",
           highlight='no', print_lang='en,fr', escape="3",
           separator_en="<br/>", separator_fr="<br/>", latex_to_html='no'):
    """ Prints the abstract of a record in HTML. By default prints
    English and French versions.

    Printed languages can be chosen with the 'print_lang' parameter.

    @param prefix_en: a prefix for english abstract (printed only if english abstract exists)
    @param prefix_fr: a prefix for french abstract (printed only if french abstract exists)
    @param limit: the maximum number of sentences of the abstract to display (for each language)
    @param max_chars: the maximum number of chars of the abstract to display (for each language)
    @param extension_en: a text printed after english abstracts longer than parameter 'limit'
    @param extension_fr: a text printed after french abstracts longer than parameter 'limit'
    @param suffix_en: a suffix for english abstract(printed only if english abstract exists)
    @param suffix_fr: a suffix for french abstract(printed only if french abstract exists)
    @parmm contextual if 'yes' prints sentences the most relative to user search keyword (if limit < abstract)
    @param highlight: if 'yes' highlights words from user search keyword
    @param print_lang: the comma-separated list of languages to print. Now restricted to 'en' and 'fr'
    @param escape: escaping method (overrides default escape parameter to not escape separators)
    @param separator_en: a separator between each english abstract
    @param separator_fr: a separator between each french abstract
    @param latex_to_html: if 'yes', interpret as LaTeX abstract
    """
    out = ''

    if print_lang == 'auto':
        print_lang = bfo.lang
    languages = print_lang.split(',')

    try:
        escape_mode_int = int(escape)
    except ValueError as e:
        escape_mode_int = 0

    abstract_en = bfo.fields('520__a', escape=escape_mode_int)
    abstract_en.extend(bfo.fields('520__b', escape=escape_mode_int))
    abstract_en = separator_en.join(abstract_en)

    abstract_fr = bfo.fields('590__a', escape=escape_mode_int)
    abstract_fr.extend(bfo.fields('590__b', escape=escape_mode_int))
    abstract_fr = separator_fr.join(abstract_fr)

    if contextual == 'yes' and limit != "" and \
           limit.isdigit() and int(limit) > 0:
        context_en = bibformat_utils.get_contextual_content(abstract_en,
                                                            bfo.search_pattern,
                                                            max_lines=int(limit))
        #FIXME add something like [...] before and after
        #contextual sentences when not at beginning/end of abstract
        #if not abstract_en.strip().startswith(context_en[0].strip()):
        #    out += '[...]'
        abstract_en = "<br/>".join(context_en)

        context_fr = bibformat_utils.get_contextual_content(abstract_fr,
                                                            bfo.search_pattern,
                                                            max_lines=int(limit))
        abstract_fr = "<br/>".join(context_fr)

    if len(abstract_en) > 0 and 'en' in languages:

        out += prefix_en
        print_extension = False

        if max_chars != "" and max_chars.isdigit() and \
               int(max_chars) < len(abstract_en):
            print_extension = True
            abstract_en = abstract_en[:int(max_chars)]

        if limit != "" and limit.isdigit():
            s_abstract = abstract_en.split(". ") # Split around
                                                 # DOTSPACE so that we
                                                 # don't split html
                                                 # links

            if int(limit) < len(s_abstract):
                print_extension = True
                s_abstract = s_abstract[:int(limit)]

            #for sentence in s_abstract:
            #    out += sentence + "."
            out = '. '.join(s_abstract)

            # Add final dot if needed
            if abstract_en.endswith('.'):
                out += '.'

            if print_extension:
                out += " " + extension_en

        else:
            out += abstract_en

        out += suffix_en

    if len(abstract_fr) > 0 and 'fr' in languages:

        out += prefix_fr

        print_extension = False

        if max_chars != "" and max_chars.isdigit() and \
               int(max_chars) < len(abstract_fr):
            print_extension = True
            abstract_fr = abstract_fr[:int(max_chars)]

        if limit != "" and limit.isdigit():
            s_abstract = abstract_fr.split(". ") # Split around
                                                 # DOTSPACE so that we
                                                 # don't split html
                                                 # links

            if int(limit) < len(s_abstract):
                print_extension = True
                s_abstract = s_abstract[:int(limit)]

            #for sentence in s_abstract:
            #    out += sentence + "."
            out += '. '.join(s_abstract)

            # Add final dot if needed
            if abstract_fr.endswith('.'):
                out += '.'

            if print_extension:
                out += " "+extension_fr

        else:
            out += abstract_fr

        out += suffix_fr

    if highlight == 'yes':
        out = bibformat_utils.highlight(out, bfo.search_pattern)

    if latex_to_html == 'yes':
        out = bibformat_utils.latex_to_html(out)

    return out