Textarea line break after ';" character - textarea

I have a textarea with dynamically added css code.
I want the css to look clean and want to know if its possible to split the lines after every ";" character.
I currently have it like this
--------------------|
display: inline;color:
red; |
|
|
|
|
--------------------
And want it to be like this automatically
--------------------|
display: inline; |
color: red; |
|
|
|
|
--------------------
Is there a way I can do this with jQuery or Javascript?

// Using jQuery
var val = $('textarea').val();
$('textarea').val(val.replace(/;/g, ';\n'));
// Using plain javascript
var textarea = document.getElementsByTagName('textarea')[0];
textarea.value = textarea.value.replace(/;/g, ';\n');

If you have access to jQuery this should work;
So lets say you have a textarea:
<textarea id="myTextarea"></textarea>
You can wire up an onchange event handler to adjust the content.
$(document).ready(function(){
$('#myTextarea').change(function(){
var oldVal = this.value;
var contentSplitBySemiColons = oldVal.split(';');
var thisFragment;
for(var i=1;i<contentSplitBySemiColons.length;i++){
thisFragment = contentSplitBySemiColons[i];
if(thisFragment[0] != '\n'){
contentSplitBySemiColons[i] = '\n' + thisFragment;
}
}
this.value = contentSplitBySemiColons.join(';');
});
});
Here's a JSFiddle of it in action if you want to try it out. http://jsfiddle.net/jeLscdm5/4/

Related

Swift - Split text based on arabic combined characters

Dears,
I have arabic sentence like this stentence
أكل الولد التفاحة
how can i split the sentence based on UNCONNECTED characters to be like this :
أ-
كل
ا-
لو-
لد
ا-
لتفا-
حة
I put - to explain what i mean.
I just need to split the text into array based on that
How can i do that using swift code for ios ?
Update:
I dont care for the spaces.
"أكل" for example is one word and doesn't contain spaces.I want to split based on UNCONNECTED characters.
So "أكل" consist from two objects : "أ" and "كل"
الولد : three objects "ا" and "لو" and "لد"
Use the below code:
let a = "أكل الولد التفاحة".split(separator: " ")
You can replace spaces with "-" using replacing occurences function.
let text = "أكل الولد التفاحة".replacingOccurrences(of: " ", with: "-", options: NSString.CompareOptions.literal, range: nil) ?? ""
I don't know how accepted answer helps to fix the issue.
Apple already provided Natural Language Framework to handle such a things which more trustworthy
When you work with natural language text, it’s often useful to tokenize the text into individual words. Using NLTokenizer to enumerate words, rather than simply splitting components by whitespace, ensures correct behavior in multiple scripts and languages. For example, neither Chinese nor Japanese uses spaces to delimit words.
Here is example
let text = """
All human beings are born free and equal in dignity and rights.
They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.
"""
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = text
tokenizer.enumerateTokens(in: text.startIndex..<text.endIndex) { tokenRange, _ in
print(text[tokenRange])
return true
}
Here is link of Apple docs
Hope it is helpful
There is two box you can just click in first. Content automatically paste click convert. Output data automatically copied with spaces I used for this quran
<h1>Allah</h1>
<center>
<textarea id="field" onclick="paste(this)" style="font-size: xxx-large;min-width: 90%; min-height: 200px;"> </textarea>
<center>
</center>
</br>
<textarea id="field2" style="font-size: xxx-large;min-width: 95%; min-height: 200px;"> </textarea>
</center>
<center>
<br>
<button onclick="myFunction()" style="font-size: xx-large;min-width: 20%;">Convert</button>
</center>
<script >
function myFunction(){
var string = document.getElementById("field").value;
// Option 1
string.split('');
// Option 2
console.log(string);
// Option 3
Array.from(string);
// Option 4
var bb = Object.assign([], string);
console.log(bb);
cleanArray = bb.filter(function () { return true });
var filtered = bb.filter(function (el) {
return el != null; });
console.log(filtered);
var bb = bb.toString();
console.log(bb);
bb = bb.replace(",","");
var stringWithoutCommas = bb.replace(/,/g, ' ');
console.log(stringWithoutCommas);
document.execCommand(stringWithoutCommas)
document.getElementById("field2").value = stringWithoutCommas;
var copyTextarea = document.querySelector('#field2');
copyTextarea.focus();
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
};
/*
var copyTextareaBtn = document.querySelector('#newr');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('#field2');
copyTextarea.focus();
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
});
*/
async function paste(input) {
document.getElementById("field2").value = "";
const text = await navigator.clipboard.readText();
input.value = text;
}
</script>
Try this:
"أكل الولد التفاحة".map {String($0)}

using katex, '&' alignment symbol displays as 'amp;'

I am using katex to render math.
https://github.com/Khan/KaTeX
Generally, to get this to work I link to the files katex.min.js and katex.min.css from a cdn, which is one of the ways the directions suggest.
I wrap what needs to be rendered in tags and give all the same class. For example:
<span class='math'>\begin{bmatrix}a & b \\c & d\end{bmatrix}</span>
And inside a script tag I apply the following:
var math = document.getElementsByClassName('math');
for (var i = 0; i < math.length; i++) {
katex.render(math[i].innerHTML, math[i]);
}
So, my implementation works but there is a problem in what katex returns. The output of the above gives me:
This exact same question is asked here:
https://github.com/j13z/reveal.js-math-katex-plugin/issues/2
But I can't understand any of it.
The solution is to use element.textContent, not element.innerHTML.
If I use a form like what follows, the matrix will be rendered properly.
var math = document.getElementsByClassName('math');
for (var i = 0; i < math.length; i++) {
katex.render(math[i].textContent, math[i]); // <--element.textContent
}
A solution that works for me is the following (it is more of a hack rather than a fix):
<script type="text/javascript">
//first we define a function
function replaceAmp(str,replaceWhat,replaceTo){
replaceWhat = replaceWhat.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var re = new RegExp(replaceWhat, 'g');
return str.replace(re,replaceTo);
}
//next we use this function to replace all occurences of 'amp;' with ""
var katexText = $(this).html();
var html = katex.renderToString(String.raw``+katexText+``, {
throwOnError: false
});
//hack to fix amp; error
var amp = '<span class="mord mathdefault">a</span><span class="mord mathdefault">m</span><span class="mord mathdefault">p</span><span class="mpunct">;</span>';
var html = replaceAmp(html, amp, "");
</script>
function convert(input) {
var input = input.replace(/amp;/g, '&'); //Find all 'amp;' and replace with '&'
input=input.replace(/&&/g, '&'); //Find all '&&' and replace with '&'. For leveling 10&x+ &3&y+&125&z = 34232
var html = katex.renderToString(input, {
throwOnError: false});
return html
}
Which version are you using?
Edit the src/utils.js and comment line number 51 to 55 after updated run in terminal npm run build command.

How do I get the ASP.Net MVC Password HTML Helper to show characters as I type?

I'm using the Password HTML Helper in MVC5 to hide the social security number as it is entered.
#Html.Password("s", null, new { #maxlength = 9, autocomplete = "off" })
The problem I see with it is you just see dots as you type. Is there any way the helper behavior can be modified to show the characters you are typing in for a second or two then have them transformed to dots? That behavior would let the user confirm they are typing in the correct character. If the helper behavior cannot be modified is there another way to accomplish this?
I found this fiddle maybe you can use this as an option
http://jsfiddle.net/Ngtp7/
$(function(){
$(".showpassword").each(function(index,input) {
var $input = $(input);
$('<label class="showpasswordlabel"/>').append(
$("<input type='checkbox' class='showpasswordcheckbox' />").click(function() {
var change = $(this).is(":checked") ? "text" : "password";
var rep = $("<input type='" + change + "' />")
.attr("id", $input.attr("id"))
.attr("name", $input.attr("name"))
.attr('class', $input.attr('class'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
})
).append($("<span/>").text("Show password")).insertAfter($input);
});
});

Invalid charset on $_POST

I'm with a problem about the charset of the $_POST. When I submited a form, case the string inserted on the InputText haved a special character or a accent, the value of this input on the $_POST array is corrupted with invalid characters.
Exemple:
I inserted on the input: "pão"
The $_POST show me: Array ( [input] => pão)
I'm using the CodeIgniter Framework with ISO-8859-1 charset. To improve my test, I used a mb_detect_encoding() and this function returned utf-8. :\
Below the code of important parts:
/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
*/
$config['charset'] = "iso-8859-1";
/*
|--------------------------------------------------------------------------
| Default Language
|--------------------------------------------------------------------------
|
| This determines which set of language files should be used. Make sure
| there is an available translation if you intend to use something other
| than english.
|
*/
$config['language'] = "portugues";
$db['default']['char_set'] = "latin1";
$db['default']['dbcollat'] = "latin1_swedish_ci";
Form that was submited:
<form action="HTTP://localhost/portalsibe/index.php/grupos/cadastro" id="form" accept-charset="utf8" method="POST" name="frmPadrao" target="" enctype="multipart/form-data">
Try this solution, insert this jquery function in your script:
Font
Credits:
Javier Poo, WeLinux S.A.
Oficina: 02-372.97.70, Celular:84039925
Bombero Ossa # 1010, Santiago
www.welinux.cl
jQuery.fn.extend({
param: function( a ) {
var s = [];
// If an array was passed in, assume that it is an array
// of form elements
if ( a.constructor == Array || a.jquery ){
// Serialize the form elements
jQuery.each( a, function(){
s.push(unescape(encodeURIComponent(escape(this.name))) + "=" + unescape(encodeURIComponent(escape(this.value))));
});
}
// Otherwise, assume that it's an object of key/value pairs
else{
// Serialize the key/values
for ( var j in a )
// If the value is an array then the key names need to be repeated
if ( a[j] && a[j].constructor == Array )
jQuery.each( a[j], function(){
s.push(unescape(encodeURIComponent(escape(j)) + "=" + encodeURIComponent(escape(this))));
});
else
s.push(unescape(encodeURIComponent(escape(j)) + "=" + encodeURIComponent(escape(a[j]))));
}
// Return the resulting serialization
return s.join("&").replace(/ /g, "+");
},
serialize: function() {
return this.param(this.serializeArray());
}
});
Can you change everything to utf8? Including database?
If yes, change all files, and set MySQL database (and tables) to utf8_general_ci. If you are using notepad++ to develop, go to Encoding > Encode in UTF-8 (em português Formatar > Codificação em UTF-8).
Try not to use ISO-8859-1 as character encoding.
Then you need to "transform" all your files and database do ISO-8859-1. Don't forget to add in your PHP/HTML files, the encoding.
For example, in HTML4: <meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1"> and HTML5: <meta charset="ISO-8859-1">
Also, try to change teh enctype in your <form> tag to application/x-www-form-urlencoded and see if it works.

TinyMCE Paragraph Text Only but with some buttons like bold, italics

For my website I need the input passed from TinyMCE to be 1 specific font.
I need them to be able to insert links, make text bold, underlined or italics. They get to have 2 headers to chose from, Header 2 and Header 3 and paragraph.
Now the problem is, I can't make the editor paste as text. If I open word I can copy and paste text with font, lets say, Chiller and it shows up as chiller.
How can I make all copy/pasted text show as my desired font (paragraph format) while allowing some buttons to work such as bold..etc.
What I currently have:
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
editor_selector : "body_content",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align: "left",
theme_advanced_buttons1: "bold,italic,underline,hr,strikethrough,formatselect,separator,undo,redo",
theme_advanced_buttons2: "justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink",
theme_advanced_buttons3: "",
theme_advanced_blockformats: "p,h2,h3",
extended_valid_elements: "iframe[title|width|height|src]",
theme_advanced_fonts : "Arial=arial",
plugins : "wordcount",
setup : function(ed){
ed.onKeyUp.add(function(ed){
///
var r = 0;
var y = tinyMCE.get('body_content').getContent();
var n = "<?php echo $max;?>";
y = y.replace(/\s/g,' ');
y = y.split(' ');
for (i=0; i<y.length; i++)
{
if (y[i].length > 0) r++;
}
var word_remain=n-r;
if(word_remain<0)
word_remain=0;
jQuery('#body_word_remain').html(word_remain);
var keypressed = null;
if (window.event)
{
keypressed = window.event.keyCode;
}
else
{
keypressed = ed.which; //NON-IE, Standard
}
if (r > n )
{
var prescribed = "<?php _e('You have exceeded the prescribed ','ad')?>";
prescribed += (r-n);
prescribed += "<?php _e(' word(s)','ad');?>";
jQuery('#prescribed').html(prescribed);
}
else
{
jQuery('#prescribed').html('');
}
});
}
});
</script>
The example here works the way I want it to:
http://fiddle.tinymce.com/
But I am not sure what they have used to achieve that effect. I am using a version 3.9.3 released on 2010-12-20 and I'd rather not update it if possible. But if I do need to update it to get my desired effect I will.
Thank you! Any help is appreciated.

Resources