Why do I get these warnings for my Vega specification? - warnings

Open the Chart in the Vega Editor
The Vega Editor produces very strange warnings for my Vega spec (see them with ALT+F8).
In a mark, it highlights "type": "text" and says 'Value is not accepted. Valid values: "group".'
In encode, it highlights "baseline": {"value": "line-bottom"} and says 'Value is not accepted. Valid values: "top", "middle", "bottom", "alphabetic".'
The line-top and line-bottom baselines were added in 5.10 according to https://vega.github.io/vega/docs/marks/text/

The Vega editor warnings about "line-bottom" is because Vega schema definition has not been updated properly to match Vega documentation for text "baseline" to include "line-top" and "line-bottom".

It seems like a validation bug. line-bottom is causing the other errors. If you change it to bottom they go away. I'll raise a bug on github.

Related

correct way to line break in json [duplicate]

This question already has an answer here:
In Angular, why doesn't line breaks affect the HTML?
(1 answer)
Closed 3 years ago.
I am not able to do a line break on \r\n with the following payload on this screen.
I am trying to find out the correct json playload, I should send to the frontend so that it's interpreted as line break.
{"allEvents": [{"data": [{"PSCPowerCableFailure": {"error_name": "patient_cart_running_on_battrey", "steps": {"1": {"step_body": {"step_link": {"type": "image", "url": "../../assets/patient-cart-running-on-battery_step_1.png"}}, "step_body_header": "Reconnect power cable to power outlet.", "step_body_text": "Confirm error is cleared on Vision Cart touchscreen. \r\nSwipe to the next troubleshooting screen if message does not clear.", "step_title": "Patient Cart Running on Battery"}, "2": {"step_body": {"step_link": {"type": "image", "url": "../../assets/patient-cart-running-on-battery_step_2.png"}}, "step_body_header": "Check circuit breaker on back of Patient Cart. Ensure that it is set to the ON (I) position.", "step_body_text": "Swipe to the next troubleshooting step if message does not clear.", "step_title": "Patient Cart Running on Battery"}, "3": {"step_body": {"step_link": {"type": "image", "url": "../../assets/exclamation-blue-circle-icon.png"}}, "step_body_header": "Call dVSTAT at 1.800.XXX.XXXX for additional assistance if required. \r\n A representative can guide you through additional troubleshooting procedures.", "step_body_text": "System Information:\r\n System Name: XXXXXX\r\n Software Version: P8d", "step_title": "Patient Cart Running on Battery"}}}, "arm_number": null, "error_display_name": "Patient Cart Running on Battrey", "error_id": "PSCPowerCableFailure", "error_name": "patient_cart_running_on_battrey", "priority": 0, "show_default": "false"}], "error_content_id": "PSCPowerCableFailure", "type": "error_occurred"}]}
Since you are using angular, you most likely download your json and bind the resulting values to some template.
There are two ways to achieve line breaks then. You can either set linebreaks via HTML <br> tag and bind the attribute to an innerHTML of an element like this:
<div [innerHTML]="retreivedJson.attributeContainingHTML"></div>
In this case you might need to use Sanitizer.bypassSecurityTrustHtml() on that attribute beforehand. An easy way to do that is to use a pipe like explained here.
Or you can send normal linebreaks with \n, in which case the element you are rendering it in needs to be a <pre> or have CSS rule white-space: pre; applied:
<pre>{{retreivedJson.attributeContainingWhitespaces}}</pre>
<!-- or -->
<div style="white-space: pre">{{retreivedJson.attributeContainingWhitespaces}}</div>
Here a Stackblitz showcasing all examples.
HTML is what's being rendered. If you want an HTML line break, you need to use an HTML tag, i.e., <br>.
If you're using a framework (e.g., Angular or Ionic), you might need to ensure your HTML tags aren't being escaped.

MarkLogic XPath on JSON with "#" symbol in property name

I am dealing with some JSON-LD data in MarkLogic and have trouble using XPath on property names with "#" symbol. For example:
{
"#type": "News",
"title": "some title",
"description": "some description"
}
My goal is to retrieve the title if the type is "News". I understand "#" is reserved to represent attribute in XPath, so something below should not work.
doc.xpath('.[#type="News"]/title')
With the xdmp.encodeForNCName function, I see the "#" symbol is represented as _40_ in the JSON representation. But it still doesn't work.
doc.xpath('.[_40_type="News"]/title')
While using fn:name() would work too, as suggested by the other answers, you can address nodes with funny spelling in MarkLogic XPath directly too. Probably a deviation from the official XPath standard itself, but MarkLogic allows writing expressions like:
doc.xpath('node("#type")[. eq "News"]/title'
Very useful for JSON properties containing spaces and such as well..
HTH!
You could test the name() in a predicate:
doc.xpath('.[*[contains(name(), "#type")] = "News"]/title')
Here is the dirty solution.
.[#*[name() = '#type']][#*='News']/title
I know you are working with json, but I just checked the xpath in html with similar attribute and value combination. You can see the xpath considered both attribute name and value (as it's not selecting other node with the same name but different value).

How to force prettier html formatting to format tags in one line?

I use prettier in my VSC, so how to force prettier HTML formatting to format tags in one line, not multiple lines?
I want to format something like this all in one line
<v-navigation-drawer :clipped="$vuetify.breakpoint.lgAndUp" v-model="drawer" fixed app>
Does exist any config for prettier HTML formatter?
Prettier has the option printWidth. If you set that option to a high number, it will break fewer lines.
In your .prettierrc.json file, you can override this option for your HTML files:
{
// Other options...
"overrides": [
{
// change .html with .vue if you are using Vue files instead of HTML
"files": "src/**/*.html",
"options": {
"printWidth": 140
}
}
]
}
Is not recommendable to use a line-lenght higher than 140. Prettier is opitionated, so it should be used without too many customizations.
First check if you have a filename .prettierrc in the root. If no, create it and then put these values in it.
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"printWidth": 3000,
"bracketSpacing": true
}
Set printWidth to something large value and toggle wrapping text with your editor whenever you want; for example, in VS Code: Alt+Z.
I know this topic is old but maybe others still have this issue. In the Prettier setting you can adjust the width of the Print Width. 120 width does the job for me.
It depends on your IDE settings but as documentation states, you should have a config file where you should look for the html.format.wrapLineLength property and apply the line length value which satisfy you. This will prevent Prettier to break your lines until assigned line length to the property is reached. This will only apply for HTML.
For overall purposes you should use prettier.printWidth property which
Fit code within this line limit
Mind that tabulation / indention spaces also count in the line length.
Unfortunately when code line exceed the above numbers it will be spited to multi-lines, each property per line. So far I did not find solution to just wrap to extra line, without spiting to multi.
UPDATE
Mentioned and desired by me behavior it is not affordable with Prettier, but the line length trick still can do the job ... partially.

How can I get gg=G in vim to ignore a comma?

I have autoindent and smartindent in vim turned on, but nocindent turned off. I'm trying to indent some JSON text without pretty-printing the whole thing, which would be too intrusive:
{
"a" : "value1",
"b": "value2",
"c": "value3",
...
Gets formatted by gg=G as:
{
"a" : "value1",
"b": "value2",
"c": "value3",
...
What's the logic going on there, and what options can I set to fix it, if it's possible? I tried toggling options like autoindent, smartindent, and cindent (with their "no" counterparts), but it doesn't have an effect on the = command. My latest attempt had these options:
autoindent
smartindent
nocindent
cinoptions=
indentexpr=
indentkeys=0{,0},:,0#,!^F,o,O,e
I can explain the logic, but I'm not sure of an easy fix. Vim's internal indenter is following C-style syntax, so since the "a" : "value1", line doesn't end with a ; it assumes that the following lines are a continuation of that statement and they should be indented to show that.
:help C-indenting goes into great depth discussing the various indent options and how they interact. I skimmed it and nothing jumped out at me, but it's worth a read.
If you have an external formatter that better recognizes the structure of your code, you can always set equalprg to run that instead of using the internal formatter.
Edit: On second thought, set cinoptions+=+0 will disable indenting for line continuation. This will also affect regular code, but it might be a reasonable tradeoff depending which annoys you more. You can also set it per filetype if you're editing standalone .json files.
The built-in indent settings won't totally cover a complex, non-C language like JSON. Better use a tailored indent setting, like the indent/json.vim indent plugin that is part of vim-json.

quick formatting shortcut sublime text

I was wondering if someone had the sequence of steps to accomplish this task, inline, without copy and pasting.
Imagine you have a block of code where things are not cleanly justified
{
foo: "foo value",
bar: "bar value",
reallylongvariable: "reallylongvariable value",
shortname: "shortname value"
}
is there a very quick way to transform it in this, justifying the spaces and ragged spacing to a unified formatting
{
foo: "foo value",
bar: "bar value",
reallylongvariable: "reallylongvariable value",
shortname: "shortname value"
}
I know about option selection. Generally, I follow these steps
option select a column,
paste it on a new set of lines,
reselect pasted content
use command + [ to remove indention,
option reselect column of unindented content
past back in place in the original column.
But this process feels very manual, and was wonder if there was way to clean up the indentation inline, without copy and paste. Perhaps a helper utility that can do this automatically within a highlighted selection.
Hopefully my question makes sense.
There are multiple plugins for this task, for example:
https://github.com/wbond/sublime_alignment
https://github.com/randy3k/AlignTab
Here you can search for all of them: https://sublime.wbond.net/search/align
I personally recommend the AlignTab. It may seem complex, but if you know how to use regular expressions it is the most powerful you will find. It may do some crazy magic if you get used to it.