Войти
×
Меню :
js (302)
bbcode (4)



Blog (1964)
other (413)
php (390)
js (302)
html (153)
php book (148)
css (147)
пк (124)
html tags (63)
js tag (56)
windows (48)
js method (44)
jquery (43)
php array (39)
Показать еще :
ruweb.net (37)
text (37)
js date (33)
form html (30)
online (29)
link (26)
fonts (24)
js events (22)
dosite (22)
php file (21)
atom (20)
foto (20)
input (19)
database (19)
forum (18)
svg (18)
lingvo (18)
php date (17)
hosting (17)
mysql (17)
фото (16)
php img (16)
android (15)
img (15)
color (15)
php time (15)
info (15)
board (14)
notepad (14)
js url (14)
xiaomi (14)
js time (14)
jsphp (14)
table (13)
osclass (13)
htaccess (13)
знак (13)
select (13)
yandex (13)
$ server (12)
php path (12)
download (12)
icon (11)
vs code (11)
html book (11)
keyboard (11)
dw block (10)
js delete (10)
form (10)
css img (10)
paint (10)
ось (10)
mouse (10)
iframe (9)
ftp (9)
cookie (8)
hover (8)
php url (7)
ok (6)
comment (6)
search (6)
hey tag (6)
canvas (6)
list (6)
php get (6)
js vars (6)
нок (6)
click (6)
tag a (5)
js math (5)
js file (5)
web (5)
heading (5)
reg.ru (5)
value (5)
mb (5)
js id (5)
year (5)
xml (5)
console (5)
folder (4)
word (4)
news (4)
ssl (4)
base64 (4)
day (4)
week (4)
numbers (4)
task (4)
symbols (4)
pages (4)
month (4)
submit (4)
ucoz (4)
js book (4)
games (4)
js hash (4)
vk (4)
bbcode (4)
js form (4)
scandir (4)
youtube (4)
2022 (4)
php var (4)
adminka (4)
js img (4)
qr code (3)
https (3)
рся (3)
video (3)
padding (3)
file (3)
js post (3)
line (3)
units (3)
aimp (3)
php day (3)
404 (3)
captcha (3)
куб (3)
domen (3)
counter (2)
height (2)
prompt (2)
kfc (2)
seo (2)
details (2)
sitemap (2)
google (2)
src (2)
akaso (2)
typeof (2)
tag hr (2)
arrows (2)
blob (2)
js no4 (1)
header (1)
cursor (1)
replace (1)
font (1)
php (1)
rutube (1)
opera (1)
нод (1)
jino (1)
archive (1)
webp (1)
втб (1)
chart (1)
date (1)
name (1)
smile (1)
scroll (1)
speed (1)
#html (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.ebutuoy\/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;

}

Не стесняемся говорить спасибо!
Всего комментариев : 0 Comments+ 2.0
+ =
Помочь проекту DwWeb.ru

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

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

2). Помочь материально.

Теги:
BBcode в javascript

Последнние комментарии:

14.12.2025 :
комменты вернулись!
Марат 20.12.2025 18:30
С сегодняшнего дня будут обрабатываться только три смайла: Здесь... подробнее...
Марат 14.12.2025 21:45
Код немного опережает описание,поэтому оно(описание) будет появляться... подробнее...
Марат 14.12.2025 21:36
Вчера написал код - сегодня коротенькое описание, что... подробнее...
Марат 13.12.2025 23:56
В настройках комментов можно указать, что справа будут показываться... подробнее...
Марат 10.12.2025 23:09
Если вы думали, что нижняя история про клаву быстро закончилась.. то... подробнее...
ruweb
См. интсрукция по ruweb. dwweb.ru есть здесь:
Все соцсети в одном месте!
defense_js Разное :Игра "пятнашки"
Угадай страну по флагу

Кальклятор
Математика онлайн

Списки шифрования
Часы

Числа словами
Названия чисел(max=10305)
Графики

Qr код онлайн

Как сделать сайт?
Md5 онлайн
Sitemap.html
ruweb
Все статьи авторские, при копироавании активная ссылка обязательна DwWeb.ru! © 2015 - 2025 Контакты. Реклама на сайте Лучший хостинг : RUWEB + помощь по RUWEB Сайт работает круглосуточно 24/7.
Страница загружена за : 0.044142 секунд.