Block quotes with a blank line between them get merged

Michel Fortin michel.fortin at michelf.com
Thu Oct 19 08:43:20 EDT 2006


Le 19 oct. 2006 à 0:30, John Gruber a écrit :


>> ~~~

>> function db_like($first, $pattern) {

>> $pattern = preg_quote($pattern);

>> $pattern = preg_replace('/(?<!\\)_/', '.', $pattern);

>> $pattern = preg_replace('/(?<!\\)%/', '.*?', $pattern);

>> return preg_match('{^'.$pattern.'$}', $first);

>> }

>> ~~~

>> The code block begins with three or more consecutive tildes `~`

>> alone on a line, and ends with the same number of tildes `~`

>> alone on a line.

>

> I don't hate it, but it's not doing it for me. If you're going to

> have stuff on separate lines like that, why not just use

> `<pre><code>` and `</code></pre>`?


Using `<pre><code>` for the example above means you have to manually
escape two '<' with `&lt;`. Luckily, there is no '&' in that code.
And you'd have to put the first line of the content on the same line
as `<pre><code>`.



> And don't forget that we'd need some sort of escape so that you

> could put a literal `~~~` line in a code block.


You don't need that for code spans do you? You don't need that
because the final marker must be the same as the one at the beginning
-- the same applies here. If you choose the number of tilde
carefully, there is no problem.

If you have many tilde-only lines of all lengths in the code block,
it'd probably be wiser to choose an intended code block instead, if
only for clarity, but I can't see that happen very often.



> I'd rather have line prefixes. I know they're harder to generate

> in textarea fields, because you have to do them by hand, but I'm

> finding it harder and harder to care about the plight of the

> textarea-field-writer.

>

> ~ function db_like($first, $pattern) {

> ~ $pattern = preg_quote($pattern);

> ~ $pattern = preg_replace('/(?<!\\)_/', '.', $pattern);

> ~ $pattern = preg_replace('/(?<!\\)%/', '.*?', $pattern);

> ~ return preg_match('{^'.$pattern.'$}', $first);

> ~ }


Personally, I don't find that aesthetically better than my proposal.
The only problem it solves is the one of two consecutive code blocks,
or a code block following a list. Other than that, it has no use; I
don't see how anyone will prefer that syntax over simple indentation,
except in the two corner cases mentioned above.

My proposal is some sort of a lazy syntax for code blocks, building
on what some people use lazily in their emails, and it has more use
than these two corner-cases. Just as you said, you don't have to use
it if you prefer the other one.



> One nice thing about '~' is that (on U.S. keyboards at least) it's

> on the same key as '`' -- so you'd use the same key for inline

> code spans as for code blocks.


Interesting. On my Canadian-French (CSA) keyboard, '~' is Option-Ç
and '`' is Option-À, two adjacent keys.

- - -

That said, we could also take a hybrid approach where there is only
one syntax for code block: indentation; but where you can use an
optional tilde '~' maker at the start of a new one when you need some
disambiguation:

Standard paragraph.

<title>My Page</title>

~ <title>
<?php echo $title ?>
</title>

* List item
* List item

~ <style>
<?php echo $stylesheet ?>
</style>

The downside of this approach is that it looks like some kind of list
item marker. But so do this:

Standard paragraph.

~ <title>My Page</title>

~ <title>
~ <?php echo $title ?>
~ </title>

* List item
* List item

~ <style>
~ <?php echo $stylesheet ?>
~ </style>

(Of course, the first tilde for the first code block is optional:
both code block syntaxes can be used there.)

Now let's compare to my approach:

Standard paragraph.

~~~
<title>My Page</title>
~~~

~~~
<title>
<?php echo $title ?>
</title>
~~~

* List item
* List item

~~~
<style>
<?php echo $stylesheet ?>
</style>
~~~

Which one do you prefer?


Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/




More information about the Markdown-Discuss mailing list