Line breaks in quotations

Asked by Jim Kerwin on 2018-08-09

I've just discovered Variety. Thank you so much for your work on this!

I'm also experimenting with "Random Quotes." Except, in my case, I'm using my own quotes.txt file. I'm trying to introduce some verses of poetry and haiku into the quotes. But they don't look right with the lines run together, as in a prose paragraph.

Is there a way to insert a line break (a "soft carriage return," as it were) to get Variety to show the result as one multi-line paragraph? Even fiddling with various U+xxxx codes and characters, I can't figure out a way to to this.

Once again, many thanks for this helpful addition to my Ubuntu Mate desktop.

Question information

Language:
English Edit question
Status:
Answered
For:
Variety Edit question
Assignee:
No assignee Edit question
Last query:
2018-08-09
Last reply:
2018-08-09
Peter Levi (peterlevi) said : #1

No way right now, it's a bug actually. Please report it here: https://github.com/varietywalls/variety/issues

Here is the relevant code in the LocalFilesSource plugin, the multiline regex clears the newlines:

    def load(self, path):
        try:
            logger.info(lambda: "Loading quotes file %s" % path)
            with open(path, 'rU') as f:
                s = f.read().decode('utf-8', errors='ignore')
                for q in re.split(r'(^\.$|^%$)', s, flags=re.MULTILINE):
                    try:
                        if q.strip() and len(q.strip()) > 5:
                            parts = q.split('-- ')
                            quote = ' '.join(parts[0].split())
                            if quote[0] == quote[-1] == '"':
                                quote = u"\u201C%s\u201D" % quote[1:-1]
                            author = parts[1].strip() if len(parts) > 1 else None
                            self.quotes.append({"quote": quote, "author": author, "sourceName": os.path.basename(path)})
                    except Exception:
                        logger.debug(lambda: 'Could not process local quote %s' % q)
        except Exception:
            logger.exception(lambda: "Could not load quotes file %s" % path)

Jim Kerwin (jim-kerwin) said : #2

I'd be happy to report the bug. But never having done so, shouldn't I
credit you as supplying the relevant code? To pretend I know what any of
that means would make me several orders of magnitude less honest than a
politician! ;-)

On Thu, Aug 9, 2018 at 3:52 PM Peter Levi <
<email address hidden>> wrote:

> Your question #671469 on Variety changed:
> https://answers.launchpad.net/variety/+question/671469
>
> Status: Open => Answered
>
> Peter Levi proposed the following answer:
> No way right now, it's a bug actually. Please report it here:
> https://github.com/varietywalls/variety/issues
>
> Here is the relevant code in the LocalFilesSource plugin, the multiline
> regex clears the newlines:
>
> def load(self, path):
> try:
> logger.info(lambda: "Loading quotes file %s" % path)
> with open(path, 'rU') as f:
> s = f.read().decode('utf-8', errors='ignore')
> for q in re.split(r'(^\.$|^%$)', s, flags=re.MULTILINE):
> try:
> if q.strip() and len(q.strip()) > 5:
> parts = q.split('-- ')
> quote = ' '.join(parts[0].split())
> if quote[0] == quote[-1] == '"':
> quote = u"\u201C%s\u201D" % quote[1:-1]
> author = parts[1].strip() if len(parts) > 1
> else None
> self.quotes.append({"quote": quote, "author":
> author, "sourceName": os.path.basename(path)})
> except Exception:
> logger.debug(lambda: 'Could not process local
> quote %s' % q)
> except Exception:
> logger.exception(lambda: "Could not load quotes file %s" %
> path)
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/variety/+question/671469/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/variety/+question/671469
>
> You received this question notification because you asked the question.
>

Can you help with this problem?

Provide an answer of your own, or ask Jim Kerwin for more information if necessary.

To post a message you must log in.