Skip to content
Advertisement

Editing/styling text from file/array and putting it back in order, styled?

tl;dr
I’m trying to style specific lines from a textfile, and in the end being able to show it on the page in the original order.

info: My page is running Joomla with the sourcerer extension.
Sample content of the wishlist:

JavaScript

Full story
I’m trying to set up a simple site for my family that can display our wishlists. We’re currently keeping the files on dropbox and so far I’ve figured out how to make the site read the file.

I would like for the script to make every line that starts with a special character, bold, and all other lines to be put in a bullet-list, but not the bolded ones.

bonus round: If there’s any links in the text it would be insane if they could be clickable.

The Problem
Right now I do a preg_match to check if any lines contains a specific Character, and if it does it’s put in an array, if not, it’ll be put in another. I don’t know how to run the check on the lines, apply the styling only to some of them and then return them in the correct order so I can display them correctly on the page.

My code

JavaScript

Advertisement

Answer

I’m not sure why you are moving the lines into separate arrays! Just iterate through line by line and work out what should be where!

Using preg_match

JavaScript

Alternative

We don’t have to use the ul | ol HTML lists we can add list properties in css to other elements:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement