question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature: remove single run/paragraph

See original GitHub issue

I make some pptx templates processing and this is really desired feature for me. API proposal:

paragraph.remove(run)

and

textframe.remove(paragraph)

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
scannycommented, Jan 22, 2015

Hi @theres, I think the API we’ll use is .delete() on each individual object for which it’s valid, so something like this:

paragraph.runs[0].delete()
run.delete()
paragraph.delete()
# etc. ...

In the meantime, this code should do the trick for plain content. The trickiness comes in when there are links to external content, like a picture or hyperlink:

def delete_paragraph(paragraph):
    p = paragraph._p
    parent_element = p.getparent()
    parent_element.remove(p)

# this second form is a little more direct, although perhaps not
# quite as clear on all the steps that are happening
def delete_run(run):
    r = run._r
    r.getparent().remove(r)

You’ll need to be careful about using any remaining reference to the paragraph after calling delete_paragraph(). It will seem to work but won’t affect the presentation content that gets saved. That’s one of the reasons using the form delete_paragraph(text_frame.paragraphs[idx]) would be preferred since it doesn’t leave a reference hanging around.

Dealing with these smaller details and edge cases will be some of the work that will go into the actual feature when we add it.

Let us know how you go if you decide to use the workaround function 😃

0reactions
zhouaide0924commented, Oct 23, 2019

Hi Scanny, Thanks for your response, it is work now. I find I used it in a wrong way. Sorry for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Quickly Remove Paragraph Marks or Hard Returns ...
You can remove a single hard return or paragraph mark by dragging over it and pressing Delete. Removing hard returns or paragraph marks...
Read more >
How to remove all empty paragraphs in Word?
Click Run Macro on the Run tab. arrow blue right bubble Remove all empty paragraphs with kutools for Word. To remove all empty...
Read more >
Javascript regex, make remove single paragraph line breaks
I'm trying to do this all client side, currently running it in Firefox. I'm not the best with regex, so this might be...
Read more >
How to Remove Paragraph Breaks & Keep Spaces ... - YouTube
Remove paragraph breaks and keep paragraphs together in Microsoft Word ... Word is one of the most widely used word processors in existence....
Read more >
Control pagination
On the Format menu, click Paragraph, and then click the Line and Page Breaks tab. Select the Keep lines together check box. Keep...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found