closing vbulletin tags in a string
4 posters
Page 1 of 1
closing vbulletin tags in a string
ok so what im wanting it to prevent errors in a string example
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=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]'
Re: closing vbulletin tags in a string
This is probably useful for you
use this way:
maybe with more details can do something better
- 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- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: closing vbulletin tags in a string
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
the html will turn out like this
and its because one color code wasnt ended before the next one started its inside each other if that makes any sense
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
Re: closing vbulletin tags in a string
this regexp work for that you want
you can make a js prevent this situation before submit for example:
- 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- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: closing vbulletin tags in a string
what it the end color tag isnt next to each other like this
- Code:
[color=#8333ff]just testing [color=#0000ff]some[/color] stuff[/color]
Re: closing vbulletin tags in a string
_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- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: closing vbulletin tags in a string
sorry. it is an error because the color tag did not close before the next one started
Re: closing vbulletin tags in a string
how you want the final fix string? in this case we have 5 elements
1$ is '#8333ff'
2$ is 'just testing'
3$ is '#0000ff'
4$ is 'some'
5$ is 'stuff'
in replace
Where should element 5 go?
|
1$ is '#8333ff'
2$ is 'just testing'
3$ is '#0000ff'
4$ is 'some'
5$ is 'stuff'
in replace
|
Where should element 5 go?
|
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: closing vbulletin tags in a string
ok lest say this is the input
this is the result i would get
the correct way should be
and the result would look like this
basically i want it to close all color tags and not allow them to be inside each other
- Code:
[color=#8333ff]just [color=#ff0000]testing [color=#0000ff]some[/color][/color] stuff[/color]
this is the result i would get
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
basically i want it to close all color tags and not allow them to be inside each other
Re: closing vbulletin tags in a string
mmmm let me think
send me the url of your blog or forum please
send me the url of your blog or forum please
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: closing vbulletin tags in a string
I believe you meant to say BBCode, not vBulletin tag codes.
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Re: closing vbulletin tags in a string
correct SL idk what i was on when i wrote that but ty...
ok so i found this idk if it will help any
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);
}
};
Re: closing vbulletin tags in a string
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
Lets try:
just some random text
See, it works fine
LGforum- Hyperactive
- Posts : 2265
Reputation : 264
Language : English
Location : UK
Similar topics
» Connect opening and closing tags
» Replace youtube tags with iframe tags
» Background color for topics that contain a certain string
» vBulletin 5 tabs
» Closing down a forum?
» Replace youtube tags with iframe tags
» Background color for topics that contain a certain string
» vBulletin 5 tabs
» Closing down a forum?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum