Skip to content

Commit

Permalink
Merge pull request #393 from Inist-CNRS/meta-mutlilines
Browse files Browse the repository at this point in the history
feat: allow multilines metadata values
  • Loading branch information
touv authored Dec 20, 2023
2 parents 10e91e6 + 8f342f1 commit 50073b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const regex = {
};

export default function Meta(ezs, commands) {
const lines = commands.split(/\r\n|\r|\n/);
const lines = commands.split('\\\n').join('').split(/\r\n|\r|\n/);
const result = {};
let meta = true;
lines.forEach((line) => {
if (!regex.comment.test(line)) {
if (regex.param.test(line) && meta) {
const match = line.match(regex.param);
const paramName = match[1];
const paramValue = match[2];
const paramValue = match[2].replace(/\^M/g, '\n');
result[paramName] = paramValue;
} else if (regex.section.test(line)) {
meta = false;
Expand Down
7 changes: 5 additions & 2 deletions packages/core/test/ezs.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,13 @@ describe('Build a pipeline', () => {
done();
});
});
it('Catch meta from script', (done) => {
it('Catch meta from script #1', (done) => {
const commands = `
title = Le titre
description = La description
description = \
La description
summary = Line1 ^M Line2 ^M Line3
[replace]
path = a
Expand All @@ -870,6 +872,7 @@ describe('Build a pipeline', () => {
const meta = ezs.metaString(commands);
assert.strictEqual(meta.title, 'Le titre');
assert.strictEqual(meta.description, 'La description');
assert.strictEqual(meta.summary, 'Line1 \n Line2 \n Line3');
done();
});

Expand Down

0 comments on commit 50073b2

Please sign in to comment.