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.
The forum of the forums
5 posters

    remove-format button removes blockcodes

    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved remove-format button removes blockcodes

    Post by hbghlyj August 20th 2021, 11:00 am

    Hello,
    I noticed that remove-format button removes blockcodes.
    Is it possible to preserve blockcodes (as it preserves blockquotes) by modifying code of SCEditorĀ Shocked

    remove-format button removes blockcodes 1

    I have another question about remove-format function:
    The font-size cannot be cleared in one click if it is nested (this is common in web page HTML)
    For example, I copied some paragraphs from wikipedia
    Code:
    [size=14]In[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Physics][size=14]physics[/size][/url][size=14],[/size][size=14]Ā [/size][b][size=14]angular momentum[/size][/b][size=14]Ā [/size][size=14](rarely,[/size][size=14]Ā [/size][b][size=14]moment of momentum[/size][/b][size=14]Ā [/size][size=14]or[/size][size=14]Ā [/size][b][size=14]rotational momentum[/size][/b][size=14]) is the rotational equivalent of[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Linear_momentum][size=14]linear momentum[/size][/url][size=14]. It is an important quantity in physics because it is a[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Conservation_law][size=14]conserved quantity[/size][/url][size=14]—the total angular momentum of a closed system remains constant.[/size]
    [size=14]In threeĀ [url=https://en.wikipedia.org/wiki/Dimensions]dimensions[/url], the angular momentum for aĀ [url=https://en.wikipedia.org/wiki/Point_particle]point particle[/url]Ā is aĀ [url=https://en.wikipedia.org/wiki/Pseudovector]pseudovector[/url]Ā [b]r[/b]Ā Ć—Ā [b]p[/b], theĀ [url=https://en.wikipedia.org/wiki/Cross_product]cross product[/url]Ā of the particle'sĀ [url=https://en.wikipedia.org/wiki/Position_vector]position vector[/url]Ā [b]r[/b]Ā (relative to some origin) and itsĀ [url=https://en.wikipedia.org/wiki/Momentum_vector]momentum vector[/url]; the latter isĀ [b]p[/b]Ā =Ā [i]m[/i][b]v[/b]Ā in Newtonian mechanics. Unlike momentum, angular momentum depends on where the origin is chosen, since the particle's position is measured from it.[/size]
    [size=14]Just as forĀ [url=https://en.wikipedia.org/wiki/Angular_velocity]angular velocity[/url], there are two special types of angular momentum of an object: theĀ [i]spin angular momentum[/i]Ā is the angular momentum about the object'sĀ [url=https://en.wikipedia.org/wiki/Centre_of_mass]centre of mass[/url], while theĀ [i]orbital angular momentum[/i]Ā is the angular momentum about a chosen center of rotation. The total angular momentum is the sum of the spin and orbital angular momenta. The orbital angular momentum vector of a point particle is always parallel and directly proportional to its orbitalĀ [url=https://en.wikipedia.org/wiki/Angular_velocity]angular velocity[/url]Ā vectorĀ [b]Ļ‰[/b], where the constant of proportionality depends on both the mass of the particle and its distance from origin. The spin angular momentum vector of a rigid body is proportional but not always parallel to the spin angular velocity vectorĀ [b]Ī©[/b], making the constant of proportionality a second-rankĀ [url=https://en.wikipedia.org/wiki/Tensor]tensor[/url]Ā rather than a scalar.[/size]
    [size=14]Angular momentum is an extensive quantity; i.e. the total angular momentum of any composite system is the sum of the angular momenta of its constituent parts. For aĀ [url=https://en.wikipedia.org/wiki/Continuum_mechanics]continuous[/url]Ā rigid body or a fluid the total angular momentum is the volume integral of angular momentum density (i.e. angular momentum per unit volume in the limit as volume shrinks to zero) over the entire body.[/size]
    [size=14]Torque can be defined as the rate of change of angular momentum, analogous toĀ [url=https://en.wikipedia.org/wiki/Force]force[/url]. The netĀ [i]external[/i]Ā torque on any system is always equal to theĀ [i]total[/i]Ā torque on the system; in other words, the sum of all internal torques of any system is always 0 (this is the rotational analogue ofĀ [url=https://en.wikipedia.org/wiki/Newton%27s_Third_Law]Newton's Third Law[/url]). Therefore, for aĀ [i]closed[/i]Ā system (where there is no net external torque), theĀ [i]total[/i]Ā torque on the system must be 0, which means that the total angular momentum of the system is constant. The conservation of angular momentum helps explain many observed phenomena, for example the increase in rotational speed of a spinningĀ [url=https://en.wikipedia.org/wiki/Figure_skater]figure skater[/url]Ā as the skater's arms are contracted, the high rotational rates ofĀ [url=https://en.wikipedia.org/wiki/Neutron_star]neutron stars[/url], theĀ [url=https://en.wikipedia.org/wiki/Coriolis_effect]Coriolis effect[/url], and theĀ [url=https://en.wikipedia.org/wiki/Precession]precession[/url]Ā ofĀ [url=https://en.wikipedia.org/wiki/Gyroscope]gyroscopes[/url]. In general, conservation limits the possible motion of a system but does not uniquely determine it.[/size]
    [size=14]In[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Quantum_mechanics][size=14]quantum mechanics[/size][/url][size=14], angular momentum (like other quantities) is expressed as an[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Operator_(physics)][size=14]operator[/size][/url][size=14], and its one-dimensional projections have[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Point_spectrum][size=14]quantized eigenvalues[/size][/url][size=14]. Angular momentum is subject to the[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Heisenberg_uncertainty_principle][size=14]Heisenberg uncertainty principle[/size][/url][size=14], implying that at any time, only one[/size][size=14]Ā [/size][url=https://en.wikipedia.org/wiki/Vector_projection][size=14]projection[/size][/url][size=14]Ā [/size][size=14](also called "component") can be measured with definite precision; the other two then remain uncertain. Because of this, the axis of rotation of a quantum particle is undefined. Quantum particles[/size][size=14]Ā [/size][i][size=14]do[/size][/i][size=14]Ā [/size][size=14]possess a type of non-orbital angular momentum called "spin", but this angular momentum does not correspond to a spinning motion.[/size][sup][size=12][url=https://en.wikipedia.org/wiki/Angular_momentum#cite_note-1][1][/url][/size][/sup]
    There are 47 pairs of [size] and [/size ] in this passage
    After first click, there are 28 pairs leftĀ 
    After second click, there are 0 pairs left
    Is it possible to clear all font-size in one click Shocked
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: remove-format button removes blockcodes

    Post by SLGray August 20th 2021, 2:54 pm

    All you have to do is only highlight the sections where you want to remove the format. Whatever you highlight should all be removed.

    Ā  Ā 



    remove-format button removes blockcodes Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 21st 2021, 7:04 am

    SLGray wrote:All you have to do is only highlight the sections where you want to remove the format. Whatever you highlight should all be removed.

    Ā  Ā 
    Hello,
    I noticed that if [size] is nested, they can′t be removed in one click.
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: remove-format button removes blockcodes

    Post by SLGray August 21st 2021, 1:55 pm

    It does when I tried.



    remove-format button removes blockcodes Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    Neptune-
    Neptune-
    Forumember


    Female Posts : 496
    Reputation : 104
    Language : French (10), English (8), CSS (5), HTML (4), Javascript (4)
    Location : Scotland, UK

    Solved Re: remove-format button removes blockcodes

    Post by Neptune- August 21st 2021, 4:20 pm

    Hello,


    If you do not want formatted text, why don't you copy/paste in source mode instead of wysiwyg mode ?
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 21st 2021, 4:30 pm

    Neptune- wrote:Hello,
    If you do not want formatted text, why don't you copy/paste in source mode instead of wysiwyg mode ?
    Hello,
    Because I would like to keep links, blockquotes and blockcodes. Smile
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 21st 2021, 4:58 pm

    SLGray wrote:It does when I tried.
    The problem is that it doesn't remove nested [size] in one click, here is a gif: https://ibb.co/YpP0yBz
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: remove-format button removes blockcodes

    Post by SLGray August 21st 2021, 5:26 pm

    Ok, I see what you mean. Usually when I copy and paste from other sites, I edit it before sending it.



    remove-format button removes blockcodes Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.

    poesia-verses likes this post

    Jucarese
    Jucarese
    Hyperactive


    Male Posts : 2551
    Reputation : 119
    Language : spanish
    Location : SSF Admin

    Solved Re: remove-format button removes blockcodes

    Post by Jucarese August 22nd 2021, 5:43 am

    This isn't remove format buttom,
    this is remove format buttom
    remove-format button removes blockcodes Remove10
    The other buttom Just change the way you see the content of the topic normal to WYSIWYG
    That's why the tags disappear

    Bockquotes is here:

    remove-format button removes blockcodes 1

    remove-format button removes blockcodes Block10

    Only when swinging between the editor's methods, the tags appear,or disappear but being there if you change the form of the editor, do not worry when sending the subject, the quote will appear without problems

    TonnyKamper likes this post

    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 22nd 2021, 6:24 am

    jucarese wrote:This isn't remove format buttom,
    this is remove format buttom
    ...
    Hello,
    You may have misunderstand me....
    I knew they were two buttons, remove-format and switch-mode. Switch-mode button has no problem, but remove-format button removes codeblocks.
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1443
    Reputation : 220
    Language : English

    Solved Re: remove-format button removes blockcodes

    Post by SarkZKalie August 22nd 2021, 7:41 am

    Next time, try to copy & paste your content to Notepad, then Ctrl+H do replace all [size] bbcode tag to empty
    Code:
    [size=14] [/size]



    remove-format button removes blockcodes Sarkzk10

    TonnyKamper likes this post

    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 24th 2021, 3:06 am

    SarkZKalie wrote:Next time, try to copy & paste your content to Notepad, then Ctrl+H do replace all bbcode tag to empty

    Code:
    [size=14] [/size]
    I think maybe we can modify a little bit of the code of sceditor to function automaticallyĀ  Dawa
    avatar
    Guest
    Guest


    Solved Re: remove-format button removes blockcodes

    Post by Guest August 24th 2021, 6:31 am

    @hbghlyj, I may be able to make such a code. Please explain in detail exactly what you want the remove format button to do, since this topic is already quite long and confusing!
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 24th 2021, 6:39 am

    Occultist wrote:@hbghlyj, I may be able to make such a code. Please explain in detail exactly what you want the remove format button to do, since this topic is already quite long and confusing!
    Thanks.
    First, I wish that it will keep all the code tags.
    Second, I wish that it will remove all the size tags only in one click (even if they are nested)


    Another question about javascript:
    I am curious what is the effect of "return true" on the editpost pageĀ 
    Screenshot:
    remove-format button removes blockcodes Image


    Last edited by hbghlyj on August 24th 2021, 9:28 am; edited 6 times in total
    avatar
    Guest
    Guest


    Solved Re: remove-format button removes blockcodes

    Post by Guest August 24th 2021, 6:47 am

    By blockcodes you mean the
    Code:
    [code][/code]
    tags?
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 24th 2021, 7:03 am

    Occultist wrote:By blockcodes you mean the
    Code:
    [code][/code]
    tags?
    Yes. The current script will remove all formatted code tags(formatted, not in the original form [code])
    avatar
    Guest
    Guest


    Solved Re: remove-format button removes blockcodes

    Post by Guest August 24th 2021, 2:05 pm

    This is a somewhat incomplete code that should do just about what you want:
    Code:
    $(function() {
        let sceditor = $.sceditor; // get instance of the editor
        if (!sceditor) return;
        // create a new command
        sceditor.command.set("removeformat2", {
            exec: function(c) {
                // when in wysiwyg; remove [b], [i], [u], [strike] and [font]
                let rangeHelper = this.getRangeHelper(); // get the current selection
                let newHTML = rangeHelper.selectedHtml().replace(
                    /\<(b|\/b|i|\/i|u|\/u|strike|\/strike|font size="\d+"|\/font)\>/g,
                    ""
                ); // remove the formatting from the selection
                rangeHelper.insertHTML(newText); // replace the selection with the unformatted text
            },
            txtExec: function() {
                // we are in text mode, so do nothing
            },
            tooltip: "Remove text formatting",
        });

        toolbar = toolbar.replace("removeformat", "removeformat2"); // replace the default button with the new one
    });
    I have only tested this for the quick reply editor, on the modernbb version(but it should work on all the other versions!). Currently it replaces the removeformat button with a new one(that has a youtube icon, as that is the default icon). The new button removes the b, i, u, strike and size tags, keeping everything else. It removes those tags no matter how nested they are.

    There are a couple other tags to remove, some css to give the button the right icon, and making sure that it works on all other editors, but first let me know if this works on your forum, and if so far it does what you're expecting it too! Smile

    The code should be added to the javascript code management section, as a new code, with whatever name you want, with the placement as "In the topics"(it will probably produce errors on other pages, but that will be taken care of in the final version).

    Update:I have edited the code. Now you can place it on all pages!
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 25th 2021, 1:41 am

    Hello,
    It seems that you've made a small mistake: you defined "newHTML" but "newText" is undefinedĀ 
    Also,Ā <font style="font-size: 14px;"> is not removed.Shocked
    avatar
    Guest
    Guest


    Solved Re: remove-format button removes blockcodes

    Post by Guest August 25th 2021, 4:51 am

    Hmm, you're right about the variable name. I thought newHTML made more sense, but forgot to replace it everywhere. Regardless, it looks like you managed to fix that yourself.

    I'm not sure what you mean about
    Code:
    <font style="font-size: 14px;">
    . If I write that in text mode, and then switch to wysiwyg mode, it stays as text. The editor itself doesn't seem to produce that kind of html. The default removeformat button doesn't do anything to it either.
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj August 25th 2021, 5:00 am

    Occultist wrote:Hmm, you're right about the variable name. I thought newHTML made more sense, but forgot to replace it everywhere. Regardless, it looks like you managed to fix that yourself.

    I'm not sure what you mean about
    Code:
    <font style="font-size: 14px;">
    . If I write that in text mode, and then switch to wysiwyg mode, it stays as text. The editor itself doesn't seem to produce that kind of html. The default removeformat button doesn't do anything to it either.
    No, it seems that switching to wysiwyg mode doesn't display HTML effects, you could try "preview" or "send" Smile
    remove-format button removes blockcodes Image
    ↑ Note that there are 3 huge "a" in the preview zone
    font-size, font-family and font-weight affect the font.
    avatar
    Guest
    Guest


    Solved Re: remove-format button removes blockcodes

    Post by Guest August 25th 2021, 6:03 am

    I see. I made a few modifications. Now anything of the form
    Code:
    <font *anything*>
    gets removed:
    Code:
    $(function () {
      let sceditor = $.sceditor; // get instance of the editor
      if (!sceditor) return;
      // create a new command
      sceditor.command.set("removeformat2", {
        exec: function (c) {
          // when in wysiwyg; remove [b], [i], [u], [strike] and [font]
          let rangeHelper = this.getRangeHelper(); // get the current selection
          let newHTML = rangeHelper
            .selectedHtml()
            .replace(
              /(\<|&lt;)(b|\/b|i|\/i|u|\/u|strike|\/strike|font.+?(?=(>|&gt;))|\/font)(>|&gt;)/g,
              ""
            ); // remove the formatting from the selection
          rangeHelper.insertHTML(newHTML); // replace the selection with the unformatted text
        },
        txtExec: function () {
          // we are in text mode, so do nothing
        },
        tooltip: "Remove text formatting",
      });

      toolbar = toolbar.replace("removeformat", "removeformat2"); // replace the default button with the new one
    });


    This has the nice side effect of removing custom fonts as well. Smile
    hbghlyj
    hbghlyj
    Forumember


    Male Posts : 32
    Reputation : 1
    Language : English+Chinese

    Solved Re: remove-format button removes blockcodes

    Post by hbghlyj September 2nd 2021, 1:27 pm

    Hello,
    I marked this topic as Solved but after refreshing the page it remains to be in progress Shocked
    remove-format button removes blockcodes Image
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: remove-format button removes blockcodes

    Post by SLGray September 2nd 2021, 1:52 pm

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



    remove-format button removes blockcodes Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.

      Current date/time is November 11th 2024, 3:22 pm