Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we add a new line break between a paragraph #150

Open
suleman-jalil-devboxtech opened this issue Mar 20, 2024 · 6 comments
Open

Comments

@suleman-jalil-devboxtech
Copy link

suleman-jalil-devboxtech commented Mar 20, 2024

Problem

  1. How can we add a paragraph.

Please share a clear and concise description of what the problem is.
The issue i have a text like below
We want to end the paragraph by line break before <>. And Next sentence should start from the new line.or
new paragraph.

"The weather forecast located in ________ to the Person's ________, of trust. In the event ________ shall not survive due to harsh weather conditions lapse.\n<<ENTER>>\nThe weather forecast located in ________ to the Person's ________, of trust. In the event ________ shall not survive due to harsh weather conditions lapse."

"<p style=\"font-size:13pt;text-align:both;\"><span style=\"font-size:13pt;\"></span> <span style=\"font-size:13pt;\"></span><span style=\"font-size:13pt;\"></span> <span style=\"font-size:13pt;\">The weather forecast located in ________ to the Person's ________, of trust. In the event ________ shall not survive due to harsh weather conditions lapse.\n<<ENTER>>\nThe weather forecast located in ________ to the Person's ________, of trust. In the event ________ shall not survive due to harsh weather conditions lapse.</span></p>"

I tried "/n, br, /t and many other option. But the line does not break. It continues.
Can someone help on it.

@suleman-jalil-devboxtech suleman-jalil-devboxtech changed the title How can we add a new paragraph How can we add a new line break between a paragraph Mar 20, 2024
@suhasg
Copy link

suhasg commented Apr 8, 2024

@satoryu I'm also struggling with adding new lines or breaking paragraphs during text substitution. Please help
@suleman-jalil-devboxtech Thanks for bringing this up.
Any workarounds or fixes, please post them here.

@lukew244
Copy link

The way I'm inserting newlines between paragraphs is like this:

def insert_blank_line(previous_paragraph = document.paragraphs.last)
  line = previous_paragraph.copy
  line.blank!
  line.insert_after(previous_paragraph)
end

If the paragraph you want is already in the document, try something like:

original_paragraph = document.paragraphs.first
text = original_paragraph.text
split_paragraphs = text.split("\n") # or whatever your delimiter is, you may need to escape the "\"
split_paragraphs.each do |p|
  new_paragraph = original_paragraph.copy
  new_paragraph.text = p
  new_paragraph.insert_after document.paragraphs.last
end
original_paragraph.remove!

This example assumes the document only has one paragraph, but you get the idea.

@suhasg
Copy link

suhasg commented May 14, 2024

@lukew244 Got it. Thank you for the quick help 👍🏻

@suleman-jalil-devboxtech
Copy link
Author

@lukew244 thank you for the help.

@Jawad79Ahmad
Copy link

@lukew244 Thanks for the quick help, its working as expected.

@Jawad79Ahmad
Copy link

Jawad79Ahmad commented May 24, 2024

I'm encountering an issue with adding tabs (4 spaces) at the beginning of a new paragraph using an escape sequence. Here are the details:

Current Approach: I am using the escape sequence \t to insert tabs in the text.
Problem: While \t works when used in the middle of a paragraph, it does not seem to affect the text when placed at the beginning of a new paragraph.

  • Working

text = "This is a new\tparagraph"

  • Not Working

text = "\tThis is a new paragraph"

In the above example, the second paragraph does not get the intended indentation when using \t at the beginning.

Desired Outcome
I want to achieve the following:

This is new paragraph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants