Camen Design Forum

What convetion should be used for code and quote bbcode?

append delete Kroc

The reason I haven't implemented pre / code and quote bbcode yet is that I’m undecided on what convention I should use. I would not like to use a convention that requires typing a symbol every line, as this goes wonky and becomes difficult to manage if you delete / add text before submitting. Therefore, some sort of enclosing wrapper would be best.

Quotes:

It is important to note that quotes will have to contain nested quotes, so the syntax has to be such that this can be safely detected and rendered.

The most common type of quote convention is "[q]…[/q]". These are okay, but nothing too special. In ReMarkable, block quotes use pipes and tabs—off the cards here—but inline quotes use « … » or << … >>. These look nicer but are less commonly known.

PRE / Code:

There is a need to quote source code and other monospace text. In bbcode this is usually [code]. In ReMarkable it is `…` (samp) or ``…`` (code), and the pre "fence" for large blocks.

~~~>
…
<~~~

Pre fences have the benefit of being nestable, however this is not common in bbcode; most bbcode does not allow you to write unescaped bbcode, other than turning the whole feature off.

I am interested mainly in elegance, simplicity to type (most bbcode is clumsy) and a natural flow in text.

What are your thoughts?

Reply RSS

Replies

append delete #51. Jonhoo

I like it - clean and simple
There are a few programming languages that use % as the comment character if I remember correctly, but those might be so obscure that it is irrelevant.
Also, when crafting your regex, make sure to consider the modulo operator. The % will have to be on a separate line (line-wrapping could cause a % to be the last character on a line without it ending the code block).

Are you considering adding syntax highlighting as well? Something like highlight.js (http://softwaremaniacs.org/soft/highlight/en/)?

Jonhoo added on

Seems to be another bug with the URL parsing?
In the link above, the )? was not meant to be a part of the URL...

append delete #52. Kroc

The URL regex can ignore brackets on the ends of URLs, but it can’t ignore more than one thing on the end. Remember that ) and ? are valid URL characters, how is it to know the URL is not supposed to be that way?

The regex for code block detection will require the % be on it’s own line, no other text. Code blocks won't be nestable, so even if a language uses % as delimiter, my regex will be able to skip over it.

e.g.

% PHP
...
...
% comment

%

will work, because the regex will only use the first opening, and ignore the second.

I won't add syntax highlighting (too much added complexity for little gain). I don’t expect people will be posting such huge swathes of code that it needs highlighting. Someone could always provide a patch to add this feature later on, I won’t aim to do it myself for now.

append delete #53. Kroc
% PHP
while (preg_match ('/^(?-s:\s*)%(.*?)?\n(.*?)\n(?-s:\s*)%(["”»]?)$/msu', $text, $m, PREG_OFFSET_CAPTURE)) {
	//format the code block
	$code[] = '<pre><span class="ct">%'.@$m[1][0]."</span>\n"
		//(if a language name is provided, include `<code>` in the HTML)
		.(@$m[1][0] ? '<code>' : '').$m[2][0].(@$m[1][0] ? '</code>' : '')
		."\n<span class=\"cb\">%</span></pre>"
	;
	//replace the code block with a placeholder
	$text = substr_replace ($text, "\n&__CODE__;".$m[3][0], $m[0][1], strlen ($m[0][0]));
}
%
append delete #54. theraje
% Pseudocode
if (code works) {
  rawkOn();
} else {
  bang("head", "wall");
}
% The "programmer function"
%

theraje added on

Nicely done, Kroc. :)

append delete #55. Kroc

You can write anything you want on the first line (like the language).

% CSS
pre				{overflow: auto; margin: 20px 0 0;}
pre, code			{font: 12.5px/20px Monaco, Consolas, monospace, monospace;}
%

And the code blocks copy and paste correctly.

append delete #56. Wannes

How are you handling the lines of code that are to long to fit in the width of the post? You can see it goes over the edge in your post Kroc.

Wannes added on

Nevermind, I had to refresh the page to see it dissapear :)

append delete #57. Jose Pedro Arvela

This is so sweet! And furthermore, it is quotable!

“#55. Kroc

You can write anything you want on the first line (like the language).

% CSS
pre				{overflow: auto; margin: 20px 0 0;}
pre, code			{font: 12.5px/20px Monaco, Consolas, monospace, monospace;}
%

And the code blocks copy and paste correctly. ”

phpBB nevermore! This shall be the forum system I shall use from now on (I always hated phpBB anyway... and all other forum systems...)!

append delete #58. thinsoldier

How do you insert images? Or do you only allow linking to the image by pasting its url?

append delete #59. Kroc

Yes. I won’t allow inserting of images due to the extra anonymity afforded on the forum, and that it doesn’t kill anybody to click link, and it’s good for those on low speed connections.

append delete #60. Wannes

And it also keeps you focused on the text. Most of the forums are more bloat than conversations. Also, when you quote a post with a image, that image gets copied to, and you quickly end up with a véry slow forum.

The only other place where I've seen a sensible layout, is the forum at http://www.teamliquid.net/forum/starcraft2 . They still have that nagging line under every post were people put there 'sigs' or whatever that's called. But still, quite minimal, unlike http://forums.xkcd.com/ . You actually need to search in a post before you find what they posted.

append delete #61. Jonhoo

One problem that might be a nuissance is that LaTeX uses % as the comment character..
How will the parser handle:

% LaTeX
\begin{document}
%
% Written by Jon Gjengset
%
\section{Hello}
World
\end{document}
%
append delete #62. Jonhoo

Yeah.. That's not entirely right...
Perhaps an escape character is in order?

append delete #63. Kroc

How was that supposed to play out? Does latex use % as a comment block delimiter (basically exactly the same as NNF)?

As soon as you have to explain text escaping to a normal user, you have lost. I specifically want to avoid that. We may be able to solve this by tightening up the regex (like % must be followed by a blank line and no other % signs), or by providing an alternate start and end delimiters when % needs to be used. (like $)

append delete #64. Wannes

I think that the second choice would be the best. If you use "$", there's an alternate character to use, and it would line up with the quotation system, where you also have a few alternatives.

append delete #65. Jonhoo

In LaTeX, each comment line is prefixed with % (just like # in PHP).
In the code above, I have used some empty comment lines (imagine a long comment with paragraphs and empty comment lines in between), but it still constitutes a problem..

Having $ and % would definitely help!

append delete #66. Kroc
$ LaTeX
\begin{document}

%
% Written by Kroc Camen
%

\section{Problem}
fixed.
\end{document}
$
append delete #67. Jonhoo

Beautiful!

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn