I have question about possibility to render the url in a reference as an actual url. Url:s are rendered as (example):
<span class="citeproc-URL">http://journals.lub.lu.se/index.php/pfs/article/view/7762</span>
Have I missed something here or is this an issue I have to solve in another way outside this module?

Issue fork bibcite-2840618

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Anonymous’s picture

maxmannen created an issue. See original summary.

kruhak’s picture

For the moment we use citeproc-php library for rendering citations. As I know this library doesn't support rendering of URL's.

I can suggest to use Views for rendering "Reference" properties as additional HTML after citation.

kruhak’s picture

Status: Active » Postponed

Mark this postponed till the moment when we start working on the rendering library.

namwebs’s picture

I can suggest to use Views for rendering "Reference" properties as additional HTML after citation.

Can you please explain a little what you mean?

Also, for references with a file (added as described in the last entry here:https://www.drupal.org/node/2849258) - is it possible to get these to show in a View which is set to show Reference / Citation?

lolcode’s picture

It does look like this could be supported in the seboettg/citeproc-php library. For example by adding a hook to allows site managers to register lambda functions.

https://github.com/seboettg/citeproc-php#use-lambda-functions-to-setup-c...

swild-ma’s picture

Fully agree with lolcode (#5). Any plans on this?

mark_fullmer’s picture

Version: 8.x-1.x-dev » 3.0.x-dev
Category: Support request » Feature request
Status: Postponed » Active
mark_fullmer’s picture

Individual sites could also potentially rewrite such URLs as actual hyperlinks by implementing HOOK__preprocess_bibcite_citation(), which provides access to the already-rendered citation. Presumably you could use regular expressions to find/replace specific markup with hyperlinks. This would not be as elegant a solution as using Lambda functions to modify the citation processor itself, as described in https://github.com/seboettg/citeproc-php#use-lambda-functions-to-setup-c... , but might be more straightforward for some developers.

swild-ma’s picture

Thanks. Yes, that should be possible but because I also want to put the title into a span, I would have to rerender the whole citation in HOOK__preprocess_bibcite_citation().
This can be avoided by overriding the BibCiteProcessor plugin (citeproc-php) with HOOK_bibcite_bibcite_processor_info_alter() and passing the lambda functions to CiteProc() in render() there.

mark_fullmer’s picture

Category: Feature request » Support request

Okay, changing this to a "Support request." Let's try to add some documentation that shows example usage of both HOOK__preprocess_bibcite_citation() and HOOK_bibcite_bibcite_processor_info_alter()

swild-ma’s picture

This is the first time I am posting; unsure how to proceed. If appropriate I can supply some code snippets related to the info_alter option.

mark_fullmer’s picture

This is the first time I am posting; unsure how to proceed. If appropriate I can supply some code snippets related to the info_alter option.

Code snippets in a comment would be a great start. I can then move them into a new page under the documentation at https://www.drupal.org/docs/contributed-modules/bibliography-citation

swild-ma’s picture

In MYMODULE.module:

/**
 * Overwrite the plugin Drupal\bibcite\Plugin\BibCiteProcessor\CiteprocPhp.
 * We want to be able to use the Lambda functions of seboettg/citeproc-php.
 * See \vendor\seboettg\citeproc-php\README.md.
 *
 * (If it is not clear whether this function gets called, flush
 * the plugins cache...)
 */
function MYMODULE_bibcite_bibcite_processor_info_alter(array &$definitions) {
  $definitions['citeproc-php']['class'] =
  'Drupal\MYMODULE\Plugin\BibCiteProcessor\CiteprocPhpFOOBAR';
}

MYMODULE\src\Plugin\BibCiteProcessor\CiteprocPhpFOOBAR.php:

<?php

namespace Drupal\MYMODULE\Plugin\BibCiteProcessor;

use Seboettg\CiteProc\CiteProc;
use Drupal\bibcite\Plugin\BibCiteProcessor\CiteprocPhp;

/**
 * Defines a style provider based on citeproc-php library.
 * This class extends the original class 
 * \vendor\seboettg\citeproc-php\src\CiteProc.php.
 *
 * @BibCiteProcessor(
 *   id = "citeproc-php-FOOBAR",
 *   label = @Translation("Citeproc PHP (FOOBAR)"),
 * )
 */
class CiteprocPhpFOOBAR extends CiteprocPhp {

  /**
   * {@inheritdoc}
   *
   * WARNING: This function is an example only. Your mileage *will* vary
   * depending on several factors; e.g. the CSL you are using.
   */
  public function render($data, $csl, $lang) {
    //
    // The following are Lambda functions for seboettg/citeproc-php.
    // See \vendor\seboettg\citeproc-php\README.md.
    $title_function = function($cslItem, $renderedText) {
      //
      // Add some classes to the title
      $title = '<span class="citeproc-title-and-descriptions">';
      $title .= '<span class="citeproc-title">';
      $title .= $renderedText;
      $title .= '</span></span>';
      return $title;
    };
    $doi_function = function($cslItem, $renderedText) {
      //
      // Pack the URL in an anchor
      //
      // WARNING: The situation here is quite complicated
      // and what can be done here probably depends on the
      // active CSL and on the contents of the DOI field 
      // in your bibcite records.
      // (See also the comment below.)
      $doi_link = '<span class="citeproc-access">';
      $doi_link .= '<a href="';
      if (!str_starts_with($renderedText, 'http')) {
        $doi_link .= 'https://doi.org/';
      }
      $doi_link .= $renderedText . '" target="_blank">';
      $doi_link .= '(abstract)</a></span>';
      return $doi_link;
    };
    $additionalMarkup = [
      'title' => $title_function,
      'DOI' => $doi_function
    ];
    
    $cite_proc = new CiteProc($csl, $lang, $additionalMarkup);
    if (!$data instanceof \stdClass) {
      $data = json_decode(json_encode($data));
    }
    $res = preg_replace('/(\\n|\r)( *)/', '', $cite_proc->render([$data]));
    //
    // CSLs can contain prefixes and suffixes. They are added  
    // only *after* the lambda functions above have run. As an 
    // alternative to the code below we could of course craft 
    // our own CSLs...
    //
    // We have to remove the prefix ('https://doi.org/') of the 
    // access field here because it has been added *after* we have 
    // already added a span around our anchor tag in $doi_function.
    $res = str_replace('https://doi.org/<span class="citeproc-access">',
                       '<span class="citeproc-access">', $res);
    //
    // Remove some unwanted <i>-Tags
    $res = str_replace(array('<i>', '</i>'), '', $res);
    return $res;
  }
}
mark_fullmer’s picture

Title: Render url in reference » Add option to render URLs in citations as hyperlinks
Assigned: Unassigned » mark_fullmer
Category: Support request » Feature request

mark_fullmer’s picture

After thinking about this further, I think that this is a common, reasonable request that should not require a developer in order to accomplish. I therefore propose adding a new, global setting to Bibcite for "Convert URLs into hyperlinks".

When enabled, this will pass the already-processed citation through Drupal core's _filter_url() function, which is robust and designed to handled a wide range of HTML content.

This approach does not give sites the ability to have some URLs be hyperlinks and others not be hyperlinks -- that, I feel, still should be the purlieu of developers and custom code.

mark_fullmer’s picture

Status: Active » Needs review
mark_fullmer’s picture

Status: Needs review » Fixed

As this is an opt-feature, I feel comfortable merging this in; should there need to be refinements, we can work those out subsequently.

  • mark_fullmer committed bf508668 on 3.0.x
    Issue #2840618 by mark_fullmer, swild-ma, kruhak: Add option to render...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

erwangel’s picture

The option proposed in MR43 indeed turns urls (doi and other locations) to hyperlinks but we still need an option to turn author and title in citation field to hyperlinks. As for now the only way I see is to play with HOOK_preprocess_bibcite_citation() and rewrite the content #markup after creating the entity's url in HOOK_bibcite_reference and push it to $variables['content']['citation']['#data'] as entity's id is not available in HOOK_preprocess_bibcite_citation variables['data'].