How to display special characters in Imperavi Redactor? - special-characters

I'd like to find an easy way to insert special characters in Imperavi's redactor.
In Windows, users can insert a Greek letter such as ß with the keyboard shortcut Alt+225.
But is there a way to have a more user-friendly feature in Redactor to insert such characters, perhaps through a dedicated menu?

Finally found a way with a custom dropdown button :
buttonsCustom: {
greek: {
title: 'Special Characters',
dropdown: {
alpha: {title: 'α',callback: function(obj){obj.insertHtml('α');}},
beta: {title: 'β',callback: function(obj){obj.insertHtml('β');}}
}
}
}

Related

How to search for and highlight a substring in Codemirror 6?

I'm building a simple code editor to help children learn HTML. One feature I'm trying to add is that when users mouseover their rendered code (in an iframe), the corresponding HTML code in the editor is highlighted. So, for example, if a user mouses-over an image of kittens, the actual code, , would be highlighted in the editor.
Mousing-over the iframe to get the html source for that element is the easy part, which I've done (using document.elementFromPoint(e.clientX, e.clientY in the iframe itself, and posting that up to the parent) - so that's not the part I need help with. The part I can't figure out is how to search for and highlight that string of selected code in the code editor.
I'm using Codemirror 6 for this project, as it seems as it will give me the most flexibility to create such a feature. However, as a Codemirror 6 novice, I'm struggling with the documentation to find out where I should start. It seems like the steps I need to complete to accomplish this are:
Search for a range in the editor's text that matches a string (ie.'<img src="kittens.gif"').
Highlight that range in the editor.
Can anyone out there give me some advice as to where in the Codemirror 6 API I should look to start implementing this? It seems like it should be easy, but my unfamiliarity with the Codemirror API and the terse documentation is making this difficult.
1. Search for a range in the editor's text that matches a string (ie.'<img src="kittens.gif"').
You can use SearchCursor class (iterator) to get the character's range where is located the DOM element in your editor.
// the import for SearchCursor class
import {SearchCursor} from "#codemirror/search"
// your editor's view
let main_view = new EditorView({ /* your code */ });
// will create a cursor based on the doc content and the DOM element as a string (outerHTML)
let cursor = new SearchCursor(main_view.state.doc, element.outerHTML);
// will search the first match of the string element.outerHTML in the editor view main_view.state.doc
cursor.next()
// display the range where is located your DOM element in your editor
console.log(cursor.value);
2. Highlight that range in the editor.
As described in the migration documentation here, marked text is replace by decoration. To highlight a range in the editor with codemirror 6, you need to create one decoration and apply it in a dispatch on your view. This decoration need to be provide by an extension that you add in the extensions of your editor view.
// the import for the 3 new classes
import {StateEffect, StateField} from "#codemirror/state"
import {Decoration} from "#codemirror/view"
// code mirror effect that you will use to define the effect you want (the decoration)
const highlight_effect = StateEffect.define();
// define a new field that will be attached to your view state as an extension, update will be called at each editor's change
const highlight_extension = StateField.define({
create() { return Decoration.none },
update(value, transaction) {
value = value.map(transaction.changes)
for (let effect of transaction.effects) {
if (effect.is(highlight_effect)) value = value.update({add: effect.value, sort: true})
}
return value
},
provide: f => EditorView.decorations.from(f)
});
// this is your decoration where you can define the change you want : a css class or directly css attributes
const highlight_decoration = Decoration.mark({
// attributes: {style: "background-color: red"}
class: 'red_back'
});
// your editor's view
let main_view = new EditorView({
extensions: [highlight_extension]
});
// this is where the change takes effect by the dispatch. The of method instanciate the effect. You need to put this code where you want the change to take place
main_view.dispatch({
effects: highlight_effect.of([highlight_decoration.range(cursor.value.from, cursor.value.to)])
});
Hope it will help you to implement what you want ;)
Have a look at #codemirror/search.
Specifically, the source code implementation of Selection Matching may be of use for you to adapt.
It uses Decoration.mark over a range of text.
You can use SearchCursor to iterate over ranges that match your pattern (or RegExpCursor)
Use getSearchCursor, something like this:
var cursor = cmEditor.getSearchCursor(keyword , CodeMirror.Pos(cmEditor.firstLine(), 0), {caseFold: true, multiline: true});
if(cursor.find(false)){ //move to that position.
cmEditor.setSelection(cursor.from(), cursor.to());
cmEditor.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
}
Programmatically search and select a keyword
Take a look at getSearchCursor source code it it give some glow about how it works and its usage.
So use getSearchCursor for finding text and optionally use markText for highlighting text because you can mark text with setSelection method of editor.
Selection Marking Demo
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
styleSelectedText: true
});
editor.markText({line: 6, ch: 26}, {line: 6, ch: 42}, {className: "styled-background"});
And it seem this is what you are looking for:
codemirror: search and highlight multipule words without dialog
RegExpCursor is another option that you can use:
new RegExpCursor(
text: Text,
query: string,
options⁠?: {ignoreCase⁠?: boolean},
from⁠?: number = 0,
to⁠?: number = text.length
)
Sample usage at:
Replacing text between dollar signs for Mathml expression.

How do I define a custom snippet using VScode "Surround" extension

I'm using a VScode extension called "Surround"
In the docs for this extension it shows how to define a custom snippet. What I want is really simple. I would like to add the ability to surround selected text with tags, ie <> </> while placing the cursors in the middle where I define what type of tag that is (html, img, button, etc)
The docs show this example:
{
"surround.custom": {
// command name must be unique
"yourCommandName": {
// label must be unique
"label": "Your Snippet Label",
"description": "Your Snippet Description",
"snippet": "burrito { $TM_SELECTED_TEXT }$0", // <-- snippet goes here.
"languageIds": ["html", "javascript", "typescript", "markdown"]
},
// You can add more ...
}
}
I can almost parse it, except I don't know what the placeholders are representing. I assume { $TM_SELECTED_TEXT } is the text I've selected but what is the trailing $0 used for? Also, how can I place 2 cursors in between the opening and closing tags?
Thanks in advance.

Is there any way in VSCode to show/highlight characters passing a character limit for a line?

Is there any way in VSCode to show/highlight characters passing a character limit for a line such as 80 (possibly ignoring whitespace in the left side)? I sometimes use Vim, in Vim, there is a script for that. I have searched the VSCode Marketplace and have found nothing. I like to keep my code consistent.
The Highlight extension can do this. In your settings:
"highlight.regexes": {
"(\\s*)(.{80})(.*)": { // skip leading whitespace, skip next 80 characters
// "filterLanguageRegex": "javascriptreact",
"decorations": [
{}, // do nothing to first 2 capture groups
{},
{
// "outline": "green solid 2px",
"borderWidth": "0 0 2px 0",
"borderColor": "red",
"borderStyle": "solid"
},
]
}
},
For styling options see https://code.visualstudio.com/api/references/vscode-api#DecorationRenderOptions
This extension seems to do what you're looking for, however it doesn't seem to be very popular yet:
"codewall" on VS Code MarketPlace
GitHub Repository

AG-Grid - How to insert a line break into my cell data

I'm new to AG-Grid, so forgive me if this is a dumb question. We're using the OSS version of Ag-Grid in an Angular 5 application. I have a column where I am combining two sets of summary data and showing them. I would like to have a line-break between the two pieces of text.
Right now it's doing this:
"Summary One Summary Two"
I want it to do this:
"Summary One
Summary Two"
So far I've tried and HTML break tag, \r\n and just \n and nothing has worked. Is this possible to do?
Thanks,
James
You can use cellRenderer to achieve this.
Have a look at below colDef.
{
headerName: "Custom column",
cellRenderer: function(param){
return param.data.col1 + '<br/>' + param.data.col2;
}
}
You might need to set rowHeight in gridOptions as well.
Live example: Plunk
I have an even simpler solution without cell renderer. By the way I am using the ag-theme-balham theme. Simply set the cellStyle to white-space pre and you are able to use \n to insert a new line.
columnDefs()
...
valueGetter: ({ data }) => 'first value\nsecond value',
cellStyle: { 'white-space': 'pre' }

remove white box html tag trackers in VScode

how do I remove or disable the white box that tracks tag signs "<" and ">" ??
add this to your user settings:
"[html]": {
"editor.matchBrackets": false
}