I am using Ace editor in my text area for highlighting. I have my own tokenizer without using regex. The tokenizer is in the server side and called using http call. Now what I wanted to do is to highlight every token I got from the server. I tried to use addMarker function to highlight every token but does not work. Sample code below,
highlightToken = function(token) {
var
aceRange = ace.require('ace/range').Range,
row = editor.selection.lead.row, // editor is my ace editor
adjAceRange = new aceRange(row, token.position - 1 , row, token.position + token.length),
styleClass = token.type;
editor.session.addMarker(adjAceRange, styleClass, "text", true);
}
In my css,
.styleClass {
position:absolute;
color: blue;}
The color of the token does not change. But if I add background property in the css, the background of the token is changed. Did I miss something?
Related
I'm attempting to add form fields to an existing PDF in a .NET 7.0.0 app using iText7 7.2.4 on Mac and I cannot get multiline text fields to honor wrapping without doing a weird hack.
The following code illustrates the issue:
using iText.Forms;
using iText.Forms.Fields;
using iText.IO.Font.Constants;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
// Create a new PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter("my_document.pdf"));
// Create a page and add it to the document
PdfPage page = pdf.AddNewPage();
// Create an AcroForm and add it to the document
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);
// Create a multiline text field that should wrap but does not.
PdfTextFormField nonWrapping = PdfFormField.CreateText
(pdf,
new Rectangle(25, 727, 100, 100),
"multiline-field-without-wrapping",
String.Concat(Enumerable.Repeat("Hello World ", 10)),
PdfFontFactory.CreateFont(StandardFonts.HELVETICA),
9.0F);
nonWrapping.SetMultiline(true);
form.AddField(nonWrapping);
// Create a multiline text field that DOES wrap but
// only because we set a background color.
PdfTextFormField wrapping = PdfFormField.CreateText
(pdf,
new Rectangle(150, 727, 100, 100),
"multiline-field-with-wrapping",
String.Concat(Enumerable.Repeat("Hello World ", 10)),
PdfFontFactory.CreateFont(StandardFonts.HELVETICA),
9.0F);
wrapping.SetMultiline(true);
wrapping.SetBackgroundColor(new DeviceRgb(0.9F, 0.9F, 0.99F));
form.AddField(wrapping);
// Close the document
pdf.Close();
It will result in a PDF that looks like this in Preview:
The only way I can get wrapping to work is by including background color. I don't want to do this but it's the only thing that works.
If I could set the opacity of the background color, that might also be acceptable but so far, I've been unable to find anything in the code or docs that would support this.
I have content that references Images by ID within a placeholder (e.g. "$m(12345)" ). I have a REST call that will return an img-tag for the placeholder.
I would like CKEditor to display the image when the content is opened in editor, or a placeholder is inserted. But I want the placeholder to remain in the content (including when switching to the Source view)
I've tried to do this by adding a rule to the dataFilter:
CKEDITOR.on('instanceLoaded', function(ckeditor){
var mediaPlaceholderRegex = /\$m\(.*\)/;
ckeditor.editor.dataProcessor.dataFilter.addRules({
text: function( text, node ) {
return text.replace( mediaPlaceholderRegex, function( match ) {
var params = "placeholder="+match;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url, false);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(params);
return xhttp.responseText;
} );
}
});
});
It does the job of replacing the placeholder with the image tag, but the img-tag is also there when switching to the source view.
Is there an easy way to only apply a filter to the wysiwyg view.
The only way I see is to add a htmlFilter that would revert the img-tag back to a placeholder.
Is there an easy way to only apply a filter to the wysiwyg view. The only way I see is to add a htmlFilter that would revert the img-tag back to a placeholder.
Good thinking. Either that of if you don't want your images to be removed/fetched from the server on every mode change, you can for example put your placeholder into the data- attribute for the image tag. It all depends on your use case but the bottom line is that dataFilter is used when you load data into the editor and htmlFilter when you get data from the editor (same methods are used when getting data and switching to source mode so htmlFilter applies here).
My online CMS (that now is using CKEditor v4.2.2) not supports <font face="Symbol">, so online edit tool must preserve the "purity" of the UTF-8 of the online editions.
The problem arises when a user copy/paste from a external text to the CKeditor box,
<p><font face="Symbol">• </font>blabla
<font face="Symbol">S</font> blabla;</p>
Can CKEditor transform these <font face="Symbol"> into "free UTF-8"? That is, can CKEditor save
<p>• blabla Σ blabla;</p>
There are some configuration to enforce only UTF8 characters, without font-symbol?
EDITED: my configurations for test contextualization,
CKEDITOR.on( 'instanceCreated', function( event ) { // contenteditable
var editor = event.editor;
// ...
editor.on( 'configLoaded', function() {
editor.config.skin = '...';
// ...
});
});
First of all, if you want to solve this, you need to find a dictionary of these characters which will allow you to translate original characters to their UTF-8 representation.
To apply this transformation to all font elements use the dataProcessor. The dataFilter is applied to all data loaded or inserted into editor.
editor.dataProcessor.dataFilter.addRules( {
elements: {
font: function( el ) {
// el will be an instance of CKEDITOR.htmlParser.element
// el.children[ 0 ] will be an instance of CKEDITOR.htmlParser.text
// You'll need to read a value of that text, replace
// all characters with their UTF-8 representatives
// and return:
return new CKEDITOR.htmlParser.text( text );
// That will replace font tags with returned text nodes.
}
}
} );
Here you can find more complex exampled of dataProcessor usage: http://ckeditor.com/forums/CKEditor/Create-new-dom-elements-using-dataProcessor.htmlFilter
I have a problem. I'd like to show CKEditor without toolbar, and still keep colors on it. This is my code.
$(document).ready(function() {
var textAreaName = 'description';
CKEDITOR.replace( textAreaName, {
removePlugins: 'toolbar,elementspath',
readOnly: true
} ) ;
var oCKeditor = CKEDITOR.instances[textAreaName];
});
The problem is text color doesn't show. It seems that CKEditor disable color as well.
Assuming (because it's still unclear) that you want to keep text color in editor's contents (BTW. editor's contents is not rendered using textarea - it is only used for easier data submitting) this is a solution:
config.extraAllowedContent = 'span{!color}';
This will allow span elements with color style. Read more about Advanced Content Filter.
use this config.uiColor = '#AADC6E';
Where config is object of that component.
Do you know how to add watermark in CKEditor (visual word processor)?
I want the behavior like this: When the CKEditor is loaded, it has text by default. When I click on it, text must disappear.
Below are the steps to add water mark in CKEditor
Generally when you set default text in Ck Editor through java script on page load. JavaScript event get fired before the control actually load so if possible set the text for code behind.
Attaching Events in Javascript for OnFocus and OnBlur
$(document).ready(function() {
var myeditor = CKEDITOR.instances['EditorId'];
myeditor.on("focus", function(e) {
RemoveDefaultText();
});
myeditor.on("blur", function(e) {
setDefaultText();
});
});
Define your default text in this function
function setDefaultText() {
if (CKEDITOR.instances['EditorId'].getData() == '') {
CKEDITOR.instances['EditorId'].setData('Your Message Here');
}
}
function RemoveDefaultText() {
if (CKEDITOR.instances['EditorId'].getData().indexOf('Your Mesage Here') >= 0) {
CKEDITOR.instances['EditorId'].setData('');
CKEDITOR.instances['EditorId'].focus();
}
}
You can also define styles to the water mark by adding classes to the default text and place the class into you ck editor content css otherwise it will not work
A ready to use plugin can be tested here. It allows to customize the default text and it takes into acount, dialogs as well as reading the data from an external script.
You might want to try this jQuery plugin:
https://github.com/antoineleclair/ckwatermark