news-catalyst / google-app-scripts

a collection of scripts for tinynews google docs add-ons
https://script.google.com/a/newscatalyst.org/d/1ILURq69o3cYUy6k1n1X6HwxdMfl9xWNhILYuZxgLfeblb3IR15WCMZSj/edit
1 stars 1 forks source link

How should we handle poetry/strangely formatted text? #331

Closed TylerFisher closed 2 years ago

TylerFisher commented 2 years ago

Crystal publishes poetry from her community, which obviously has unique spacing and line break needs. Is there some way we can mark a section of content as-is kind of like backticks on a coding-forward platform?

I see you.
Doing the best you can.
You didn’t ask for this and yet, it is yours to carry.
So how will you carry it?
Slung over your shoulder?
jacqui commented 2 years ago

I've spent some time with the various options google docs offers for formatting text, and then how that formatting carries through to the data from the docs api.

From what I can tell, there are two options to note lines of poetry: format the lines differently from all the other text, or use a start & end marker.

I wish we could make our own custom text style and call it "POEM" but I don't see how to do that in Google Docs. Using an existing format (ex: highlight; superscript; strikethrough; red text color) seems either like a hack or prone to confusion (what if the text should just be red and is not poetry?). To be fair... this is a hack, but I don't want to make things confusing.

Using a start and end marker might be better, then, as it's clear and doesn't co-opt another format's meaning. The data that comes through treats each line as a separate element:

{"paragraph":{"elements":[{"textRun":{"content":"POEM START\n","textStyle":{}},"startIndex":1,"endIndex":12}],"paragraphStyle":{"namedStyleType":"NORMAL_TEXT","direction":"LEFT_TO_RIGHT"}},"startIndex":1,"endIndex":12}
// I've omitted most of the lines here for brevity
{"startIndex":12,"endIndex":26,"paragraph":{"elements":[{"startIndex":12,"textRun":{"textStyle":{},"content":" in the rain-\n"},"endIndex":26}],"paragraphStyle":{"namedStyleType":"NORMAL_TEXT","direction":"LEFT_TO_RIGHT"}}}
{"endIndex":402,"startIndex":391,"paragraph":{"paragraphStyle":{"direction":"LEFT_TO_RIGHT","namedStyleType":"NORMAL_TEXT"},"elements":[{"endIndex":402,"startIndex":391,"textRun":{"textStyle":{},"content":"   \tof you\n"}}]}}
{"paragraph":{"paragraphStyle":{"direction":"LEFT_TO_RIGHT","namedStyleType":"NORMAL_TEXT"},"elements":[{"endIndex":410,"textRun":{"content":"POEM END","textStyle":{}},"startIndex":402},{"textRun":{"textStyle":{},"content":"\n"},"endIndex":411,"startIndex":410}]},"startIndex":402,"endIndex":411}

This is using a poem by e.e. cummings as an example - here's the google doc.

A few things would need to change in the processDocumentContents function:

  1. the section iterating over each paragraph element needs to look for POEM START in the content of the line of text
  2. and then... note the index of this element
  3. and for all subsequent elements, which should arrive in order, but just in case, have an index greater than POEM START, give them a custom namedStyleType of our own, like poem instead of copying the default paragraph type of NORMAL_TEXT from the data
  4. this paragraph element iterator also needs to look for POEM END and note the index
  5. the result I'm going for here is all lines between the indexes for poem start & poem end will be marked as poem
  6. a line that's marked as poem should also not get the text cleanup applied to it, so extra spaces and so on are preserved
  7. the two start & end elements should be discarded and not added to the contents in Hasura

I feel like this could work. Then the front-end could use a special node to format poems differently than other text.

What do you think?