Skip to content

Commit

Permalink
fix: inline field
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianvasquez committed Dec 30, 2022
1 parent af4ebbf commit b8ad291
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/text/inlineFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -55,8 +55,10 @@ function extractInlineFields (str) {
}
}
}
return result
}
return result

return str.split('\n').map(extract).flat()

}

Expand Down
37 changes: 33 additions & 4 deletions test/text/__snapshots__/inlineFields.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ Array [
],
"raw": "a::b",
},
Object {
"chunks": Array [
"c",
"d",
],
"raw": "c::d",
},
]
`;

Expand All @@ -139,6 +146,13 @@ Array [
],
"raw": "a::b",
},
Object {
"chunks": Array [
"c",
"d",
],
"raw": "c::d",
},
]
`;

Expand All @@ -153,6 +167,14 @@ Array [
],
"raw": "a::b::c",
},
Object {
"chunks": Array [
"a",
"f",
"d",
],
"raw": "a::f::d",
},
]
`;

Expand All @@ -167,6 +189,13 @@ Array [
],
"raw": "a::b",
},
Object {
"chunks": Array [
"a",
"f",
],
"raw": "a::f",
},
]
`;

Expand Down Expand Up @@ -292,29 +321,29 @@ 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
a::b
a::f 1`] = `
"before
a::f"
"
`;

exports[`removeInlineFields http://example.org :: is a :: website 1`] = `""`;
Expand Down
2 changes: 1 addition & 1 deletion test/text/inlineFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit b8ad291

Please sign in to comment.