PHP has no problem with outputting a different language than HTML but as it seems, VSCode doesn't understand this. I've searched a bit for solutions, but Google gives me nothing.

For example, I'm using PHP to generate dynamic Markdown files.

header("Type: text/markdown");
# Some PHP code

# Header

Some **markdown** code.

    This is a code block.

It is not much of a problem for me that the above example provides no syntax highlighting for Markdown. The real issue is with the HTML formatter. It removes leading space, which would cause the This is a code block. part to stop being a code block, since the indentation would be removed. Similar problem is with lists and double spaces.

Is there any way I could stop the HTML formatter in VSCode from breaking my Markdown code?

1 Answers

Quentin On

The VS Code PHP language syntax is for PHP embedded in HTML documents (which, along with pure PHP (which is compatible)) is the most common form of PHP.

If you want support for PHP embedded in Markdown, you'll need a syntax library for that. I'm not aware of any existing one, so you might have to write your own.

The relevant documentation can be found on the VS Code website.

Your simplist approach is likely to be looking for an existing PHP grammar and an existing Markdown grammar and then combining them (which removing the HTML support).