В связи с переходом на новый движок... возможны сбои в работе! Простите!
Работы производятся прямо сейчас 19-03-2024! 🞨
Меню :
bbcode (4)



Blog (1392)
php (329)
js (244)
html (147)
css (131)
html tags (62)
js tag (56)
jquery (42)
text (37)
js method (36)
php array (33)
js date (33)
form html (30)
online (29)
Показать еще :
fonts (26)
ruweb.net (25)
foto (22)
php file (20)
atom (20)
forum (19)
hosting (18)
svg (18)
input (18)
php date (17)
board (16)
php time (16)
html book (16)
color (15)
info (15)
img (14)
js time (14)
js url (14)
js events (14)
htaccess (13)
select (13)
notepad (13)
osclass (13)
keyboard (12)
знак (12)
dw block (12)
php img (12)
php path (12)
table (12)
download (12)
icon (11)
form (11)
jsphp (11)
alphabet (10)
keyframes (10)
js delete (10)
yandex (10)
mouse (10)
chart (9)
hover (9)
dosite (8)
browser (8)
php post (7)
comment (7)
php url (7)
iframe (6)
php get (6)
mysql (6)
click (6)
list (6)
canvas (6)
adminka (6)
vs code (6)
js id (5)
mb (5)
heading (5)
value (5)
reg.ru (5)
ftp (5)
year (5)
js math (5)
tag a (5)
bbcode (4)
php var (4)
base64 (4)
xml (4)
scandir (4)
games (4)
flags (4)
symbols (4)
week (4)
day (4)
ssl (4)
нок (4)
submit (4)
task (4)
vk (4)
month (4)
pages (4)
console (4)
js form (4)
domen (3)
line (3)
https (3)
js post (3)
jquery post (3)
money (3)
numbers (3)
js img (3)
padding (3)
куб (3)
captcha (3)
ucoz (3)
js hash (3)
tag hr (2)
details (2)
typeof (2)
seo (2)
prompt (2)
sitemap (2)
рся (2)
youtube (2)
height (2)
arrows (2)
js vars (2)
counter (2)
google (2)
qr kod (2)
video (2)
speed (1)
smile (1)
нод (1)
rutube (1)
scroll (1)
windows (1)
archive (1)
jino (1)
cursor (1)

BBcode в javascript

В общем-то функция BBcode в javascript ничем не отличается, от ранее написанной страницы о BBcode в php. Единственное отличие BBcode в javascript, что данный пример не использует массивы, а в функцию на каждую замену – отдельная строка с функцией replace

Преобразование BBcode в html в javascript

Для того, чтобы преобразовать BBcode в html в javascript, копируем все, что выделено внизу... вставляем туда, где это вам требуется...

заменяем название htmlToBBCode например на BBCodeTohtml ? html на ...например backhtml

Берем каждую строку, на примере первой:

html = html.replace(/<h2(.*?)>(.*?)<\/h2>/, "\n[h2]$2[/h2]\n");

И преобразуем её в такую:

backhtml = backhtml .replace( '/\[h2\](.*?)\[\/h2\]' , '<h2>$1</h2>' );

Я бы вам предложил готовую BBcode функцию javascript, но её нет у меня!

Ну а вот живая функция html в BBcode есть, которой непосредственно пользуюсь и использовали в наших комментах

Преобразование html в BBcode в javascript

В некоторых строках, где присутствует переменная httpDomen - для смайлов - заменяем на свой путь до папки.

Некоторые строки закомментированы(//) - это сделано потому, что не все преобразования мне требуются...

var htmlToBBCode = functionhtml {

html = html.replace(/<h2(.*?)>(.*?)<\/h2>/, "\n[h2]$2[/h2]\n");

html = html.replace(/<h3(.*?)>(.*?)<\/h3>/, "\n[h3]$2[/h3]\n");

html = html.replace(/<h4(.*?)>(.*?)<\/h4>/, "\n[h4]$2[/h4]\n");

html = html.replace(/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/gi, "[url=$2]$4[/url]");

html = html.replace(/<span(.*?)style="color:(.*?)"(.*?)>(.*?)<\/span>/gi, '[COLOR="$2"]$4[/COLOR]');

html = html.replace(/<img(.*?)src="httpDomen\/comments+1_4\/blocks\/_smaile\/(.*?).gif"(.*?)>/gi, "[$2]");

html = html.replace(/<img(.*?)src="httpDomen\/comments+1_4\/blocks\/_smaile_girl\/(.*?).gif"(.*?)>/gi, "[$2]");

html = html.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, '[img]$2[/img]');

html = html.replace(/<red>(.*?)<\/red>/gi, '[red]$1[/red]');

html = html.replace(/<s>(.*?)<\/s>/gi, '[s]$1[/s]');

html = html.replace(/<l>(.*?)<\/l>/gi, '[l]$1[/l]');

html = html.replace(/<strong>(.*?)<\/strong>/gi, '[strong]$1[/strong]');

html = html.replace(/<em>(.*?)<\/em>/gi, '[em]$1[/em]');

html = html.replace(/<u>(.*?)<\/u>/gi, '[u]$1[/u]');

html = html.replace(/<sup>(.*?)<\/sup>/gi, '[sup]$1[/sup]');

html = html.replace(/<sub>(.*?)<\/sub>/gi, '[sub]$1[/sub]');

html = html.replace(/<iframe(.*?)src="https:\/\/www.youtube.com\/embed\/(.*?)"(.*?)><\/iframe>/gi, "[YOUTUBE]$2[/YOUTUBE]");

html = html.replace(/<br(.*?)>/gi, "\n");

//- if a paragraph opens on the same line as another one closes, insert an extra blank line

//- opening tag becomes two line breaks

//- closing tags are just removed

// html += html.replace(/<\/p><p/<\/p>\n<p/gi;

// html += html.replace(/<p[^>]*>/\n\n/gi;

// html += html.replace(/<\/p>//gi;

// html = html.replace(/<textarea(.*?)>(.*?)<\/textarea>/gmi, "\[code]$2\[\/code]");

// html = html.replace(/<b>/gi, "[b]");

// html = html.replace(/<i>/gi, "[i]");

// html = html.replace(/<u>/gi, "[u]");

// html = html.replace(/<\/b>/gi, "[/b]");

// html = html.replace(/<\/i>/gi, "[/i]");

// html = html.replace(/<\/u>/gi, "[/u]");

// html = html.replace(/<em>/gi, "[b]");

// html = html.replace(/<\/em>/gi, "[/b]");

// html = html.replace(/<strong>/gi, "[b]");

// html = html.replace(/<\/strong>/gi, "[/b]");

// html = html.replace(/<cite>/gi, "[i]");

// html = html.replace(/<\/cite>/gi, "[/i]");

// html = html.replace(/<font color="(.*?)">(.*?)<\/font>/gmi, "[color=$1]$2[/color]");

// html = html.replace(/<font color=(.*?)>(.*?)<\/font>/gmi, "[color=$1]$2[/color]");

// html = html.replace(/<link(.*?)>/gi, "");

// html = html.replace(/<li(.*?)>(.*?)<\/li>/gi, "[*]$2");

// html = html.replace(/<ul(.*?)>/gi, "[list]");

// html = html.replace(/<\/ul>/gi, "[/list]");

// html = html.replace(/<div>/gi, "\n");

// html = html.replace(/<\/div>/gi, "\n");

// html = html.replace(/<td(.*?)>/gi, " ");

// html = html.replace(/<tr(.*?)>/gi, "\n");

// html = html.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, "[img]$2[/img]");

// html = html.replace(/<head>(.*?)<\/head>/gmi, "");

// html = html.replace(/<object>(.*?)<\/object>/gmi, "");

// html = html.replace(/<script(.*?)>(.*?)<\/script>/gmi, "");

// html = html.replace(/<style(.*?)>(.*?)<\/style>/gmi, "");

// html = html.replace(/<title>(.*?)<\/title>/gmi, "");

// html = html.replace(/<!--(.*?)-->/gmi, "\n");

// html = html.replace(/\/\//gi, "/");

// html = html.replace(/http:\//gi, "http://");

// html = html.replace(/<(?:[^>'"]*|(['"]).*?\1)*>/gmi, "");

// html = html.replace(/\r\r/gi, "");

// html = html.replace(/\[url=\//gi, "[url=");

// html = html.replace(/(\S)\n/gi, "$1 ");

return html;

}

Не стесняемся говорить спасибо!
Помочь проекту DwWeb.ru

Поделиться ссылкой! C друзьями или врагами!

Этим вы очень поможете проекту! Заранее огромное спасибо!

Ещё : dwweb.ru есть здесь:
ruweb
Все статьи авторские, при копироавании активная ссылка обязательна DwWeb.ru! © 2015 - 2024 Контакты. Реклама на сайте Лучший хостинг : RUWEB + помощь по RUWEB
Страница загружена за : 0.017127 секунд. Подробнее