Inspired by cloning medium with parchment - quill

Did somebody tried this examples?
https://quilljs.com/guides/cloning-medium-with-parchment
I'm looking for an answer what the
static formats(node)
is used for. If it return's
null|undefined|false
than it seems that nothing is affected.

It returns the format represented by the Blot. For example for a header it might be implemented this way:
formats(domNode) {
if (domNode.tagName === 'H1') return 1;
if (domNode.tagName === 'H2') return 2;
if (domNode.tagName === 'H3') return 3;
return null;
}
You can find more details about Blots at https://github.com/quilljs/parchment. Also how Quill implements their formats might be helpful: https://github.com/quilljs/quill/tree/develop/formats.

Related

Loop for check text in column

I would like an example to check a column for "ok" text.
When text is found, I will give an instruction.
How can I do this?
Thanks
You should try to do a little more research before posting questions, but here is a basic formula that will do what you need.
function checkColumn(theRange,textToFind) {
for(var i=0;i<theRange.length;i++){
if(theRange[i].includes(textToFind)){
return true;
}
}
return false;
}

Break out of an anonymous function in kotlin

Created a test case to try and represent what I'm trying to do. I can't figure out how to "stop" continuing to do work inside of an anonymous function. In the example below I would like to break out of the "apple" section if the answer is correct. The code below doesn't compile because it says return#apple instead of return#banana which is the only valid option but I wrote it below to try and explain what I'm trying to achieve and better understand how to go about doing something like this.
class FunctionBreakingTest {
#Test fun stopInMiddleOfLambda() {
var answer = "wrong"
doStuff apple# {
doStuff banana# {
answer = "correct"
if (answer == "correct") {
return#apple
}
answer = "wrong"
}
answer = "wrong"
}
assertEquals("correct", answer)
}
private fun doStuff(foo: () -> Unit) = foo.invoke()
}
You need to make doStuff an inline function: non-local return is only supported for lambdas that are inlined.
private inline fun doStuff(foo: () -> Unit) = foo.invoke()
Then your test case passes.
Not only is return#apple illegal, just plain return is also illegal (because the non-local return requires inlining - See the answer by #hotkey, make doStuff inline and then it works)...
(Note that such non-local returns are supported only for lambda expressions passed to inline functions.)
This section of the Kotlin Documentation covers Returns at labels. Note: using anonymous functions instead of lambdas would allow you to eliminate the labels if you wanted (but, you only get local returns, and you would need to modify your code slightly).
#Test fun stopInMiddleOfLambda() {
var answer = "wrong"
doStuff(fun() {
doStuff(fun() {
answer = "correct"
if (answer == "correct") {
return
}
answer = "wrong"
})
if(answer != "wrong") {
return
}
answer = "wrong"
})
assertEquals("correct", answer)
}
...

Apply generic mask via filter?

I'm currently using ngMask to handle masking for user input. It works great, but, AFAIK, can only be used on input elements. I now need to mask this same data for display. For example, in a table, I would hope to display item.ssn = 123456789 as 123-45-6798.
What is the best way to do this? I understand I can make custom filters, but was wondering if there was a generic way to do this for all text. Like this if you could extend the ngMask functionality...
<td><span mask="999-99-9999">{{item.ssn}}</span></td>
or as a filter...
<td>{{item.ssn|filter:'999-99-9999'}}</td>
You need to implement a filter. You can rely on MaskService provided with ngMask:
angular.module('myModule').filter('mask', ['MaskService', function(MaskService) {
return function(text, mask) {
var result,
maskService = MaskService.create(),
if (!angular.isObject(mask)) {
mask = { mask: mask }
}
maskService.generateRegex(mask).then(function() {
result = maskService.getViewValue(text).withDivisors()
}
return result;
}
}])
Then:
<td>{{item.ssn | mask:'999-99-9999'}}</td>
Take a look at date filter. you pretty much need to implement the same but for strings. You can use source code for reference.
In the simplest case you can just use simple regex replace:
angular.module('myModule').filter('ssn', function() {
return function(text) {
return (""+text).replace(/(\d\d\d)(\d\d)(\d\d\d\d)/, '$1-$2-$3');
}
})
<td>{{item.ssn|ssn}}</td>
Works for me. Follow.
https://github.com/alairjt/displayMask
<span>{{'01234567890' | mask:'999.999.999-99'}}</span>
//012.345.678-90
Just use AngularJS
{{youdate | date : "dd.MM.y"}}
reference: https://docs.angularjs.org/api/ng/filter/date

Backbone.js: Best way to handle multiple nullable filter parameters

have the following function on my collection:
getFiltered: function (status, city) {
return this.filter(function (trainer) {
return ((status === null) ? trainer : trainer.get("TrainerStatusName") === status) &&
((city === null) ? trainer : trainer.get('City') === city);
});
}
What is is best way to deal with nullable params passed in i.e. if city it null then ignore filter/fetch all and if status is null then ignore filter/fetch all
The code above works, but curious about alternatives
Ok, first off, I'm a little confused by your question; the title says its about handling "nullable" parameters, but your code looks like it is dealing with "special case" parameters (specifically "all") ... except for the case of trainer being null, but I don't think that is even possible when iterating through a Backbone collection.
* * Edit * *
OP updated the question, so the above is no longer relevant. I've also updated my answer accordingly.
In any case, there's nothing at all wrong or unusual about your code; ternary operators are a standard way of handling one-off special cases. If you're looking for alternative ideas though, here's one that uses an extra function to DRY out (eliminate the duplication of) your code:
function matchesOrAll(expected, actual) {
return expected === null || expected === actual;
}
getFiltered: function (status, city) {
return this.filter(function (trainer) {
return matchesOrAll(status, trainer.get("TrainerStatusName") &&
matchesOrAll(city, trainer.get("City"));
}
* * Edit * *
Now that we're talking about null and not "all", it's worth pointing out that there is a better pattern for simpler cases of nulls/undefined. If you were just filtering cities, for instance, the code could just be:
getFiltered: function (expectedCity) {
return this.filter(function (currentCity) {
return expectedCity === (currentCity || expectedCity);
}
In other words, you could take advantage of Javascript's "truthiness", and the fact that disjunctive (ie. ||) booleans expressions return the first truthy value. This eliminates the need for a ternary, and many libraries use this pattern to fill in un-provided arguments; for instance, here's a line from jQuery that sets the "target" argument to a new object if none is provided:
target = arguments[1] || {};
Unfortunately though, when you're dealing with properties/attributes of things (eg. trainer.get('foo')) instead of just objects directly (eg. trainer), there's no good shortcut you can use (other than making a function).

Concise way to write decision tree with height 2 in C

I have a decision tree of height 2:
const BOOL isVerticalAnimationRequired = YES;
const BOOL isArgumentEditorExpanded = YES;
const BOOL isSelectionLeftToRight = YES;
UITableViewRowAnimation argumentEditorAnimation;
if (isVerticalAnimationRequired)
{
argumentEditorAnimation = (isArgumentEditorExpanded) ? UITableViewRowAnimationTop : UITableViewRowAnimationBottom;
}
else
{
argumentEditorAnimation = (isSelectionLeftToRight) ? UITableViewRowAnimationLeft : UITableViewRowAnimationRight;
}
My problem is that the code is verbose. Ideally I would like to declare and set argumentEditorAnimation in one statement.
Are there any clever C style tips for handling situation like this?
I think I would not try to fold this into one expression for reasons of clarity, but if you must:
argumentEditorAnimation =
isVerticalAnimationRequired ?
(isArgumentEditorExpanded ?
UITableViewRowAnimationTop
: UITableViewRowAnimationBottom)
: (isSelectionLeftToRight ?
UITableViewRowAnimationLeft
: UITableViewRowAnimationRight);
Alternatively, you can make your code more concise by dropping the {} when they're not needed.
(Consider using shorter identifiers if you want to write these kinds of expressions. The long identifiers make the code verbose as well. E.g., drop the is in your booleans.)
Sometimes logic like this can best be expressed with a small table that you index with your decision criteria.
In this case, I would just use good formatting as larsmans showed in his answer.

Resources