Skip to main content
Topic: Mother f#^$king code pasting in editor. (Read 6312 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Mother f#^$king code pasting in editor.

Reply #15
Yup ... I see that now that I updated the site lol ... have to see what else we can come up with
Be safe, Be kind, Happy Programing

Re: Mother f#^$king code pasting in editor.

Reply #16
Hey, brainwave. Why do we need the code tag as such? pre is for pre-formatted text, which is basically what code is anyway. Using it for code is valid usage, according to W3.

http://www.w3.org/TR/html5/grouping-content.html#the-pre-element

Quote
Some examples of cases where the
Code: [Select]
pre
element could be used:
 
  • Including an e-mail, with paragraphs indicated by blank lines, lists indicated by lines prefixed with a bullet, and so on.
  • Including fragments of computer code, with structure indicated according to the conventions of that language.
Now, it does recommend wrapping the code in a code tag, but it doesn't strictly require that it has to be done.

Quote
To represent a block of computer code, the pre element can be used with a code element; to represent a block of computer output the pre element can be used with a samp element.

Note the "can".

Also, if using the code tags for output, in theory that would require a different markup to source code.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #17
Oh and while I'm looking at Subs, the old markup for the quote tags is effin horrible. I'll re-write that into something saner.

I'll also change some of the others to make them more up to date. Things like switching i for em in the italic tags, etc. Could even go so far as to have bbc colour classes so they could be adjusted on a per theme basis (which can be really good for readability). Example:

Code: [Select]
			array(
'tag' => 'green',
'before' => '<span class="bbc_color bbc_green">',
'after' => '</span>',
),

We should also ditch the horrible IE filters for things like shadow. Just let them call css3 text shadow and bugger old IE.

And, if we want a marquee tag (bouncing parrots!) I can write a really slick one in valid css3/html. No deprecated tags required.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #18
Oh and while I'm on a roll :D here's another brainwave. At the moment the PHP BBC tag does not style the same way as the ordinary code tags, nor does it have a selection link above it. We should use consistent formatting there too.

[php]            array(
            'tag' => 'php',
            'type' => 'unparsed_content',
            'content' => '<span class="phpcode">$1</span>',
            'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
               if (!isset($disabled[\'php\']))
               {
                  $add_begin = substr(trim($data), 0, 5) != \'&lt;?\';
                  $data = highlight_php_code($add_begin ? \'&lt;?php \' . $data . \'?&gt;\' : $data);
                  if ($add_begin)
                     $data = preg_replace(array(\'~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~\', \'~\?&gt;((?:</(font|span)>)*)$~\'), \'$1\', $data, 2);
               }'),
            'block_level' => false,
            'disabled_content' => '$1',
         ),[/php]

Testing something.

Code: [Select]
[php]				array(
'tag' => 'php',
'type' => 'unparsed_content',
'content' => '<span class="phpcode">$1</span>',
'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
if (!isset($disabled[\'php\']))
{
$add_begin = substr(trim($data), 0, 5) != \'&lt;?\';
$data = highlight_php_code($add_begin ? \'&lt;?php \' . $data . \'?&gt;\' : $data);
if ($add_begin)
$data = preg_replace(array(\'~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~\', \'~\?&gt;((?:</(font|span)>)*)$~\'), \'$1\', $data, 2);
}'),
'block_level' => false,
'disabled_content' => '$1',
),[/php]

ETA: Yup. Putting php tags inside code tags borks the syntax highlighting. Is not optimal innit.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #19
I think its the pre tag that is causing sce to go nuts ... not the code per say ...

so and experiment

<p class="bla"></p>


Quote
Oh and while I'm looking at Subs, the old markup for the quote tags is effin horrible. I'll re-write that into something saner.
No worries but be aware, thats just parse_bbc, you will need to update the editor to insert the new bbc tags as well, and the conversion from to wiz ....
Be safe, Be kind, Happy Programing

Re: Mother f#^$king code pasting in editor.

Reply #20
So does that pre tag paste mess things up as well ??

<p class="bla"></p>


ETA: apparently not ... so its only the pre code code pre thingy

ETA2: Changed parse_bbc code to only do it as a pre tag, so lets see what that does (have not changed the editor)
Be safe, Be kind, Happy Programing

Re: Mother f#^$king code pasting in editor.

Reply #21
Hey I wonder if it's to do with the css:

Code: [Select]
.bbc_code{display:block;
The code element is not block by default. Try ditching that and just leaving it (code tag) wrapped in pre for all browsers.

ETA: Ok, scratch that then. It's valid without the code tag so why bloat things?
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #22
Testing new stuff in FF. Quick reply.

Code: [Select]
			array(
'tag' => 'php',
'type' => 'unparsed_content',
'content' => '<span class="phpcode">$1</span>',
'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
if (!isset($disabled[\'php\']))
{
$add_begin = substr(trim($data), 0, 5) != \'&lt;?\';
$data = highlight_php_code($add_begin ? \'&lt;?php \' . $data . \'?&gt;\' : $data);
if ($add_begin)
$data = preg_replace(array(\'~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~\', \'~\?&gt;((?:</(font|span)>)*)$~\'), \'$1\', $data, 2);
}'),
'block_level' => false,
'disabled_content' => '$1',
),
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #23
Full reply.

Code: [Select]
			array(
'tag' => 'php',
'type' => 'unparsed_content',
'content' => '<span class="phpcode">$1</span>',
'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
if (!isset($disabled[\'php\']))
{
$add_begin = substr(trim($data), 0, 5) != \'&lt;?\';
$data = highlight_php_code($add_begin ? \'&lt;?php \' . $data . \'?&gt;\' : $data);
if ($add_begin)
$data = preg_replace(array(\'~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~\', \'~\?&gt;((?:</(font|span)>)*)$~\'), \'$1\', $data, 2);
}'),
'block_level' => false,
'disabled_content' => '$1',
),
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #24
;D Works now. Yay!
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #25
hey looks like crap without block :o
Be safe, Be kind, Happy Programing


Re: Mother f#^$king code pasting in editor.

Reply #27
Ok, next drama: this post is causing a pile of validation errors due to it wanting to insert coloured spans inside all the pre tags:

http://www.elkarte.net/index.php?topic=103.msg677#msg677


<div class="inner" id="msg_677">Oh and while I'm on a roll <img src="http://www.elkarte.net/Smileys/fugue/cheesy.gif" alt=":D" title="Cheesy" class="smiley" /> here's another brainwave. At the moment the PHP BBC tag does not style the same way as the ordinary code tags, nor does it have a selection link above it. We should use consistent formatting there too.

<span class="phpcode"><span style="color: #000000"><span style="color: #0000BB"><pre style="display: inline;">   
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   array(
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #DD0000">'tag'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'php'</span><span style="color: #007700">,
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #DD0000">'type'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'unparsed_content'</span><span style="color: #007700">,
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #DD0000">'content'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'&lt;span&nbsp;class="phpcode"&gt;$1&lt;/span&gt;'</span><span style="color: #007700">,
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #DD0000">'validate'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;isset(</span><span style="color: #0000BB">$disabled</span><span style="color: #007700">['php'])&nbsp;?&nbsp;</span><span style="color: #0000BB">null&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">create_function</span><span style="color: #007700">(</span><span style="color: #DD0000">'&amp;$tag,&nbsp;&amp;$data,&nbsp;$disabled'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   if&nbsp;(!isset($disabled[\'php\']))
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   {
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   $add_begin&nbsp;=&nbsp;substr(trim($data),&nbsp;0,&nbsp;5)&nbsp;!=&nbsp;\'&amp;lt;?\';
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   $data&nbsp;=&nbsp;highlight_php_code($add_begin&nbsp;?&nbsp;\'&amp;lt;?php&nbsp;\'&nbsp;.&nbsp;$data&nbsp;.&nbsp;\'?&amp;gt;\'&nbsp;:&nbsp;$data);
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   if&nbsp;($add_begin)
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   $data&nbsp;=&nbsp;preg_replace(array(\'~^(.+?)&amp;lt;\?.{0,40}?php(?:&nbsp;|\s)~\',&nbsp;\'~\?&amp;gt;((?:&lt;/(font|span)&gt;)*)$~\'),&nbsp;\'$1\',&nbsp;$data,&nbsp;2);
<pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   <pre style="display: inline;">   }'</span><span style="color: #007700">),
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #DD0000">'block_level'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #DD0000">'disabled_content'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'$1'</span><span style="color: #007700">,
</span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   </span><span style="color: #0000BB"><pre style="display: inline;">   ),</span><span style="color: #0000BB"></span></span></span>

Testing something.

<div class="codeheader">Code: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">[Select][/url]</div>
<code class="bbc_code">
[php]<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>array(
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>'tag' =&gt; 'php',
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>'type' =&gt; 'unparsed_content',
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>'content' =&gt; '&lt;span class=&quot;phpcode&quot;&gt;$1&lt;/span&gt;',
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>'validate' =&gt; isset($disabled['php']) ? null : create_function('&amp;$tag, &amp;$data, $disabled', '
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>if (!isset($disabled[\'php\']))
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>{
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>$add_begin = substr(trim($data), 0, 5) != \'&amp;lt;?\';
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>$data = highlight_php_code($add_begin ? \'&amp;lt;?php \' . $data . \'?&amp;gt;\' : $data);
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>if ($add_begin)
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>$data = preg_replace(array(\'~^(.+?)&amp;lt;\?.{0,40}?php(?:&amp;nbsp;|\s)~\', \'~\?&amp;gt;((?:&lt;/(font|span)&gt;)*)$~\'), \'$1\', $data, 2);
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>}'),
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>'block_level' =&gt; false,
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>'disabled_content' =&gt; '$1',
<span style="white-space: pre;">   </span><span style="white-space: pre;">   </span><span style="white-space: pre;">   </span>),[/php]
</code>
ETA: Yup. Putting php tags inside code tags borks the syntax highlighting. Is not optimal innit. </div>

[/pre]
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #28
Hey I think I found another bug. :D
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Mother f#^$king code pasting in editor.

Reply #29
hey looks like crap without block :o

That'd just be css though, or maybe we want to wrap it in something else. Wouldn't worry too much.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P