diff --git a/src/text/inlineFields.js b/src/text/inlineFields.js index 3bf48f9..abd5069 100644 --- a/src/text/inlineFields.js +++ b/src/text/inlineFields.js @@ -41,8 +41,8 @@ function parseWithParenthesis (str) { // Accepts embedded pairs between parentheses (like::this) function extractInlineFields (str) { - const result = [] - for (const line of str.split('\n')) { + function extract (line) { + const result = [] for (const inline of parseWithParenthesis(line)) { if (inline.chunks.length > 1) { result.push(inline) @@ -55,8 +55,10 @@ function extractInlineFields (str) { } } } + return result } - return result + + return str.split('\n').map(extract).flat() } diff --git a/test/text/__snapshots__/inlineFields.js.snap b/test/text/__snapshots__/inlineFields.js.snap index bf9ccfe..b615746 100644 --- a/test/text/__snapshots__/inlineFields.js.snap +++ b/test/text/__snapshots__/inlineFields.js.snap @@ -125,6 +125,13 @@ Array [ ], "raw": "a::b", }, + Object { + "chunks": Array [ + "c", + "d", + ], + "raw": "c::d", + }, ] `; @@ -139,6 +146,13 @@ Array [ ], "raw": "a::b", }, + Object { + "chunks": Array [ + "c", + "d", + ], + "raw": "c::d", + }, ] `; @@ -153,6 +167,14 @@ Array [ ], "raw": "a::b::c", }, + Object { + "chunks": Array [ + "a", + "f", + "d", + ], + "raw": "a::f::d", + }, ] `; @@ -167,6 +189,13 @@ Array [ ], "raw": "a::b", }, + Object { + "chunks": Array [ + "a", + "f", + ], + "raw": "a::f", + }, ] `; @@ -292,21 +321,21 @@ between c::d 1`] = ` " between -c::d" +" `; exports[`removeInlineFields a::b c::d after 1`] = ` " -c::d + after" `; exports[`removeInlineFields a::b::c a::f::d 1`] = ` " -a::f::d" +" `; exports[`removeInlineFields before @@ -314,7 +343,7 @@ a::b a::f 1`] = ` "before -a::f" +" `; exports[`removeInlineFields http://example.org :: is a :: website 1`] = `""`; diff --git a/test/text/inlineFields.js b/test/text/inlineFields.js index 2aa6ac0..3f5d049 100644 --- a/test/text/inlineFields.js +++ b/test/text/inlineFields.js @@ -26,7 +26,7 @@ const markdown = [ 'before\na::b\na::f', 'a::b\nbetween\nc::d', 'a::b\nc::d\nafter', - 'lives in :: [Test with relative](../houses/BobHouse.md)' + 'lives in :: [Test with relative](../houses/BobHouse.md)', ] expect.extend({ toMatchSnapshot })