Just for people's reference, attached is the updated notebook.
And here is the associated function:
ClearAll[PsychoSentenceSVG, modifyWords];
modifyWords[{word1_String, word2_String}, {style1_, style2_}] :=
Switch[{style1, style2},
{None, None},
{word1, word2},
{None, _},
{word1, Style[word2, style2]},
{_, None},
{Style[word1, style1], word2},
{_, _},
{Style[word1, style1], Style[word2, style2]}
];
Options[PsychoSentenceSVG] = {ReplacementCharacter -> "-",
FontFamily -> "Courier", FontSize -> 12};
PsychoSentenceSVG[sentence_String, path_String,
fileName_String, {style1_, style2_}, OptionsPattern[]] :=
Module[{splitSentence, dashedTemplate, stringTable,
processedSentences, replacementCharacter, fontFamily, fontSize},
replacementCharacter = OptionValue[ReplacementCharacter];
fontFamily = OptionValue[FontFamily];
fontSize = OptionValue[FontSize];
splitSentence = Partition[StringSplit[sentence], 2, 2, 1, ""];
dashedTemplate =
Map[StringReplace[#, _ -> replacementCharacter] &,
splitSentence, {2}];
splitSentence = modifyWords[#, {style1, style2}] & /@ splitSentence;
stringTable = Table[
Riffle[Flatten[
ReplacePart[dashedTemplate, i -> splitSentence[[i]]]],
" "], {i, Length[splitSentence]}];
processedSentences = Row /@ stringTable;
processedSentences =
TextCell[#, "Text", FontFamily -> fontFamily,
FontSize -> fontSize, ShowStringCharacters -> False] & /@
processedSentences;
MapIndexed[
Export[FileNameJoin[{path,
"s" <> fileName <> "w" <> ToString[#2[[1]]] <> ".svg"}], #1,
"SVG"] &, processedSentences]
];
Attachments: