Browser word-wrap

Hii all, :wave:

Lately I was asking myself: Is there a way of activating word-wrap in falkon browser?

The background of my question is:

On occasions there are sites where some code is published. Sometimes this code is very long but “printed” in just one line.
So I have to scroll horizontally for quite a while to see it all. It´s quite confusing that way. :neutral_face:

In (some) text editors there´s a way of tweaking the settings in a way that word-wrap is activated. Is something like that possible in the falkon browser too?

I had a lengthy discussion with ChatGPT about it and we went through different scenarios.
It turned out doing this for falkon poses some difficulties but it could be done more easily with google-chrome.

I know there´s discussion here for firefox using the
about.config settings.

But I needed a solution which helped me to do it more “programmatically”. :blush:

After putting quite some time and effort into the discussion we finally succeeded.

Just another note about the background of my query:

Every now and then I order I download link from ChatGPT, which provides a summary of all the conversations I´ve ever had with the chatbot.
A zip-file is then provided and the file chat.html is the crucial part. So all conversations are neatly displayed in an html file.

Recently I entered a code to be reviewed by ChatGPT and this code contained a very long line:

pattern_encoded_strings='0400100803000000030000000300000004007806030000000300000030000c00030000000400d800030000000300000003000000030000000300000043000000320000000300000003000000130100009200000012000000420000009300000062000000b3000000b200000003000000030000009300000042000000c3000000b20000000300000012000000040008070400080112000000630000000300000013000000f200000003000000a30000009200000033010000f200000043010000220000002201000004007008220000002300000072010000b30100009200000083000000230000008201000063010000130000000400a001220000002300000072010000b3010000b20100000300000003000000030000002301000043000000c20000009001300072000000210104000301000092000000220100003200000033010000d200000012000000'

In fact it was much longer; I abbreviated it here. But you get the point.

The html file would print it in one line and I had to scroll “endlessly” to view it all (see above).

Now to the solution:

Here´s a script we wrote (mainly ChatGPT), which automates the process of adding the
overflow-wrap: break-word;
style rule to the HTML file:

#!/bin/bash

# Define the CSS style to be added
CSS_STYLE="overflow-wrap: break-word;"

# Path to the HTML file (assuming it's always named "chat.html" and located in the same directory as the script)
HTML_FILE="chat.html"

# Check if the HTML file exists
if [ -f "$HTML_FILE" ]; then
    # Add the CSS style to the HTML file
    sed -i "s#<style>#&\n    body {\n        $CSS_STYLE\n    }#" "$HTML_FILE"
    echo "CSS style added to $HTML_FILE"
else
    echo "Error: HTML file not found"
fi

Here’s how the script works:

  1. It defines the CSS style rule (overflow-wrap: break-word;) to be added to the HTML file.
  2. It specifies the path to the HTML file (chat.html).
  3. It checks if the HTML file exists.
  4. If the HTML file exists, it uses sed (a stream editor) to insert the CSS style rule into the existing <style> section of the HTML file.
  5. If the HTML file doesn’t exist, it displays an error message.

To use the script:

  1. Open a text editor and paste the script into a new file.
  2. Save the file with a .sh extension (e.g., add_word_wrap.sh).
  3. Open a terminal and navigate to the directory where the script is saved.
  4. Run the script using the command bash add_word_wrap.sh.

This script will automatically add the overflow-wrap: break-word; style rule to the <style> section of the chat.html file whenever you run it.
You can run the script each time you update the HTML file to ensure that the word-wrap style is always applied.

And it works splendidly. :smiley:
I tried in with google-chrome and with falkon as well.

Here´s how the relevant part looks in falkon:

I don´t know whether all of this is of any interest to anyone.
For me, however, it solved a “problem”.:blush:
Therefore I wanted to publish the solution here.

Many greetings from Rosika :slightly_smiling_face:

5 Likes

It is to me, but then again, I’m always interested in new ideas that can add functionality to anything I use. The concept of adding word-wrap functionality to any textual-based display/app can be very useful. As I see it, the next step would be to improve this script to be able to word-wrap the content of an open display window rather than an existing file. Another possibility would be to add the functionality of a command-line argument, so the script could be executed for any file (e.g.: add_word_wrap.sh <path-to-file>).

What do you think?

Ernie

2 Likes

Hi Ernie, :wave:

thanks for your comments and your interest in the topic.

Hmm, I´m not quite sure I understand.
Do you think of a browser window which displays a certain webpage and while it is open the contents should adapt to word-wrap by issuing a certain command in the terminal :question:

Sorry if I´m a bit slow in understanding…

I see. So the script should take care not only of a certain html-file but of any html-files, text-files etc, right?

Thanks for the suggestion.

Cheers from Rosika :slightly_smiling_face:

2 Likes

No, The way a web browser handles long lines is probably something browser devs would have to undertake.

I think so. With that modification, the script would become more useful, and easier to use, don’t you agree?

Ernie

2 Likes

Hi Ernie, :wave:

thanks for the clarification.

Yes, you´re quite right.

I don´t know whether taking care of html-files and text-files alike by the implementation of the same “code” in the script would work… :thinking: .
I certainly lack the knowledge for evaluating it.

Would the line
sed -i "s#<style>#&\n body {\n $CSS_STYLE\n }#" "$HTML_FILE"
work for text-files, too?
We´d have to check first.

For (some) text editors there´s a setting regarding word-wrap.
Wouldn´t a script dealing with this subject interfere with the settings in the text-editor?

Questions upon questions.

Cheers from Rosika :slightly_smiling_face:

1 Like

Probably not, so perhaps you should first check that the input is an HTML or HTM file, exiting with an error message if it isn’t. Whether you need that check or not probably depends on if you’re going to share the script with others.

Ernie

2 Likes

Thanks, Ernie.

I´d like to look into it but it may take a while.

In the meantime: have a nice day and all the best
from Rosika :slightly_smiling_face:

That project sounds like fun. If you don’t mind, I may try to work on it a bit. If I get it to work properly, I’ll come back to this thread and show you what I’ve come up with. Will that be O.K. with you? It may take me a few days because I’m working on another project right now.

Ernie

2 Likes

Hi Ernie, :wave:

I´m glad you like it. :heart:

Yes, of course. By all means.
That´s really very nice of you. Take your time.
I´m pretty busy at the moment, too.

Have a nice day.

Many greetings from Rosika :slightly_smiling_face:

1 Like