JSFiddle - React, Tailwind, and code Playground

by Max Kovalov

HTML

<body>
  <p class="authors">
    Mertens, Jean-Francois;-;[email protected];-;;-;CORE, Universite Catholique de Louvain;-;!-!Rubinchik, Anna;-;[email protected];-;http://econ.haifa.ac.il/~arubinchik;-;Department of Economics, University of Haifa;-;http://hevra.haifa.ac.il/econ/en
  </p>
  <p class="authors">
    Mertens, Jean-Francois2;-;[email protected];-;;-;CORE, Universite Catholique de Louvain;-;!-!Rubinchik2, Anna;-;[email protected];-;http://econ.haifa.ac.il/~arubinchik;-;Department of Economics, University of Haifa;-;http://hevra.haifa.ac.il/econ/en
  </p>

</body>

JavaScript

var authors = document.querySelectorAll(".authors");

Array.prototype.slice.call(authors)
  .map(function(auth) {
    return auth.innerHTML = names(auth.innerHTML);
  });


function parse_data(data) {
  var RECORD_SEPARATOR = ";-;!-!";
  var FIELD_SEPARATOR = ";-;";

  return data
    .split(RECORD_SEPARATOR)
    .map(function(line) {
      return line.split(FIELD_SEPARATOR);
    })
    .map(function(recordArr) {
      return {
        full_name: recordArr[0],
        email: recordArr[1],
        website: recordArr[2],
        work: recordArr[3]
      };
    });
}

function names(data) {
  return array_to_coma_string(
    parse_data(data)
    .map(function(record) {
      return record.full_name;
    })
  );
}

function array_to_coma_string(a) {
  return [a.slice(0, -1).join(', '), a.slice(-1)[0]].join(a.length < 2 ? '' : ' and ');
}