The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Replace html with bbcode (in posts)

3 posters

Go down

Solved Replace html with bbcode (in posts)

Post by LeChat October 17th 2023, 9:01 pm

Technical Details


Forum version : #phpBB3
Position : Founder
Concerned browser(s) : Mozilla Firefox, Google Chrome, Internet Explorer
Forum link : http://mayo.forumpolish.com

Description of problem

I want to replace this code:

Code:
<div class="tele_bg">
<div class="tele_ico">
<img src="OBRAZEK LUB GIF"></div>
<div class="tele_name">IMIĘ POSTACI</div><div class="tele_msn">

<p>Treść wiadomości</p>
<p>Treść wiadomości</p>
<p>[img="link"]OBRAZEK W WIADOMOŚCI[/img]</p>

</div><div class="tele_field"></div></div>

with something more or less like this:

Code:
[tele]
[teleimg]OBRAZEK LUB GIF[/teleimg]
[telename]IMIĘ POSTACI[/telename]

[p]Treść wiadomości[/p]
[p]Treść wiadomości[/p]
[p][img="link"]OBRAZEK W WIADOMOŚCI[/img][/p]
[/tele]

I saw this topic: https://help.forumotion.com/t153342-tutorial-create-new-bbcode-tags?highlight=bbcode , but it looks more complicated than what I want.

Any ideas?

Edit: I have something like this - but maybe is better way to do that?

Code:
(function() {
    BBParser = {
        initialize: function() {
            $(function() {
                BBParser.setupBBParser()
            })
        },
        add: [{
            tag: 'zapro',
            close: true,
            replacement: '<div class="wizmot zapro">{content}</div>'
        }, {
            tag: 'kom',
            close: true,
            replacement: '<div class="wizkom">{content}</div>'
        }, {
            tag: 'status',
            close: true,
            replacement: '<div class="wizmot stat">{content}</div>'
        }, {
            tag: 'zaczep',
            close: true,
            replacement: '<div class="wizmot czep">{content}</div>'
        }, {
            tag: 'lubie',
            close: true,
            replacement: '<div class="wizcyt">{content}</div>'
        }, {
            tag: 'inne',
            close: true,
            replacement: '<div class="wizmot inne">{content}</div>'
        }],
        validateTag: function(a) {
            if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a)
        },
        replacers: function(a, b, c) {
            return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "")
        },
        optionReg: /.*?=("|'|)(.*?)\1\]/,
        parsedContent: function(a, b, c) {
            return a.replace(c ? RegExp("(\\[" + b.tag + "[^\\]]*\\])([\\s\\S]*?)\\[/" + b.tag + "]", "g" + (b.insensitive ? "i" : "")) : RegExp("\\[" + b.tag + "[^\\]]*\\]", "g" + (b.insensitive ? "i" : "")), function(d, e, f) {
                c || (e = d);
                e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
                if ("undefined" !== typeof b.replace) {
                    d = c ? b.replace(e, f) : b.replace(e);
                    "string" === typeof d ? c ? f = d : e = d : d;
                    "object" === typeof d && (e = d.option || e, f = d.content || f)
                }
                return BBParser.replacers(b.replacement, e, f)
            })
        },
        setupBBParser: function() {
            var postBody = $(".postbody, .blog_message");
            for (var i = 0, e;
                (e = postBody[i++]);) {
                for (var j in BBParser.add) {
                    var item = BBParser.add[j];
                    BBParser.validateTag(item.tag);
                    e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close)
                }
            }
        }
    };
    BBParser.initialize()
})();


Last edited by LeChat on October 19th 2023, 8:45 pm; edited 1 time in total
LeChat
LeChat
Forumember

Posts : 39
Reputation : 1
Language : english, polish

http://cadikim.forumpl.net

Back to top Go down

Solved Re: Replace html with bbcode (in posts)

Post by skouliki October 18th 2023, 7:44 am

skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Replace html with bbcode (in posts)

Post by LeChat October 18th 2023, 5:51 pm

If I read it correctly, it's something only for administrators and moderators, and it isn't editable solution. But something "static" - not changeable in every post?

I need something which my users can edit themself. The bold text is for users to edit.

[tele]
[teleimg]IMAGE OR GIF LINK[/teleimg]
[telename]RPG CHARACTER NAME[/telename]

[p]TEXT[/p]
[p]TEXT[/p]
[p][img="link"]IMAGE LINK[/img][/p]
[/tele]
LeChat
LeChat
Forumember

Posts : 39
Reputation : 1
Language : english, polish

http://cadikim.forumpl.net

Back to top Go down

Solved Re: Replace html with bbcode (in posts)

Post by Razor12345 October 19th 2023, 10:59 am

Good afternoon!

How about this tutorial? You can tweak it a bit and a good basis for creating bbcode

A slightly simplified code on the French support forum: tutorial


Replace html with bbcode (in posts) Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Replace html with bbcode (in posts)

Post by LeChat October 19th 2023, 8:45 pm

Again, it's for moderators and admins only.

I guess I'll have to leave the html for users to use then. Anyway, thank you for your help. I mark it as solved even though it wasn't solved, but you can close the topic. xD
LeChat
LeChat
Forumember

Posts : 39
Reputation : 1
Language : english, polish

http://cadikim.forumpl.net

Back to top Go down

Solved Re: Replace html with bbcode (in posts)

Post by Razor12345 October 19th 2023, 9:08 pm

The user role check can be removed and the buttons become available to all users.

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


Replace html with bbcode (in posts) Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

TonnyKamper likes this post

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum