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


}

Не благодарите, но ссылкой можете поделиться!
Временная ссылка для быстрейшей индексации : список всех квадратных корней.
Теги :
BBcode в javascript
Еще никто не прокомментировал! COMMENTS+   BBcode
Подписаться + =

ruweb dwweb.ru есть здесь:
Последние комментарии :
Марат :
15.08.2023 17:50
Значит в "maxv" сидит…
подробнее.
михаил :
15.08.2023 16:53
а если это сделано для диаграммы values / maxv)…
подробнее.
Марат :
17.07.2023 15:50
Спасибо за интересный вопрос! Посмотрите …
подробнее.
Александр :
17.07.2023 14:58
а как сделать чтобы при повторном клике значение value возвращалось к…
подробнее.
Марат :
30.06.2023 10:18
Спасибо за внимательность!
подробнее.
???? :
29.06.2023 15:37
Прямоугольник - это геометрическая фигура, у которой три угла…
подробнее.
Немного о ruweb.net!
Страница загружена за : 0.015447 секунд. Подробнее