Fix the indexing of the fromMarkdown fragments

This commit is contained in:
Tessa Kelly 2023-03-09 15:45:40 -07:00
parent 777fbba780
commit 3d33ce400b
2 changed files with 12 additions and 2 deletions

View File

@ -21,6 +21,7 @@ just a single whitespace.
- remove initFragment, splitHighlightableOnWords, splitWords
- remove toggle, which is not used
- rename groupIndex -> index
- ensure that fromMarkdown indexes the fragments correctly
## Types
@ -330,6 +331,7 @@ fromMarkdown markdownString =
)
( Nothing, [] )
|> Tuple.second
|> List.indexedMap (\i highlightable -> { highlightable | index = i })
{-| -}

View File

@ -126,8 +126,16 @@ fromMarkdownSpec =
let
testFromMarkdown startingString expected =
Highlightable.fromMarkdown startingString
|> List.map (\{ text, marked } -> ( text, marked ))
|> Expect.equal expected
|> Expect.all
[ -- the right words are marked
List.map (\{ text, marked } -> ( text, marked ))
>> Expect.equal expected
, -- the indexing is correct
\highlightables ->
Expect.equal
(List.indexedMap (\index _ -> index) highlightables)
(List.map (\{ index } -> index) highlightables)
]
defaultMark =
Tool.buildMarker