The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

closing vbulletin tags in a string

4 posters

Go down

closing vbulletin tags in a string Empty closing vbulletin tags in a string

Post by _Twisted_Mods_ November 9th 2016, 6:39 pm

ok so what im wanting it to prevent errors in a string example

Code:

str = '[color=red]just some random[color=green]text[/color][/color]'

the sting wouldnt be right because the color tags are inside each other so what im wanting to do is make a function that will check the string to make sure all color tags are closed correct and return a result like this

Code:

str = '[color=red]just some random[/color][color=green]text[/color]'
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by Ch@lo Valdez November 10th 2016, 1:37 am

This is probably useful for you

Code:

function str_replace(c){
    var a = /\[color=(\w+)\](.*?)\[color=(.*?)\](\w+)\[\/color\]\[\/color\]/,
        b = '[color=red]$2[/color][color=green]$4[/color]';
 return c.replace(a, b)
};

use this way:

Code:
text = document.getElementsByTagName('textarea')[0]; //or jQuery $('textarea').val()
text.value = str_replace(text.value);

maybe with more details can do something better
Ch@lo Valdez
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by _Twisted_Mods_ November 10th 2016, 2:27 pm

ok well im usen a script to color highlighted text in a textbox but i want to make sure each vbulletin color tag is closed correct and it dont put color tags inside each other and send it incorrect

example if i put somthing like this in the text box and submit it

Code:

[color=#8333ff]just testing [color=#0000ff]some stuff[/color][/color]

the html will turn out like this

Code:

<div><span style="color:#8333ff;">just[color=#0000ff] testing</span> some stuff [/color]</div>


and its because one color code wasnt ended before the next one started its inside each other if that makes any sense
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by Ch@lo Valdez November 10th 2016, 3:19 pm

this regexp work for that you want
Code:
a = /\[color=(\w+)\](.*?)\[color=(.*?)\](\w+)\[\/color\]\[\/color\]/;
b = '[color=$1]$2[/color][color=$3]$4[/color]';

you can make a js prevent this situation before submit for example:

Code:
your_submit_button.onclick = function(){
textarea = your textarea here;
a = /\[color=(.*?)\](.*?)\[color=(.*?)\](.*?)\[\/color\]\[\/color\]/;
b = '[color=$1]$2[/color][color=$3]$4[/color]';
c= textarea.value.match(a);
if (c){
textarea.value = textarea.value.replace(a, b);
return false
}else{
//go submit
}
};


Last edited by Ch@lo Valdez on November 10th 2016, 3:42 pm; edited 1 time in total
Ch@lo Valdez
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by _Twisted_Mods_ November 10th 2016, 3:29 pm

what it the end color tag isnt next to each other like this

Code:

[color=#8333ff]just testing [color=#0000ff]some[/color] stuff[/color]
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by Ch@lo Valdez November 10th 2016, 3:40 pm

_Twisted_Mods_ wrote:what it the end color tag isnt next to each other like this

Code:

[color=#8333ff]just testing [color=#0000ff]some[/color] stuff[/color]

this is another error string to fix or the result you want ?
Ch@lo Valdez
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by _Twisted_Mods_ November 10th 2016, 3:45 pm

sorry. it is an error because the color tag did not close before the next one started
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by Ch@lo Valdez November 10th 2016, 4:00 pm

how you want the final fix string? in this case we have 5 elements
Code:
[color=#8333ff]just testing [color=#0000ff]some[/color] stuff[/color]

1$ is '#8333ff'
2$ is 'just testing'
3$ is '#0000ff'
4$ is 'some'
5$ is 'stuff'

in replace
Code:
'[color=$1]$2[/color][color=$3]$4[/color]'

Where should element 5 go?

Code:
'[color=$1]$2[/color][color=$3]$4 $5[/color]'
Ch@lo Valdez
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by _Twisted_Mods_ November 10th 2016, 4:13 pm

ok lest say this is the input

Code:

[color=#8333ff]just [color=#ff0000]testing [color=#0000ff]some[/color][/color] stuff[/color]

this is the result i would get
closing vbulletin tags in a string B166014f28554f778da866de4868df5e
the correct way should be

Code:

[color=#8333ff] just[/color] [color=#ff0000]testing [/color][color=#0000ff]some[/color][color=#8333ff]stuff[/color]

and the result would look like this

closing vbulletin tags in a string 80061e1fff774c52b6a1f9df2cd04102

basically i want it to close all color tags and not allow them to be inside each other
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by Ch@lo Valdez November 10th 2016, 4:27 pm

mmmm let me think

send me the url of your blog or forum please
Ch@lo Valdez
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by _Twisted_Mods_ November 10th 2016, 4:39 pm

sent u a pm
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by SLGray November 10th 2016, 9:30 pm

I believe you meant to say BBCode, not vBulletin tag codes.


closing vbulletin tags in a string Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51463
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by _Twisted_Mods_ November 11th 2016, 12:19 am

correct SL idk what i was on when i wrote that but ty...


ok so i found this idk if it will help any

Code:

 * Fixes any invalid nesting.
       *
       * If it is a block level element inside 1 or more inline elements
       * then those inline elements will be split at the point where the
       * block level is and the block level element placed between the split
       * parts. i.e.
       *    [inline]textA[blocklevel]textB[/blocklevel]textC[/inline]
       * Will become:
       *    [inline]textA[/inline][blocklevel]textB[/blocklevel][inline]textC[/inline]
       *
       * @param {Array} children
       * @param {Array} [parents] Null if there is no parents
       * @param {Array} [insideInline] Boolean, if insdie an inline element
       * @param {Array} [rootArr] Root array if there is one
       * @return {Array}
       * @private
       */
      fixNesting = function(children, parents, insideInline, rootArr) {
         var   token, i, parent, parentIndex, parentParentChildren, right,
            isInline = function(token) {
               var bbcode = base.bbcodes[token.name];

               return !bbcode || bbcode.isInline !== false;
            };

         parents = parents || [];
         rootArr = rootArr || children;

         // this must check length each time as the length
         // can change as tokens are moved around to fix the nesting.
         for(i=0; i<children.length; i++)
         {
            if(!(token = children[i]) || token.type !== tokenType.open)
               continue;

            if(!isInline(token) && insideInline)
            {
               // if this is a blocklevel element inside an inline one then split
               // the parent at the block level element
               parent              = last(parents);
               right                = parent.splitAt(token);
               parentParentChildren = parents.length > 1 ? parents[parents.length - 2].children : rootArr;

               if((parentIndex = $.inArray(parent, parentParentChildren)) > -1)
               {
                  // remove the block level token from the right side of the split
                  // inlnie element
                  right.children.splice($.inArray(token, right.children), 1);

                  // insert the block level token and the right side after the left
                  // side of the inline token
                  parentParentChildren.splice(parentIndex+1, 0, token, right);

                  // return to parents loop as the children have now increased
                  return;
               }

            }

            parents.push(token);
            fixNesting(token.children, parents, insideInline || isInline(token), rootArr);
            parents.pop(token);
         }
      };
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

closing vbulletin tags in a string Empty Re: closing vbulletin tags in a string

Post by LGforum November 22nd 2016, 4:22 am

I'm curious as to why you want to fix this? Color tags within color tags isn't a bad thing or even incorrect, if anything its an even more efficient use of tags and I'm pretty sure it will be parsed correctly by the forum and will be displayed correctly in posts, won't it?

Lets try:
just some random text

See, it works fine Smile
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum