How to remove multiple lines with varying content?

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.

CM!

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.

  1. Can the text to keep be on multiple lines, or is it always just a single line as per your example?
  2. Can the quoted text contain quoted text?
  3. 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?
  4. Is it always an exactly four line copyright notice?
  5. Does ithe copyright notice always begin with “Auszug aus” (excerpt from), and could this technically occur in the excerpt too?
  6. 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?
1 Like

I think this should do what you want:

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

1 Like

Thanks for your response.

  1. I only copy short fragments for context, so is only one line
  2. Yes, but not at the beginning and end of the line.
  3. Yes.
  4. Yes
  5. Yes, unlikely
  6. Once it is in the draft

Thanks, this works great (and should do so for 99% of my drafts.). I tried to identify all the rest and remove it, while you filtered what I need.

No worries about my academic paperwork and proper citing, I just use copying from iBooks for lifelong learning with Anki :slight_smile:

1 Like

Since I red your response above - the Regen will not work when you have a quote inside of the quoted text :wink:

This is no problem, thanks. I will learn how to limit it to the beginning/end of a line, if necessary.

Here’s my take based on the answers you provided to my clarification questions.

It’s one script step of a couple of lines. One line to change the content and one line to explicitly update the draft.

draft.content = draft.lines.splice(0, draft.lines.length - 5).join("\n").substring(1).slice(0, -1);
draft.update();

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.

1 Like

Not an expert here, but check this action Anti-fy selection | Drafts Directory and then this forum post, see if it helps