How to get vscode markdown to highlight OCaml code? - visual-studio-code

I cannot get my OCaml code block highlight in vscode markdown files. The default syntax to specify language is language where you can put the name of the language to get highlighted. I cannot find the documentation for the keywords for OCaml. .ml files do have highlights.

Regarding markdown, adding ml to the backtick fence should be enough, since VSCode uses highlight.js, and this library does list its supported languages.
With VSCode 1.71 (Aug. 2021), you can even specify triple-backtick code blocks with more than just a language identifier in the info string.
See PR 157947: "Allow markdown code blocks to contain data after language id". Released to VSCode insiders today.
(From issue 157793)

You need to install the OCaml Platform extension.

Related

Disable competing language servers / code highlighters

I want to add a language server to handle completion / highlighting / etc. for a file.
As a basis for testing stuff I am using an example from Microsoft (https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample) and changed it to be active for any File. This language server highlights any word in all capital letters.
When opening a C++ File, I get the highlighting / completion of my language server and the default one for C++ (See image).
I would like to detect if some other extension / build in highlighter is active for a file and deactivate it for this workspace or the current file if it is impossible for the current workspace)
Is there a way to do this in a generic way where I do not have to know which extensions are highlighting code?
If no, is there a way to do this, if I know a set of extensions I want to deactivate?
I finally had enough time to try around a bit more and found that providing your own language for the same extension is enough.
In package.json I added an element in contributes.languages with extensions containing .cpp (since I am using cpp files for testing).
I also copied over some implementation code from an example.
This suppressed the default highlighter and code completion for cpp files. Since i am only implementing a semantic token provider, I can see the default highlighting before my provider takes over. (I think this could be solved by adding a syntax highlighter, but this is already sufficient fo my preliminary testing)
I am not sure, how stable all of this would be as a plugin (I only tested in Extension Development Host mode)
Here an image of the results:

Reference-style links in Visual Studio Code

I found that Markdown has something called reference-style links. I don't know if is it official Markdown syntax or it exists only in some Markdown add-ons.
I tried to create something like that in VSCode, but it doesn't work:
[Test][ducksearch]
[ducksearch]: https://duckduckgo.com
I wonder is it a bug/un-implemented function in VSCode or that syntax works only with some extension?
Reference-style links are part of the original Markdown specification. They should work just about everywhere Markdown does, and that includes Visual Studio Code.
Just add a blank line to separate the paragraph containing the link from the reference:
[Test][ducksearch]
[ducksearch]: https://duckduckgo.com
Not only reference-style links are supported natively by VSCode markdown editor, but VSCode 1.68 (May 2022) will enable "go to definition".
See issue 146293
Enable triggering go to definition on a markdown reference link to jump to the link definition
[text][link] // trigger on link here
[link]: https://example.com
Go to def (from text) should jump to the definition of link, at the end of the file
This is implemented in PR 148017, and available in the Insider edition right now.

VSCode: is it possible to easily format/color my own "language"?

I'm using VSCode on a linux machine, but I used to use Notepad++. with windows, and within Notepad's language options (to color and format the code as java, php, c#, etç), there was an option to create your own custom formatter, and I used this option to create my own "Diary language", example:
If I start and end a line with *, it formats the line with black and
bold.
If I start and end a line with #, it formats the line with red
and plain.
If I start a line with > and end it with <, it formats the line with blue and underline.
I know that I can develop my own plugin for vscode, but that is not easy and definitely not fast, is there an option or plugin that allows me to do this?
Yes, I can use some software or app to remind me some stuff, and I am using some, but it would be nice to have my annotations colored inside my text editor.
It's not a duplicate of Customizing syntax highlighting in Visual Studio Code since I'm not creating my own language. This is the point of my question, I do not want to create a whole new language pack/theme, I just want some coloring, like the notepad++ option.
The second question on the page https://code.visualstudio.com/docs/languages/overview#_common-questions seems to answer this
Q: What if I don't want to create a full language service, can I reuse
existing TextMate bundles?
A: Yes, you can also add support for your favorite language through
TextMate colorizers. See Themes, Snippets, and Colorizers topic in the
Extension Authoring section to learn how to integrate TextMate
.tmLanguage syntax files into VS Code.
Which points to https://code.visualstudio.com/docs/extensions/themes-snippets-colorizers, which shows you how to more easily intergrate custom colour and theme rules.

Getting github to syntax highlight my files

github automaticall syntax highlights any code files such as those with .c extensions. And there seems plenty of information about controlling highlighting from within 'markdown' or .md files.
But how can I get it to highlight code files that it doesn't know about?
I can't even get the tabbing right - if I say 4-spaces tabs while editing, it goes back to 8-space ones when I've finished.
I don't care what highlighting style it uses even if it's the wrong language; it must be better than the plain text appearance which looks really flat. Oddly, when editing it uses some sort of highlighting, which again disappears when I've finished.
The files aren't in any well-known language so the highlighting won't be perfect; I just want a bit of colour. But I'd rather not change file extensions as that could be confusing.
The tabbing is done through a ?t=4 parameter added to the GitHub url.
But the syntax highlighting (using Rouge on GitHub pages for instance) itself is either:
set in fenced code block (but only for .md markdown pages)
or by changing the file extension (which you don't want)
But how can I get it to highlight code files that it doesn't know about?
Update Feb. 2021 (5 years later)
Nat Friedman (CEO of GitHub) announces it on Twitter:
Another tiny but nice improvement we just shipped to GitHub – syntax highlighting now works on new files without the need to commit first.

Why is `&&` highlighted on Github

On Github, I realized that &&s are highlighted in this file but not in the other languages such as Java, JavaScript etc in the same repo. Does anyone know what the highlight actually means?
Thanks
Allen
Because it is an ASHX (WebHandler) file. The syntax highlighting on GitHub it language-specific:
What is ASHX:
http://www.c-sharpcorner.com/uploadfile/prathore/what-is-an-ashx-file-handler-or-web-handler/
Another example of GitHub syntax highlighting for ASHX:
https://github.com/JamesDunne/sql.ashx/blob/master/sql.ashx
This is a bug with GitHub Linguist, which is not selecting the right grammar for highlighting. The current grammar is expecting this kind of syntax and is unable to highlight your file.
My guess is we'd need to select a new grammar just for .ashx. If you know a TextMate, Sublime Text, or Atom grammar capable of highlighting correctly .ashx files, please open an issue or pull request at Linguist.