What is the VS Code TextMate syntax for JSON inside an HTML attribute - vscode-extensions

I would like to add a grammar rule similar to the one found here. What that rule does is enable VSCode's JSON editor when it encounters an html file with
<script type="application/json">#Edit JSON</script>
What I would like is the same JSON editor support whenever it encounters a html attribute in this form:
<my-chart data='{"hello": "world"}'></my-chart>
In other words, any attribute that uses single quotes, inside of which it starts with a { and ends with a }, or starts with a [ and ends with a ].
Any suggestions what that should look like?

I've basically found a way. WIP

Related

In Docusaurus, is there can I preserve capitalization in anchors created from headings in docs?

I'm using Docusaurus to publish documentation for an open source library's API. The headings of my source markdown files correspond to the names of methods and properties for classes in the library. This all works fine.
However, the anchors that are created in the HTML are all lowercase. I want them to respect the capitalization used in the markdown file.
For example, this markdown header:
###.doSomething()
Generates the following HTML:
<h3>
<a aria-hidden="true" tabindex="-1" class="..." id="dosomething"></a>.
<code>.doSomething()</code>
<a class="..." href="#dosomething" title="...">#</a>
</h3>
As you can see, camelCase is transformed to lowercase. I would like to keep capitalization intact. Is it possible?
P.S. The markdown files are automatically generated from jsdoc comments. In jsdoc, links to a method or properties include capitalization.
TL;DR
Inside your project, navigate to the directory node_modules > github-slugger;
Open the index.js file;
Remove the line if (!maintainCase) string = string.toLowerCase()
The function will become something like this:
function slugger (string, maintainCase) {
if (typeof string !== 'string') return ''
// if (!maintainCase) string = string.toLowerCase() <-- remove this!
return string.trim()
.replace(specials, '')
.replace(emoji(), '')
.replace(whitespace, '-')
}
IMPORTANT!
If you update the docusaurus, you may need to apply this change again;
It may be necessary to edit the doc to see the changes, because of cache. Here I edited the doc file and it worked;
You must restart the docusaurus service after you make this change. And probably needs to clear the cache with npm cache clear --force;
Also, I think you should delete the folder .docusaurus to force the rebuild of all documents.
RESULT
The .md file:
---
id: intro
---
# Random title
### WriNTinG with CaSeS
test 1
### .doAnotherThink()
test 3
### .doCamelCaseWithSeveralLETTERS()
test 3
ROADMAP
I must say that this one was hard. First I tried to track down the anchor tags, then the description. Eventually I found about the github-slugger, and looked like that was the way.
But once I made the changes, nothing had happened to the document! So after hours trying, I gave up… Then, just for curiosity, I decide to see what the slug function did to the document, by adding a second header with the same name. And — luck! — it kept the original case.
It turns out that you can simply use explicit IDs to solve this issue: https://docusaurus.io/docs/next/markdown-features/headings#explicit-ids

Go template is adding extra quotes to output

I want to use the value of my variable in Go template as-is but Go is adding extra quotes around it. E.g., for a Go template like
{{.Site}}:{{.Port}}/{{.Path}}
I want to get the output as
Mysite:3000/from/here
but the template is giving me the following instead:
"Mysite":"3000"/"from/here"
So,
How can I fix it (get rid of all the extra quotes or better suspend them all)? See https://play.golang.org/p/uKpgXdLv5gM
Go template also changed "orgId=1&refresh=30s" to orgId=1\u0026refresh=30s, how to avoid that?
Moreover, if I add https:// to the front of my url, the output is truncated. How to fix that as well?
Finally, is it possible to escape "`" within "`"?
As per Go HTML template doc:
HTML templates treat data values as plain text which should be encoded so they can be safely embedded in an HTML document. The escaping is contextual, so actions can appear within JavaScript, CSS, and URI contexts.
The security model used by this package assumes that template authors are trusted, while Execute's data parameter is not. More details are provided below.
It means JavaScript escaping is enabled whenever the go HTML template engine detects that it is within a <script> tag, (i.e., it has nothing to do with whether using regular " or not as the first commenter thinks). So
to get the output as
Mysite:3000/from/here
instead of:
"Mysite":"3000"/"from/here"
Do not wrap it with <script> & </script> tag.
Do the concatenation after template Execute().
Again, with <script> & </script> tag wrapped around, I'm getting:
var url = `"Mysite":"3000"/"from/here"/${othervars}?"orgId=1\u0026refresh=30s"`
vs. without <script> & </script> tag wrapped around it, I'm getting:
var url = `Mysite:3000/from/here/${othervars}?orgId=1&refresh=30s`
Just what I need.
However, my actual case is that I'm using go HTML template engine to process my .html template files, so I cannot really do the concatenation afterwards, as everything is defined in the .html template file. So, just as Martin Gallagher has shown in his code, for such case, using template function seems to be the only option.
But even that might not be a viable option, as this is what I'm getting out of Martin's code:
var url = "Mysite:3000\/from\/here?orgId=1\u0026refresh=30s"
It is still not exactly what I wanted:
var url = `Mysite:3000/from/here/${othervars}?orgId=1&refresh=30s`
So maybe with such case, it indeed has no ideal solution.

funcList Visual Studio Code regex for custom language

I'm trying to get the funcList visual studio code extension plugin to work with a proprietary language that I use and I'm having a problem getting the regex to work. The plugin documentation can be found here: https://marketplace.visualstudio.com/items?itemName=qrti.funclist and describes creating a settings.json file inside the .vscode folder of your project. My problems arise when trying to modify the regex expressions for the funcList.nativeFilter and funcList.displayFilter configuration values. Here is my current settings.json file:
{
"funcList.nativeFilter": "/(?:^|\\s)Function\\s+\\w+\\(/mg",
"funcList.displayFilter": "/\\s*Function\\s+(.*)/1",
"funcList.sortList": 1,
"funcList.doubleSpacing": false
}
I believe the main problem is the part of \\w+ in the nativeFilter property. This seems to only match on characters/numbers but not any special characters. Here is a snippet of a piece of code that I would like to work with this Function List:
Function Do.Something(paramOne, paramTwo)
'...
End Function
Method Do.Something_Else(paramOne, paramTwo)
'...
End Function
Ideally, the nativeFilter would capture Function Do.Something(paramOne, paramTwo) .. until End Function and then the displayFilter would only capture the first line (ie. Do.Something(paramOne, paramTwo))
Note: according to the docs, nativeFilter does not allow regex groups, but displayFilter allows groups 0-9.
I use this for javascript and the funcList extension. It is similar to what you are trying to do:
// so that "function someName(arg1, arg2) is captured
"funcList.nativeFilter": "/^[a-z]+\\s+\\w+\\s*\\(.*\\)/mgi",
// now display "someName(arg1, arg2)"
"funcList.displayFilter": "/\\S* +(\\w+\\s*\\(.*\\))/1",
You obviously have capital letters, periods and underscores to worry about but hopefully this helps you to some degree. [I see I did not need to actually put the function keyword in to make it work...]
[EDIT] Try this, it seems to work:
"funcList.nativeFilter": "/^Function \\w+.\\w+\\(.*\\)?/mg",
"funcList.displayFilter": "/\\S* +(\\w+.\\w+\\(.*\\))/1",
You just needed the . as it is not included in \w
This seems to be working for my needs:
{
"funcList.nativeFilter": "/^(Function|Method|Macro)\\s+[a-zA-Z0-9.+(){}\\/\\\\[\\],_\\-=:;!##$%^&*|,.<>? ]*\\).*$/mg",
"funcList.displayFilter": "/\\s*((Function|Method|Macro)\\s+[a-zA-Z0-9.+(){}\\/\\\\[\\],_\\-=:;!##$%^&*|,.<>? ]+)/1"
}
With this plugin, you need to capture the entire line in order to get the navigation to work when clicking on a function list.

Accessing custom jbake confing properties in asciidoc

After some time I spent staring at the jbake code, I figured out that if I declare my own property in jbake.properties :
...
foo=bar
...
I can reuse that in files that go through a template engine by referencing it as ${config.foo}. I'd like to have this substitution working also on the content lvl, i.e. for files written in asciidoc, living inside the content directory.
Is there any non-trivial way to achieve it? How can I make the templating engine to proccess the result of asciidoc parses engine, or make it running it before the asciidoctor?
I found the answer myself.
To use the property substitution in asciidoc files, add following to the jbake.properties:
...
asciidoctor.attributes.export=true
foo=world
...
and reference the variable in aFile.adoc this way:
Hello {foo}!

Displaying parsed HTML output using Velocity

i have a velocity template...
It contains the following tag:
#field('itemname')
The "itemname" variable contains this:
<i>Some</i> <b>Example Title</b>
The source of the outputted page has this:
<i>Some</i>
<b>Example Title</b>
So, the user sees the actual HTML tags:
<i>Some</i> <b>Example Title</b>
What I want them to see is:
Some Example Title
Where am I going wrong?
If I see right from your snippets, the problem is not with the velocity template, but with the mime type encoding of the HTTP Response your user is receiving. It should be "text/html", but I suspect it's something else, and so, the browser is showing the tags instead of "rendering" them to what they represent.
Of course, I don't know what your #field() macro does, so the problem might be something else, e.g. that macro might generate a wrapping PRE tag or a Text Area, and this might be the cause you why the those B and I tags are displayed as they are instead of being rendered.