I use Drafts to create Anki cards for vocabulary learning using x-url-callback. When I read books in iBooks, I copy phrases into Drafts, later add the translation for the desired word and send it to Anki. Unfortunately, when I copy from iBooks, quotation marks are automatically put around the phrase and a copyright notice is added:
„asked me a seemingly innocuous question“
Auszug aus How to Change Katy Milkman Dieses Material ist möglicherweise urheberrechtlich geschützt.
I just want to have
asked me a seemingly innocuous question
I guess the unwanted content could be replaced with a Drafts action. I can do a simple search and replace using draft.content.replace. But how can I replace the variable part between Auszug aus and Dieses Material ist möglicherweise urheberrechtlich geschützt.? (the content in bold is static, the content in italic varies). Thanks for guidance.
One example leaves quite a few questions about the structure and how to determine what the copyright consists of, so here’s a few questions to help narrow that down and to determine when is best for you to remove the copyright notice.
Can the text to keep be on multiple lines, or is it always just a single line as per your example?
Can the quoted text contain quoted text?
In your example, there is a blank line between the quoted text and the additional copyright notice. Is that the only place a blank line can occur?
Is it always an exactly four line copyright notice?
Does ithe copyright notice always begin with “Auszug aus” (excerpt from), and could this technically occur in the excerpt too?
Do you want to remove the copyright notice from the draft once the text is in the draft, or when pasted from the clipboard into the draft?
It replaces the content of the current draft if a string between two quotation marks like in your example was found with just the text between the two quotation marks.
If you have further use cases with text replacement / matching I recommend to checkout regex101.com to test regex matching for string.
If you’re not familiar with regex its worth checking it out. There was a podcast episode of “The Automators” a while ago explaining the basics
The action is position-based and work by removing the last five lines and the first and last characters of what remains after that.
This aproach should then deal with the quotes within quotes, as well as being agnostic of the content containing any of the content in the final lines. Should you ever wish to quote multi-line entries, this approach it would also accommodate that. The only time there could be issues is if the copyright somehow varied from the standard number of lines.