Skip to content

Commit

Permalink
fix(formatter): added quotes to json keys, added option to disable se…
Browse files Browse the repository at this point in the history
…t/function formatting

closes #682
  • Loading branch information
christopherpickering committed Jun 2, 2023
1 parent 6d5a443 commit 6f7df03
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 230 deletions.
46 changes: 46 additions & 0 deletions docs/src/_data/configuration.json
@@ -1,4 +1,50 @@
[
{
"name": "no_set_formatting",
"description": {
"en": "Do not attempt to format set contents. ** If you use this option please open a gh issue explaining what caused you to use it.",
"ru": "Не пытайтесь форматировать содержимое набора. ** Если вы используете эту опцию, пожалуйста, откройте проблему gh, объяснив, что заставило вас использовать ее.",
"fr": "Ne pas tenter de formater le contenu du jeu. ** Si vous utilisez cette option, veuillez ouvrir un problème gh en expliquant ce qui vous a poussé à l'utiliser"
},
"usage": [
{
"name": "pyproject.toml",
"value": "no_set_formatting=true"
},
{
"name": ".djlintrc",
"value": "\"no_set_formatting\": true"
},
{
"name": "cli",
"value": "--no-set-formatting"
}
],
"tags": ["formatter"]
},
{
"name": "no_function_formatting",
"description": {
"en": "Do not attempt to format function contents. ** If you use this option please open a gh issue explaining what caused you to use it.",
"ru": "Не пытайтесь форматировать содержимое функции. ** Если вы используете эту опцию, пожалуйста, откройте проблему gh, объяснив, что заставило вас ее использовать.",
"fr": "Ne pas tenter de formater le contenu de la fonction. ** Si vous utilisez cette option, veuillez ouvrir un problème gh en expliquant ce qui vous a poussé à l'utiliser."
},
"usage": [
{
"name": "pyproject.toml",
"value": "no_function_formatting=true"
},
{
"name": ".djlintrc",
"value": "\"no_function_formatting\": true"
},
{
"name": "cli",
"value": "--no-function-formatting"
}
],
"tags": ["formatter"]
},
{
"name": "no_line_after_yaml",
"description": {
Expand Down
63 changes: 63 additions & 0 deletions docs/src/_includes/cli.md
@@ -0,0 +1,63 @@
{% raw %}

```bash
Usage: djlint [OPTIONS] SRC ...

djLint · lint and reformat HTML templates.

Options:
--version Show the version and exit.
-e, --extension TEXT File extension to check [default: html]
-i, --ignore TEXT Codes to ignore. ex: "H014,H017"
--reformat Reformat the file(s).
--check Check formatting on the file(s).
--indent INTEGER Indent spacing. [default: 4]
--quiet Do not print diff when reformatting.
--profile TEXT Enable defaults by template language. ops:
django, jinja, nunjucks, handlebars, golang,
angular, html [default: html]
--require-pragma Only format or lint files that starts with a
comment with the text 'djlint:on'
--lint Lint for common issues. [default option]
--use-gitignore Use .gitignore file to extend excludes.
--warn Return errors as warnings.
--preserve-leading-space Attempt to preserve leading space on text.
--preserve-blank-lines Attempt to preserve blank lines.
--format-css Also format contents of <style> tags.
--format-js Also format contents of <script> tags.
--configuration PATH Path to global configuration file in
.djlintrc format
--statistics Count the number of occurrences of each
error/warning code.
--include TEXT Codes to include. ex: "H014,H017"
--ignore-case Do not fix case on known html tags.
--ignore-blocks TEXT Comma list of template blocks to not indent.
--blank-line-after-tag TEXT Add an additional blank line after {% <tag>
... %} tag groups.
--blank-line-before-tag TEXT Add an additional blank line before {% <tag>
... %} tag groups.
--custom-blocks TEXT Indent custom template blocks. For example
{% toc %}...{% endtoc %}
--custom-html TEXT Indent custom HTML tags. For example <mjml>
--exclude TEXT Override the default exclude paths.
--extend-exclude TEXT Add additional paths to the default exclude.
--linter-output-format TEXT Customize order of linter output message.
--max-line-length INTEGER Max line length. [default: 120]
--max-attribute-length INTEGER Max attribute length. [default: 70]
--format-attribute-template-tags
Attempt to format template syntax inside of
tag attributes.
--per-file-ignores <TEXT TEXT>...
Ignore linter rules on a per-file basis.
--indent-css INTEGER Set CSS indent level.
--indent-js INTEGER Set JS indent level.
--close-void-tags Add closing mark on known void tags. Ex:
<img> becomse <img />
--no-line-after-yaml Do not add a blank line after yaml front
matter.
--no-function-formatting Do not attempt to format function contents.
--no-set-formatting Do not attempt to format set contents.
-h, --help Show this message and exit.
```
{% endraw %}
17 changes: 16 additions & 1 deletion docs/src/_includes/demo.njk
Expand Up @@ -185,7 +185,22 @@ keywords: online template formatter, djLint, HTML, templates, formatter, linter,
</span></a>
</label>
</div>

<div class="field">
<label class="checkbox">
<input id="settings-no-function-formatting" type="checkbox">
No Function Formatting <a href="/docs/configuration/#no-function-formatting" target="_blank"><span class="icon has-text-grey-light">
<i class="fas fa-circle-question"></i>
</span></a>
</label>
</div>
<div class="field">
<label class="checkbox">
<input id="settings-no-set-formatting" type="checkbox">
No Set Formatting <a href="/docs/configuration/#no-set-formatting" target="_blank"><span class="icon has-text-grey-light">
<i class="fas fa-circle-question"></i>
</span></a>
</label>
</div>


</form>
Expand Down
61 changes: 1 addition & 60 deletions docs/src/docs/getting-started.md
Expand Up @@ -24,67 +24,8 @@ npm i djlint

djLint is a command line application. See `configuration` for advanced configuration.

{% raw %}
{% include 'src/\_includes/cli.md' %}

```bash
Usage: djlint [OPTIONS] SRC ...

djLint · lint and reformat HTML templates.

Options:
--version Show the version and exit.
-e, --extension TEXT File extension to check [default: html]
-i, --ignore TEXT Codes to ignore. ex: "H014,H017"
--reformat Reformat the file(s).
--check Check formatting on the file(s).
--indent INTEGER Indent spacing. [default: 4]
--quiet Do not print diff when reformatting.
--profile TEXT Enable defaults by template language. ops:
django, jinja, nunjucks, handlebars, golang,
angular, html [default: html]
--require-pragma Only format or lint files that starts with a
comment with the text 'djlint:on'
--lint Lint for common issues. [default option]
--use-gitignore Use .gitignore file to extend excludes.
--warn Return errors as warnings.
--preserve-leading-space Attempt to preserve leading space on text.
--preserve-blank-lines Attempt to preserve blank lines.
--format-css Also format contents of <style> tags.
--format-js Also format contents of <script> tags.
--configuration PATH Path to global configuration file in
.djlintrc format
--statistics Count the number of occurrences of each
error/warning code.
--include TEXT Codes to include. ex: "H014,H017"
--ignore-case Do not fix case on known html tags.
--ignore-blocks TEXT Comma list of template blocks to not indent.
--blank-line-after-tag TEXT Add an additional blank line after {% <tag>
... %} tag groups.
--blank-line-before-tag TEXT Add an additional blank line before {% <tag>
... %} tag groups.
--custom-blocks TEXT Indent custom template blocks. For example
{% toc %}...{% endtoc %}
--custom-html TEXT Indent custom HTML tags. For example <mjml>
--exclude TEXT Override the default exclude paths.
--extend-exclude TEXT Add additional paths to the default exclude.
--linter-output-format TEXT Customize order of linter output message.
--max-line-length INTEGER Max line length. [default: 120]
--max-attribute-length INTEGER Max attribute length. [default: 70]
--format-attribute-template-tags
Attempt to format template syntax inside of
tag attributes.
--per-file-ignores <TEXT TEXT>...
Ignore linter rules on a per-file basis.
--indent-css INTEGER Set CSS indent level.
--indent-js INTEGER Set JS indent level.
--close-void-tags Add closing mark on known void tags. Ex:
<img> becomse <img />
--no-line-after-yaml Do not add a blank line after yaml front
matter.
-h, --help Show this message and exit.
```
{% endraw %}
{% admonition
"note",
"Note",
Expand Down
62 changes: 1 addition & 61 deletions docs/src/fr/docs/getting-started.md
Expand Up @@ -24,67 +24,7 @@ npm i djlint

djLint est une application en ligne de commande. Voir `configuration` pour une configuration avancée.

{% raw %}

```bash
Usage: djlint [OPTIONS] SRC ...

djLint · lint and reformat HTML templates.

Options:
--version Show the version and exit.
-e, --extension TEXT File extension to check [default: html]
-i, --ignore TEXT Codes to ignore. ex: "H014,H017"
--reformat Reformat the file(s).
--check Check formatting on the file(s).
--indent INTEGER Indent spacing. [default: 4]
--quiet Do not print diff when reformatting.
--profile TEXT Enable defaults by template language. ops:
django, jinja, nunjucks, handlebars, golang,
angular, html [default: html]
--require-pragma Only format or lint files that starts with a
comment with the text 'djlint:on'
--lint Lint for common issues. [default option]
--use-gitignore Use .gitignore file to extend excludes.
--warn Return errors as warnings.
--preserve-leading-space Attempt to preserve leading space on text.
--preserve-blank-lines Attempt to preserve blank lines.
--format-css Also format contents of <style> tags.
--format-js Also format contents of <script> tags.
--configuration PATH Path to global configuration file in
.djlintrc format
--statistics Count the number of occurrences of each
error/warning code.
--include TEXT Codes to include. ex: "H014,H017"
--ignore-case Do not fix case on known html tags.
--ignore-blocks TEXT Comma list of template blocks to not indent.
--blank-line-after-tag TEXT Add an additional blank line after {% <tag>
... %} tag groups.
--blank-line-before-tag TEXT Add an additional blank line before {% <tag>
... %} tag groups.
--custom-blocks TEXT Indent custom template blocks. For example
{% toc %}...{% endtoc %}
--custom-html TEXT Indent custom HTML tags. For example <mjml>
--exclude TEXT Override the default exclude paths.
--extend-exclude TEXT Add additional paths to the default exclude.
--linter-output-format TEXT Customize order of linter output message.
--max-line-length INTEGER Max line length. [default: 120]
--max-attribute-length INTEGER Max attribute length. [default: 70]
--format-attribute-template-tags
Attempt to format template syntax inside of
tag attributes.
--per-file-ignores <TEXT TEXT>...
Ignore linter rules on a per-file basis.
--indent-css INTEGER Set CSS indent level.
--indent-js INTEGER Set JS indent level.
--close-void-tags Add closing mark on known void tags. Ex:
<img> becomse <img />
--no-line-after-yaml Do not add a blank line after yaml front
matter.
-h, --help Show this message and exit.
```
{% endraw %}
{% include 'src/\_includes/cli.md' %}

{% admonition
"note",
Expand Down
62 changes: 1 addition & 61 deletions docs/src/ru/docs/getting-started.md
Expand Up @@ -24,67 +24,7 @@ npm i djlint

djLint - это приложение командной строки. Для расширенной настройки смотрите `конфигурация`.

{% raw %}

```bash
Usage: djlint [OPTIONS] SRC ...

djLint · lint and reformat HTML templates.

Options:
--version Show the version and exit.
-e, --extension TEXT File extension to check [default: html]
-i, --ignore TEXT Codes to ignore. ex: "H014,H017"
--reformat Reformat the file(s).
--check Check formatting on the file(s).
--indent INTEGER Indent spacing. [default: 4]
--quiet Do not print diff when reformatting.
--profile TEXT Enable defaults by template language. ops:
django, jinja, nunjucks, handlebars, golang,
angular, html [default: html]
--require-pragma Only format or lint files that starts with a
comment with the text 'djlint:on'
--lint Lint for common issues. [default option]
--use-gitignore Use .gitignore file to extend excludes.
--warn Return errors as warnings.
--preserve-leading-space Attempt to preserve leading space on text.
--preserve-blank-lines Attempt to preserve blank lines.
--format-css Also format contents of <style> tags.
--format-js Also format contents of <script> tags.
--configuration PATH Path to global configuration file in
.djlintrc format
--statistics Count the number of occurrences of each
error/warning code.
--include TEXT Codes to include. ex: "H014,H017"
--ignore-case Do not fix case on known html tags.
--ignore-blocks TEXT Comma list of template blocks to not indent.
--blank-line-after-tag TEXT Add an additional blank line after {% <tag>
... %} tag groups.
--blank-line-before-tag TEXT Add an additional blank line before {% <tag>
... %} tag groups.
--custom-blocks TEXT Indent custom template blocks. For example
{% toc %}...{% endtoc %}
--custom-html TEXT Indent custom HTML tags. For example <mjml>
--exclude TEXT Override the default exclude paths.
--extend-exclude TEXT Add additional paths to the default exclude.
--linter-output-format TEXT Customize order of linter output message.
--max-line-length INTEGER Max line length. [default: 120]
--max-attribute-length INTEGER Max attribute length. [default: 70]
--format-attribute-template-tags
Attempt to format template syntax inside of
tag attributes.
--per-file-ignores <TEXT TEXT>...
Ignore linter rules on a per-file basis.
--indent-css INTEGER Set CSS indent level.
--indent-js INTEGER Set JS indent level.
--close-void-tags Add closing mark on known void tags. Ex:
<img> becomse <img />
--no-line-after-yaml Do not add a blank line after yaml front
matter.
-h, --help Show this message and exit.
```
{% endraw %}
{% include 'src/\_includes/cli.md' %}

{% admonition
"note",
Expand Down
10 changes: 10 additions & 0 deletions docs/src/static/js/editor.js
Expand Up @@ -74,6 +74,16 @@ if (typeof Worker !== 'undefined') {
).checked;
if (noLineAfterYaml) config['noLineAfterYaml'] = noLineAfterYaml;

const noFunctionFormatting = document.getElementById(
'settings-no-function-formatting',
).checked;
if (noFunctionFormatting)
config['noFunctionFormatting'] = noFunctionFormatting;
const noSetFormatting = document.getElementById(
'settings-no-set-formatting',
).checked;
if (noSetFormatting) config['noSetFormatting'] = noSetFormatting;

return config;
}

Expand Down
8 changes: 8 additions & 0 deletions docs/src/static/js/worker.js
Expand Up @@ -113,6 +113,14 @@ self.onmessage = async (event) => {
? `config.blank_line_before_tag="${config.blankLineBeforeTag}"`
: '';

const noSetFormatting = config.noSetFormatting
? `config.no_set_formatting="${config.noSetFormatting}"`
: '';

const noFunctionFormatting = config.noFunctionFormatting
? `config.no_function_formatting="${config.noFunctionFormatting}"`
: '';

try {
await self.pyodide.runPythonAsync(`
import io
Expand Down

0 comments on commit 6f7df03

Please sign in to comment.