Trivadis / plsql-formatter-settings

PL/SQL & SQL formatter settings based on the Trivadis PL/SQL & SQL Coding Guidelines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stop of SQL code blocks in Markdown files is identified wrongly

PhilippSalvisberg opened this issue · comments

A SQL code block is identified here:

https://github.com/Trivadis/plsql-formatter-settings/blob/sqlcl-22.2.1/sqlcl/format.js#L562

If a SQL block starts indented, the end of the block is not identified correctly. It looks for the three backticks on a new line. As a result the result will contain everthing until the end of code block that ends on a new line.

See https://github.com/PhilippSalvisberg/plscope-utils/blob/v1.0.0/database/README.md?plain=1#L32-L58 .

More precise is this example: https://regex101.com/r/vQZ3kP/1 .

At the moment the formatter is not able to handle indented code. In most cases the indentation is lost. In other cases the code is not formatted due to a syntax error (e.g. for @database/utils/user/plscope.sql spaces before the @ lead to a syntax error).

So the regex should be changed to ensure only non-indented code blocks are found and formatted.

As a workaround for version sqlcl-22.2.1 indented code blocks should be used without SQL code highlighting.

regex should be something like this:

(\n```[ \t]*sql[ \t]*[^\n]*\n)(.+?)(\n```)

This supports: