Another life-changing fantastic idea for quotes! (Bit silly, too.)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #15, on March 9th, 2011, 11:48 PM »
Hmm. OK, well, we already know what is newline delineated because we're given newlines by the editor and they're still present in the message body. So it's not like we're totally devoid of that meaning.

We can easily use that to define blocks of text that should be indicated with >>... but without using JS there's no way to display it. Part of me things we should just treat it as a single block of text, stick it in a paragraph tag and attach a coloured left border to it the way some email clients do. That way you essentially leave layout to the client to deal with ;)

But yeah, it's not pretty or clever to have to deal with this.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #16, on March 10th, 2011, 11:03 AM »
Quote from Arantor on March 9th, 2011, 11:48 PM
Hmm. OK, well, we already know what is newline delineated because we're given newlines by the editor and they're still present in the message body. So it's not like we're totally devoid of that meaning.
That's the basics... Obviously it gets more complicated because of 5 things:
- Cutting lines that are longer than an arbitrarily decided length. I think around 80 chars would be logical, but smaller screens will show them in two lines... Whatever. Can live with that uh. Most likely these screens are on mobile -- and you know how dealing with quotes is horrible on mobile screens. The > solution is actually a great step in usability for these. (Select a line, press Return, type answer...)
- wordwrap() doesn't work on UTF, ah ah. So I have to do it differently, getting all lines that are longer than 80 chars and splitting them manually.
- words that are too long: it's relatively easy to split them to the next line... But how do we put them back together at posting time?
- tags: same here...
- how do we differentiate between line breaks that are due to long lines, and line breaks that were in the original? I thought that it could be solved by telling the editor that a 50-char line (or smaller) means a real line-break while more is a normal line. But of course, it would be too easy -- because of the aforementioned tag & long word problems, it's never easy to determine that kind of thing...
Quote
We can easily use that to define blocks of text that should be indicated with >>... but without using JS there's no way to display it.
I haven't been using JS because it can be done with PHP and JS would only complicate things. (I'm thinking this feature will only be on non-Wysiwyg anyway. I don't care -much- about Wysiwyg and Wysiwyg users probably don't even know what a non-HTML e-mail is...)
Quote
Part of me things we should just treat it as a single block of text, stick it in a paragraph tag and attach a coloured left border to it the way some email clients do. That way you essentially leave layout to the client to deal with ;)
That would mean using a contentEditable frame instead of a textarea, if you want to add coloring inside the area...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #17, on March 10th, 2011, 11:14 AM »
It sort of depends how you approach it; from a display perspective, the issue of using paragraph tags with a left border solves all the display issues, but none of the editing issues.

It's not like it would be a problem to use a contentEditable frame; we're already doing that anyway in the WYSIWYG editor, but yeah I see where you're going.

Thing is, Thunderbird uses the left border gig in HTML emails which is where I got it from, as does other stuff, and everyone else uses >> for non HTML emails, so it's not like it is anything special. FWIW, they also do it as >> to indicate the start of a line and not bother to worry about how long the line is.

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #18, on March 12th, 2011, 01:45 AM »
Finished doing my first 'working' version of the parser... It only parses TO mail format, not FROM it for now.

Stats: 45 lines of code, 1 preg_match_all, 2*words preg_match, 4*words westr::strlen, 2 explode (1 per line), 1 str_replace per line. Heavy, eh....? Couldn't do any better... But it's still pretty fast and it's nestable.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Adonis

  • Skyrim Arch-mage and errand runner
  • Posts: 80
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #20, on March 12th, 2011, 06:47 AM »
Just skimming the topic as it's something I'm fond of.

I usually end up C/P the [BB] tags after I add some hard returns between the individual bits I'd like to quote.  Opening and closing tags seems easier than a mysterious and arbitrary > length.

It'd like a system that automated the above a little more.

So if the original quote is [startquote]"There is no one who loves pain itself, who seeks after it and wants to have it,"[endquote]

Putting the cursor after "itself," and pressing 'SplitQuote' automagically get you


 [startquote]"There is no one who loves pain itself,[endquote]

 [startquote]who seeks after it and wants to have it,"[endquote]

 


Nao

  • Dadman with a boy
  • Posts: 16,079

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #24, on March 12th, 2011, 01:14 PM »
I have no idea.... Google says there's a "Split quote" bookmarklet for vB, but it simply splits every paragraph into its own quote, at the beginning. That's an interesting approach but to me it sounds like a wrong one, if only because of the potential waste of space if the user doesn't modify anything at all and just answers at the beginning of their post.

Anyway... Currently working on implementing that 'splitQuote' function. And of course, my implementation is ugly... What matters is to make it work, for now. I think I can be done before tonight but I have to go right now. A Jane Austen movie to watch...
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #25, on March 12th, 2011, 06:09 PM »
My, my... It's working pretty well. And with a relatively short function. And without a single regex involved, ahah. (I originally had one.)

Added this in editor.js (the splitQuote registration):

Code: [Select]
$(this.oTextHandle).keydown(this.aEventWrappers.shortcutCheck).keydown(splitQuote);

And then this in post.js:

Code: [Select]
// Split a quote if we press Enter inside it.
function splitQuote(oEvent)
{
// Did we just press Enter?
if (oEvent.which != 13)
return true;

// Where are we, already?
if ('selectionStart' in this)
var selectionStart = this.selectionStart;
else
{
var range = document.selection.createRange(), stored_range = range.duplicate();
dul.moveToElementText(this);
dul.setEndPoint('EndToEnd', range);
var selectionStart = dul.text.length - range.text.length;
}

// Is there an opened quote tag here?
var selection = this.value.substring(0, selectionStart), lcs = selection.toLowerCase(), lioQuote = lcs.lastIndexOf('[quote');
if (lioQuote <= lcs.lastIndexOf('[/quote'))
return true;
var quote = '\n\n' + selection.substring(lioQuote);

surroundText('[/quote]\n', quote.substring(0, quote.indexOf(']') + 1), this);

return true;
};

Can you give it a try, Pete? I tested in many possible ways but I'm sure you'll be interested in seeing it for yourself.
Also, I'm readding the original quote with author and time, but I think it'd be smarter to add something like[quote continued], where we would make it clear that this quote is a continuation of the previous one.

NB: it doesn't work on nested quotes, I fear... Maybe you can find a workaround, like counting the number of quotes and the number of /quotes and generating the splitter quotes based on the difference between them... That might work.

Adonis

  • Skyrim Arch-mage and errand runner
  • Posts: 80

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #27, on March 13th, 2011, 12:19 AM »
Added support for multiple levels of tags...

Code: [Select]
// Is there an opened quote tag here?
var selection = this.value.substring(0, selectionStart), lcs = selection.toLowerCase();
var quotes = lcs.match(/\[quote.*?\]/g), unquotes = lcs.match(/\[\/quote\]/g);
if (quotes === null || (unquotes !== null && quotes.length <= unquotes.length))
return true;
var num = quotes.length - (unquotes === null ? 0 : unquotes.length) + 1;

surroundText(new Array(num).join('[/quote]') + '\n', '\n\n' + new Array(num).join('[quote]'), this);

The 'join' thing is the equivalent of str_repeat. Pretty neat... (Took the idea from php.js)
It still won't deal with things that are cut in the middle, like code tags or even anchors or whatever. Dunno if it's that important... Is it? Also, it no longer reproduces the earlier quote variables (author, date). Adding them back would probably be a bit complicated... (I can't just use a list of the last quotes in the array... If I have a self-closed quote right before my post, it will get crazy and reproduce that quote's data instead of the correct one.)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #28, on March 13th, 2011, 12:21 AM »
Quote
It still won't deal with things that are cut in the middle, like code tags or even anchors or whatever. Dunno if it's that important... Is it?
It probably should, to be honest.
Quote
Adding them back would probably be a bit complicated...
Yup. Not sure it's hugely critical personally.

* Arantor will go test shortly.

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #29, on March 13th, 2011, 12:24 AM »
Or maybe just that...

Code: [Select]
surroundText(new Array(num).join('[/quote]') + '\n', '\n\n[quote continued]' + new Array(num - 1).join('[quote]'), this);
Quote from Arantor on March 13th, 2011, 12:21 AM
Quote
It still won't deal with things that are cut in the middle, like code tags or even anchors or whatever. Dunno if it's that important... Is it?
It probably should, to be honest.
What about... If I cut a code tag that's located in a nested quote? (i.e. not directly inside the main quote.)