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



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

}

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

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

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

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

Теги:
BBcode в javascript
ruweb
См. интсрукция по ruweb. dwweb.ru есть здесь:
Все соцсети в одном месте!
defense_js Разное :Игра "пятнашки"
Угадай страну по флагу

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

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

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

Qr код онлайн

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