JohannesNE / literature-clock

Clock using time quotes from the literature, based on the work of Jaap Meijers
http://literature-clock.jenevoldsen.com
Other
598 stars 105 forks source link

Double quoting is not intuitive #38

Closed JohannesNE closed 2 years ago

JohannesNE commented 2 years ago

If the .csv file has an entry that starts and ends with a quote, these need to be escaped by double quotes (""). I.e.

01:30|half-past one|"""Half-past one"", The street lamp sputtered, The street lamp muttered, The street lamp said, ""Regard that woman ..."""|Rhapsody on a Windy Night|TS Eliot|unknown

This is quite difficult to both read and write, and should not be necessary since all entries in the .csv should simply be interpreted as strings.

I'm just not yet sure how to do this in R.

fbtot commented 2 years ago

Maybe it’s easier to do it in VSCode with search and replace and a regex. If you search "{1,3}(.*?)"{1,3} and replace it with “$1”, VSCode will change the "" (between one and three) into “”, keeping what is between them the same. This way we can replace all the "" with “”. It still needs a manual check, of course, but it’s not a gargantuan job.

I can do this if you want. I was also thinking about writing a CONTRIBUTING.md, so that newcomers know how to add new quotes correctly.

Regarding the R script, I skimmed through the documentation and I found this. I tried to implement it and I came up with this:

litclock <- mutate(litclock,
    quote = str_replace_all(quote, '"{1,3}(.*?)"{1,3}', "“\\1”"),
    quote_time = str_replace_all(quote_time, '"{1,3}(.*?)"{1,3}', "“\\1”")
)

This way, if there are "" (between one and three) in the CSV they become “” in JSON. It seems to work, but i’m not 100% sure since I never used R.

JohannesNE commented 2 years ago

Thanks, that could definitely work, and it may be the safest solution. to simply not use ", since they mess up the parsing if they are not correctly matched.

I would, however, prefer that the quotes are parsed as markdown text (as it is now) to automatically use “ and ” appropriately.

JohannesNE commented 2 years ago

I think I found a solution here https://github.com/JohannesNE/literature-clock/pull/40

fbtot commented 2 years ago

I think I found a solution here #40

Yeah this is great! Much simpler than what I thought. It also solved a problem with double quotes not appearing in dialogues sometimes. Kudos!