0

I'm using Migrate, Migrate Tools, Migrate CSV to import data from a csv file into my website.

One field I have is Text (Formatted, Long), and this is where I import a bunch of information about my specific item.

If in my csv file I write out something like this in a cell (Using Alt+Enter to create a line break in the cell):

This is paragraph 1 of a block of text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut optime, secundum naturam affectum esse possit. Tu autem, si tibi illa probabantur, cur non propriis verbis ea tenebas? Sine ea igitur iucunde negat posse se vivere? Quod autem satis est, eo quicquid accessit, nimium est;

This is paragraph 2 of a block of text. Duo Reges: constructio interrete. Non enim quaero quid verum, sed quid cuique dicendum sit. Quod quidem iam fit etiam in Academia. Cum ageremus, inquit, vitae beatum et eundem supremum diem, scribebamus haec.

It ends up importing like this into Drupal:

This is paragraph 1 of a block of text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut optime, secundum naturam affectum esse possit. Tu autem, si tibi illa probabantur, cur non propriis verbis ea tenebas? Sine ea igitur iucunde negat posse se vivere? Quod autem satis est, eo quicquid accessit, nimium est; This is paragraph 2 of a block of text. Duo Reges: constructio interrete. Non enim quaero quid verum, sed quid cuique dicendum sit. Quod quidem iam fit etiam in Academia. Cum ageremus, inquit, vitae beatum et eundem supremum diem, scribebamus haec.

Just one big block of text.

Does anyone know of anything special that I need to put into my Excel cell after each paragraph so that Drupal knows to break up each paragraph into its own <p> paragraph tag once imported from the saved .csv file?

I've gone through numerous sites/threads trying to find an answer but I can't quite seem to find anything explaining what I need to do in Excel prior to exporting as CSV to maintain the paragraph breaks.

Note, after I export from excel to csv, i open the file in Notepad and resave as UTF-8 in order to import the content properly in Drupal.

Is this something that is even possible at all?

1

If your CSV file is saved with new line characters then I expect it is also saved that way into the database. You can check this if you have access to the database. But you can also check this more or less on the Edit page of some of the content that has been imported.

Drupal uses Text formats to display the text. This means it can change what is being served from the database.

Check which Text format is being used on that field and then check the configuration for that format. You can check which Text format is being used on the Edit page, right below the text area element.

"Losing" new line characters can happen if you don't have a Convert line breaks into HTML (i.e. <br> and <p>) option turned on on the format that you apply to your field.

Try using that option on the Text format of the content you've imported, or maybe you have the "Plain text" format, since you're importing content, but make sure that this format has the option Convert line breaks into HTML (i.e. <br> and <p>) enabled.

You can find Text formats under Configuration > Content authoring > Text formats and editors.

Just make sure you don't save the node with a Text format chosen that doesn't have that option enabled (you will see all the paragraphs lumped together), because saving the node will override what is written in the database. Don't save if it doesn't look good, and try to find which Text format makes it look good, it will probably be the one that has the mentioned option enabled ;)

3
  • Thank you! Turning on the line-break option seemed to work for the most part. Now is there a way of separating the line breaks into their own <p> tags or probably not? Also, I'm assuming not, but, saving say unordered lists or anchor links in the csv file won't be able to transfer over will it? Aug 18 '20 at 19:08
  • Actually, what seems to be happening is it adds a line break <br> between the first and second paragraph in the cell, then puts all the following ones into their own <p> paragraph tags. Aug 18 '20 at 19:18
  • I guess the most reliable way is to keep your data as HTML because then there is no doubt about how content should be displayed. HTML doesn't recognize new lines, and collapses white space (unless in some very special cases). The Text formats were introduced to make editors jobs easier so you don't have to know code to create content. But technically speaking empty lines aren't supposed to be used to denote separate paragraphs, you usually use Formatting for that. Are you asking about editing in Drupal or CSV? You can edit the CSV to add the <p> and other tags, and import into a Full HTML.
    – prkos
    Aug 18 '20 at 19:44

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .