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.

remove-format button removes blockcodes

5 posters

Go down

Solved remove-format button removes blockcodes

Post by hbghlyj August 20th 2021, 5:00 pm

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
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by SLGray August 20th 2021, 8: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.
SLGray
SLGray
Administrator
Administrator

Male Posts : 50150
Reputation : 3457
Language : English
Location : United States

View user profile https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 21st 2021, 1:04 pm

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.
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by SLGray August 21st 2021, 7: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.
SLGray
SLGray
Administrator
Administrator

Male Posts : 50150
Reputation : 3457
Language : English
Location : United States

View user profile https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: remove-format button removes blockcodes

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

Hello,


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

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

View user profile https://www.galaxie-series.net/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 21st 2021, 10: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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 21st 2021, 10: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
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by SLGray August 21st 2021, 11: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.
SLGray
SLGray
Administrator
Administrator

Male Posts : 50150
Reputation : 3457
Language : English
Location : United States

View user profile https://forumsclub.com/gc/128-link-directory/

poesia-verses likes this post

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by jucarese August 22nd 2021, 11: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
jucarese
jucarese
Hyperactive

Male Posts : 2100
Reputation : 91
Language : spanish
Location : SSF Admin

View user profile http://asistencia.foroactivo.com/u23082

TonnyKamper likes this post

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 22nd 2021, 12:24 pm

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.
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by SarkZKalie August 22nd 2021, 1:41 pm

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
SarkZKalie
SarkZKalie
Support Moderator
Support Moderator

Male Posts : 1332
Reputation : 214
Language : English

View user profile https://rotavn.forumotion.com/

TonnyKamper likes this post

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 24th 2021, 9: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
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by Guest August 24th 2021, 12:31 pm

@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!
avatar
Guest
Guest


Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 24th 2021, 12:39 pm

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, 3:28 pm; edited 6 times in total
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by Guest August 24th 2021, 12:47 pm

By blockcodes you mean the
Code:
[code][/code]
tags?
avatar
Guest
Guest


Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 24th 2021, 1:03 pm

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])
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by Guest August 24th 2021, 8: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!
avatar
Guest
Guest


Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 25th 2021, 7: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
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by Guest August 25th 2021, 10: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.
avatar
Guest
Guest


Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj August 25th 2021, 11: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.
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by Guest August 25th 2021, 12:03 pm

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
avatar
Guest
Guest


Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by hbghlyj September 2nd 2021, 7: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
hbghlyj
hbghlyj
Forumember

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

View user profile https://cjhb.666forum.com/

Back to top Go down

Solved Re: remove-format button removes blockcodes

Post by SLGray September 2nd 2021, 7: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.
SLGray
SLGray
Administrator
Administrator

Male Posts : 50150
Reputation : 3457
Language : English
Location : United States

View user profile https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

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