CKeditor changes character "š" to "š" in source - ckeditor

For my site I am using CKeditor to add/edit content and I noticed when I write character š in source code it is changed to š - this causes problems when I do search in the database, so I am wondering how to fix this, so that that character will stay written in the source code the same way (not changed)?
I can fix this by adding this to config:
config.entities = false;
But with this, everything is disabled (even quotes, double quotes,... are now not changed in source), so this is not the best solution, right?
I also tried with those settings, but they don't help:
config.IncludeGreekEntities = false;
config.IncludeLatinEntities = false;
What else can I try? Is there any way to manually set that some characters should not be converted?

This command seems to work, I no longer have problems with š (other special chars are still converted - like quote, which is fine):
CKEDITOR.config.entities_latin = false;

If it causes an issue with your search implementation, it is not only a "š" character which will be an issue here but all special characters which may be used for search. I don't think CKEditor has a config to whitelist entities which should not be encoded.
I would suggest just decoding this characters after getting data from CKEditor, like:
var map = { 'š': 'š', 'à': 'à' };
editor.getData().replace( /š|à/g, function( m ) { return map[ m ] } );
----- EDIT:
To integrate it with CKEditor one may use toDataFormat event:
var editor = CKEDITOR.replace( 'editor1' ),
map = { 'š': 'š', 'à': 'à' };
editor.on( 'toDataFormat', function( evt ) {
evt.data.dataValue = evt.data.dataValue.replace( /š|à/g, function( m ) { return map[ m ] } );
}, null, null, 16 );
See working example on codepen.

Only had deleted "scaron" and "Scaron" from ckeditor.js source.

Related

Handsontable : one double quote is missing after Copy-paste or drag the value (two consecutive double quotes)

Requirement: I have a requirement to use Handsontable on my web application, where the user can enter value with two consecutive double-quotes
jsfiddle link:
sample strings:
${v=""}
var s=""
http://jsfiddle.net/a3uj6/1/
Handsontable Issue:
If the cell has Two consecutive double quotes, one double quote is missing upon copy-paste the cell to another cell.
Same issue occurs, if the user drags the cell-value to place it in the next column/cell.
NOTE: User is not doing copy/paste or dragging a multi-line text, it is just a single-line text with two consecutive quotes.
I have posted this as an issue in the github as well. Meanwhile, if there is any work-around to fix the copy/paste issue, is more welcomed.
Thanks.
this is a not elegant solution but is a workaround that works for me.
Using the hook onBeforePaste you could handle the contents pasted as follows:
onBeforePaste: (values, range) => {
const { startRow, startCol } = [range];
var content = [];
values.forEach((row, i) => {
row.forEach((value, x) => {
content.push([startRow + i, startCol + x, value]);
});
});
hotInstante.setDataAtCell(content);
return false;
},
There are the documentation of hooks used
https://handsontable.com/docs/8.1.0/Core.html#setDataAtCell
https://handsontable.com/docs/8.1.0/Hooks.html#event:beforePaste

Column Indentation Guide on Textmate

I'd like to know if there's a bundle or a preference somewhere in Textmate to get Sublime's white dotted column delimiter. Look at the screenshots.
Look at this PHP function in Textmate
(source: darwinsantos.com)
Now look at it in Sublime.
(source: darwinsantos.com)
If you take a close look notice that in Sublime the beginning and ending curly brace are bound by a white dotted line that let's you know that both curly braces are aligned in the exact same column.
Is there a way to get this in Textmate?
Update (5/2016): TextMate has gotten indent guides! As of version 2.0-beta.9.2 View->Show Indent Guides. They're a work in progress, but they are available.
Update: If you're able to get this working and are willing to build your own textmate via the official instructions, then you might have a crack a building (and maybe even contributing to) my fold guides enabled version of TextMate2. There are no builds, and it is not ready to be introduced into TextMate2 yet as it lacks a setting to disable the guides.
This is a feature in development, when complete it will be significantly more intelligent than what I'm about to describe. The new version, when it eventually comes out, will respect the indentation rules of the language, rather than simply filling in pairs of spaces/tabs.
That said, I've used this to ensure countless lines of templates are perfect.
The method is updated, but otherwise the same as described for Textmate1 by Cocabits.
You will end up with something like this:
Note the second to last line, lacking the white space to trigger the lines. The new version will be much closer to Sublime's
First we are going to need to teach TextMate how to identify the tabs and spaces which we use before each line of code.
I have created a fold guides bundle however this is the first time I've given it out and I am terrified it just won't work for you, that said give it a try.
If it doesn't work, you will need to manually add these rules, I will show you how to make it its own bundle, but you could add it directly to any language you like.
Create a bundle from Bundles->Edit Bundles, then, File->New, select bundle and give it a name, then File->New and make a grammar. The grammar should have this code:
{ patterns = (
{ include = '#leading-spaces'; },
{ name = 'meta.leading-tabs';
begin = '^(?=\t)';
end = '(?=[^\t])';
patterns = (
{ match = '(\t)(\t)?';
captures = {
1 = { name = 'meta.odd-tab'; };
2 = { name = 'meta.even-tab'; };
};
},
);
},
);
repository = {
leading-spaces = {
begin = '^(?=\s\s)';
end = '(?=[^\s\s])';
patterns = (
{ match = '(\s\s)(\s\s)?';
captures = {
1 = { name = 'meta.odd-tab'; };
2 = { name = 'meta.even-tab'; };
};
},
);
};
};
}
And the inspector should look like this:
Now we just need a theme rule to match 'meta.even-tab' and or 'meta.odd-tab', so just add this to your current theme:
{name = 'Alternating Tabs';
scope = 'meta.even-tab';
settings = {
background = '#232323';
};
}

Select hyphenated word with double-click

UPDATE: Per the recommendation below, here's specifically what I'd like to do: If I double-click the mouse cursor anywhere from the "b" to the "n" of "blue-green", I want all of the word "blue-green" should be highlighted. How can this be done? Currently, depending on where you click, it treats "blue-green" as three separate character strings. So, if you double click between the "b" and "e" of "blue" it highlights only "blue" and not "-green." If you double-click the hyphen, it highlights the hyphen alone. And if you double-click between the "g" and "n" of "green" it highlights only "green" and not "blue-".
ORIGINAL: When I double-click a hyphenated word or set of characters (e.g. "123-abc" or "blue-green" etc.), only the part of the word that I double-clicked is highlighted. I'd like the whole word to be highlighted.
I'm using Windows 7 Pro. If it needs to be done on a per-application basis, I'm most interested in fixing it for Google Chrome, but any Windows-compatible web browser would be OK.
Old question, but I happen to have been working on the same issue. Here's my solution:
jsFiddle.net
"use strict"
// Tweak to make a double-click select words with hyphens
//
// As of 2016-0816, None of the major Mac browser selects whole words
// with hyphens, like "ad-lib". This tweak fixes the hypen issue.
//
// Note: Firefox 48.0 doesn't automatically select whole words with
// apostrophes like "doesn't". This tweak also treats that.
;(function selectWholeWordsWithHyphens(){
var pOutput = document.getElementById("output")
var selection = window.getSelection()
// Regex designed to find a word+hyphen before the selected word.
// Example: ad-|lib|
// It finds the last chunk with no non-word characters (except for
// ' and -) before the first selected character.
var startRegex = /(\w+'?-?)+-$/g
// Regex designed to find a hyphen+word after the selected word.
// Example: |ad|-lib
var endRegex = /^-('?-?\w+)+/
// Edge case: check if the selection contains no word
// characters. If so, then don't do anything to extend it.
var edgeRegex = /\w/
document.body.ondblclick = selectHyphenatedWords
function selectHyphenatedWords(event) {
if (!selection.rangeCount) {
return
}
var range = selection.getRangeAt(0)
var container = range.startContainer
var string = container.textContent
var selectionUpdated = false
if (string.substring(range.startOffset, range.endOffset)
.search(edgeRegex) < 0) {
// There are no word characters selected
return
}
extendSelectionBackBeforeHypen(string, range.startOffset)
extendSelectionForwardAfterHyphen(string, range.endOffset)
if (selectionUpdated) {
selection.removeAllRanges()
selection.addRange(range)
}
function extendSelectionBackBeforeHypen(string, offset) {
var lastIndex = 0
var result
, index
string = string.substring(0, offset)
while (result = startRegex.exec(string)) {
index = result.index
lastIndex = startRegex.lastIndex
}
if (lastIndex === offset) {
range.setStart(container, index)
selectionUpdated = true
}
}
function extendSelectionForwardAfterHyphen(string, offset) {
if (!offset) {
return
}
string = string.substring(offset)
var result = endRegex.exec(string)
if (result) {
range.setEnd(container, offset + result[0].length)
selectionUpdated = true
}
}
}
})()
It's a standard through all programs that it will do that because they all run off the operating system's typing configuration/program thing. To fix it you would need to do something in System32. I don't know what you would need to do but I suspect this is your problem. You should probably go into more detail though about specifically what it is you want.

Broken toggle-comment in Textmate

I'm having a problem with the Toggle Comment command ("Comment Line / Selection") in TextMate for Actionscript 2 (I know, I know). I've tried completely stripping the language set down to isolate the issue, and tried walking through the Ruby, both to no avail. My issue is that the command insists on using block comments for comment toggling (⌘ + /) and doesn't respect when I add a preferences file to change TM_COMMENT_MODE. I even tried using this simple preference:
{ shellVariables = (
{ name = 'TM_COMMENT_START';
value = '// ';
},
);
}
but no luck. I'm hoping that someone who speaks Ruby much better than myself (ie. at all) can find a simple fix for this. You can reproduce in any (recent) install of TextMate by creating a new actionscript 2 file and trying to ⌘ + / a section of code (or even a line). Contrast to a JS file which will use a line comment. Copy the "Comments" snippet from JavaScript to Actionscript bundles, and the problem will persist.
Thanks!
In your ActionScript Bundle, add a Preference called "Comments". In the editor part, add:
{ shellVariables = (
{ name = 'TM_COMMENT_START';
value = '// ';
},
{ name = 'TM_COMMENT_DISABLE_INDENT';
value = 'YES';
},
{ name = 'TM_COMMENT_START_2';
value = '/* ';
},
{ name = 'TM_COMMENT_END_2';
value = '*/';
},
);
}
and finally at the bottom, set the scope selector to: scope.actionscript.2
Here is an image of what mine looks like
be sure to use the Reload Bundles menu item after you've made these changes.

CKEditor: How to stop angle brackets from converting to HTML entities

Our site is using tags like <# TAGNAME #> but CKEditor converts < and > to &lt and &gt which breaks these tags for use in our software.
I've discovered this option: config.protectedSource.push( /<#[\s\S]*##>/g ); which seems to stop the conversion if the data is saved from Source mode, but in WYSIWYG mode I can't find a way to stop the conversion. I've tried many options in their API but none of them seem to have helped, how can I fix this problem?
Were were looking at using CKEDitor to edit Smarty templates. The problem we were hitting was that it was replacing all the angle brackets and ampersands within the curly brackets, which messed everything up. This came up in a Google search so our solution should help anyone with similar issues.
CKEditor rebuilds the HTML every time you switch to Source mode and when you save, so you need to add to the HTML http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Data_Processor htmlFilter.
This worked for us:
//replace Form_content with whatever your editor's id is.
htmlParser = CKEDITOR.instances.Form_content.dataProcessor.htmlFilter;
//We don't want HTML encoding on smarty tags
//so we need to change things in curly brackets
htmlParser.onText = function(text) {
//find all bits in curly brackets
var matches = text.match(/\{([^}]+)\}/g);
//go through each match and replace the encoded characters
if (matches!=null) {
for (match in matches) {
var replacedString=matches[match];
replacedString = matches[match].replace(/>/g,'>');
replacedString = replacedString.replace(/</g,'<');
replacedString = replacedString.replace(/&/g,'&');
text = text.replace(matches[match],replacedString);
}
}
return text;
}
The onText function processes all the bits that aren't in tags or comments.
I'd imagine you can do something similar by altering the code above - I've left it as is as I think our problems and required solutions are very similar.
editor.on( 'mode', function(ev) {
if ( ev.editor.mode == 'source' ) {
var str=ev.editor.getData();
str=str.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, "\"");
ev.editor.textarea.setValue(str);
}
});
http://cksource.com/forums/viewtopic.php?f=11&t=20647&start=10
If you type < or > in any WYSIWYG editor, they will be converted to their HTML entities in source mode.

Resources