TinyMCE- Get plain text - tinymce

In tinyMCE, Is there any way to get the plain text instead of HTML text?

Try this:
var myText = tinyMCE.activeEditor.selection.getContent({ format: 'text' });

var rawtext = tinyMCE.activeEditor.getBody().textContent;

I just tried this approach:
editor.getContent()
.replace(/<[^>]*>/ig, ' ')
.replace(/<\/[^>]*>/ig, ' ')
.replace(/ | /gi, ' ')
.replace(/\s+/ig, ' ')
.trim();
Replaces both opening and closing html tags with space
Replaces various known special characters with space (add yours as well)
Replaces multiple spaces with a single space
Worked reasonably well, but it is obviously not perfect. I need only an approximation of plain text for purposes of word counting, so I am willing to ignore corner cases such as having part of the word bold or italic (replacement above for <b>a</b><i>x</i> will produce two separate words a b instead of ab).
It is an extension of Regular expression to remove HTML tags from a string
Hope that helps.

Related

How to remove whitespace in typeahed

I'm working on a typeahead search in flutter and let's say the user searches for bengali biriyani and return some names based on those two typed in words.
I'm splitting the search query like below:
List<String> searchWordList = search.toLowerCase().split(' ');
So List searchWordList is suppose to have ['Bengali','Biriyani']. But once I typed in bengali and put in a space the list(I'm printing the list on every turn) becomes something like this:
['Bengali', ' ']
It gets fixed as soon as I start typing something else but this should not happen.
Here are the visual presentation of the problem:
I'm guessing split() is not the way to go in this cases. But if so what can I do to mitigate this issue?
You can use trim() to remove the extra whitespace:
List<String> searchWordList = search.trim().toLowerCase().split(' ');

Hide certain characters in a text field in Flutter

I have a text field which I need to style for example with bold or italics parts.
I tried overridding the TextEditingController's buildTextSpan and formatting the text using annotation ranges with custom styles but the edge cases were too much and I really couldn't get it to work.
So, thought about using a formatter where before every change in format I'll add a custom character, like this:
This text is |bBOLD and this is |iITALICS. Would get me this:
This text is BOLD and this is ITALICS. So I override the buildTextSpan to build the TextSpan from a parse function where I split the text by the special characters and check the initial letter of each text for formatting info.
This works well except for the fact that when I press the right arrow to go the next character after the "This text is ", the cursor will stay fixed as it thinks there are two characters but being only for formatting, they aren't there on the render.
Is there any way I could tell the textfield to ignore certain characters when selecting, moving selection or typing?
I think this would work!
static const kCharToBEIgnored = 0x2C;
// Here 0x2C means ',' comma
// For complete list visit https://api.flutter.dev/flutter/charcode/charcode-library.html
String get text {
return String.fromCharCodes(
_value.text.codeUnits.where((ch) => ch != kCharToBEIgnored),
);
}

Horizontal line on the console?

I want to print a horizontal line to the console. At the moment, I use -----, but there are small spaces between the single characters.
Is there a better character I might use?
_ is not a viable option, as it is not vertically centered. Is there something like a middlescore, strikethrough (or whatever it's name is) character?
Hyphen ---------------------
Underscore _____________________
EM Dash —————————————————————
Horizontal Bar ―――――――――――――――――――――
Horizontal Box ─────────────────────
There is a big list of characters to try over at wikipedia.
The horizontal box drawing character is my recommendation. It is designed for this purpose
With bash, to display a horizontal rule the size of your window you can use:
printf %"$COLUMNS"s | tr " " "-"
With zsh, you could avoid the tr:
printf '—%.0s' {1..$COLUMNS}
NOTE: I know this is not what OP wants, but it is what I think someone from Google could be seeking.
Unicode character \u2500 solved it for me. According to Wikipedia it is for box drawings light horizontal, which is exactly what I need :-)
Thanks #Gusdor for pointing me to the correct Wikipedia article!
I believe that extended ASCII character #196 can serve your purpose:
See http://www.asciitable.com/
It seems like a vertically-centered non-gap line.
―/― is a horizontal bar character ―
Works for me in terminal.
If you're using Windows, open RUN, type charmap and hit enter.
There are a plenty of characters listed there with previews and names. I'm sure you'll find what you're looking for in charmap.
Update
If you're using a Linux Distribution, check this out.
if working on node js
const line = '#'.repeat(process.stdout.columns || 100);
console.log(line)
function and in Typescript
function consoleLine(mainChar:string, fallbackNum:number):string {
const line = (toRepeat:string) => toRepeat?.repeat(process.stdout?.columns || fallbackNum)
const mainLine = line(mainChar);
const emptyLine = line(' ');
return `${mainLine}\n${emptyLine}\n${mainLine}`;
};
console.log(consoleLine('#', 100));
print a dotted line the width of the console
print('-'*80)

Org-Mode Inline Code with Equals Signs

In org-mode, I want to give inline code with equals signs and quotation marks:
<div class="foo">
The way I would normally do this in org-mode is
=<div class="foo">=
When I export this to HTML, it gets rendered like this:
<div class"foo">=
What is the right way to do this inline (rather than just creating a source block)?
You could use verbatim markers, ~, instead:
~<div class="foo">~
The problem is that the equals sign after 'class' is interpreted as the closing code section delimiter. You can prevent this by inserting a space before the equals sign, like this:
=<div class = "foo">=
I wanted org-mode's source code to appear correctly in Github's parser. But, just as =:echo "hello"= would not appear correctly in Emacs, it also did not appear correctly in Github. However, I tried other characters with C-x 8 RET, and the LEFT DOUBLE QUOTATION MARK and RIGHT DOUBLE QUOTATION MARK work. That is,
=:echo “hello“=
appear successfully as
:echo “hello“
Unfortunately, I don't think they will actually work if copy-and-pasted into all environments. Vim gives E15: Invalid expression: “hello“. But then, how often do we paste commands into Vim's command line. Well, okay, there is :#".
After almost a decade, here's the correct answer:
Org's escape character is zero width space. When this character is inserted, Emacs will not interpret = as the end of the verbatim. Emacs can correctly interpret =<div class​="foo">=. Note that this string has an invisible zero width space character.
However, I think due to a bug, exports from org to other formats, will have this character and need to be removed manually. For example, the export of the string above to markdown will be `<div class​="foo">` which is what we want, except that it has an additional zero width space character.
It is not very hard to fix this. Removing all these additional characters can be easily done with replace-string command.
Tip: You can use C-x 8 RET (or insert-char command) and choose 200B to insert zero width space character inside Emacs.

Multi-line button labels

Is there an easy way to have two lines of button.text where you specify each line individually? Also, there seem to be large margins on the buttons so the text font needs to be quite small to fit. Is there a way to allow the text to use more of the button area?
The way I would do a two-line text implementation is:
Dim t1,t2 As String
t1="This is line one"
t2="This is line two"
...
MyButton.Text = t1 & CRLF & t2
The CRLF performs a Carriage Return and Line feed thus splitting the text up
I can't help with the padding issue though. Have you tried changing the font size?
MyButton.TextSize=9