Skip to content

Commit

Permalink
Configurable default values for directive arguments (#122)
Browse files Browse the repository at this point in the history
* Configurable default values for directive arguments

* Add tests and documentation

* Add test for 100% code coverage

* Skip test on Windows

* Fix error in tests
  • Loading branch information
mondeja committed Sep 15, 2022
1 parent 0c5dba6 commit 3a4c332
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.7.1
current_version = 3.8.0

[bumpversion:file:mkdocs_include_markdown_plugin/__init__.py]

Expand Down
17 changes: 14 additions & 3 deletions README.md
Expand Up @@ -38,16 +38,27 @@ plugins:
> Make sure that you define `include-markdown` before other plugins that could
conflict, like [`mkdocs-macros-plugin`][mkdocs-macros-plugin-link].

### Custom opening and closing tags
### Configuration

The default opening and closing tags are `{%` and `%}`. You can change this
default with the configuration fields `opening_tag` and `closing_tag`:
The global behaviour of the plugin can be customized in the configuration.

- <a name="config_tags" href="#config_tags">#</a> **opening_tag** and
**closing_tag**: The default opening and closing tags. By default are
`{%` and `%}`.

The rest of the options will define the default values passed to arguments
of directives and are documented in the [reference](#reference).

```yaml
plugins:
- include-markdown:
opening_tag: "{!"
closing_tag: "!}"
encoding: ascii
preserve_includer_indent: false
dedent: true
trailing_newlines: false
comments: false
```

### Reference
Expand Down
17 changes: 13 additions & 4 deletions locale/es/README.md
Expand Up @@ -31,17 +31,26 @@ plugins:
> Asegúrate que defines `include-markdown` antes de otros plugins que pudieran
entrar en conflicto, como [`mkdocs-macros-plugin`][mkdocs-macros-plugin-link].

### Etiquetas de apertura y cierre personalizadas
### Configuración

Las etiquetas de apertura y cierre por defecto son `{%` y `%}`. Se puede cambiar
este valor por defecto con los campos de configuración `opening_tag` y
`closing_tag`.
El comportamiento global del plugin puede ser personalizado en la configuración.

- <a name="config_tags" href="#config_tags">#</a> **opening_tag** and **closing_tag**:
Las etiquetas de apertura y cierre. Por defecto son `{%` y `%}`.

El resto de las opciones definirán los valores por defecto pasados a los
argumentos de las directivas y están documentados en la [referencia](#reference).

```yaml
plugins:
- include-markdown:
opening_tag: "{!"
closing_tag: "!}"
encoding: ascii
preserve_includer_indent: false
dedent: true
trailing_newlines: false
comments: false
```

### Referencia
Expand Down
37 changes: 26 additions & 11 deletions locale/es/README.md.po
Expand Up @@ -305,17 +305,6 @@ msgstr ""
"envolver con comillas dobles `\"` o simples `'`, que se pueden escapar "
"anteponiendo un carácter `\\` como `\\\"` y `\\'`."

msgid "Custom opening and closing tags"
msgstr "Etiquetas de apertura y cierre personalizadas"

msgid ""
"The default opening and closing tags are `{%` and `%}`. You can change this "
"default with the configuration fields `opening_tag` and `closing_tag`:"
msgstr ""
"Las etiquetas de apertura y cierre por defecto son `{%` y `%}`. Se puede "
"cambiar este valor por defecto con los campos de configuración `opening_tag`"
" y `closing_tag`."

msgid ""
"<a name=\"include-markdown_encoding\" href=\"#include-"
"markdown_encoding\">#</a> **encoding** (*utf-8*): Specify the encoding of "
Expand All @@ -333,3 +322,29 @@ msgstr ""
"<a name=\"include_encoding\" href=\"#include_encoding\">#</a> **encoding** "
"(*utf-8*): Especifica la codificación del archivo incluído. Si no se define,"
" se usará `utf-8`."

msgid "Configuration"
msgstr "Configuración"

msgid ""
"The global behaviour of the plugin can be customized in the configuration."
msgstr ""
"El comportamiento global del plugin puede ser personalizado en la "
"configuración."

msgid ""
"<a name=\"config_tags\" href=\"#config_tags\">#</a> **opening_tag** and "
"**closing_tag**: The default opening and closing tags. By default are `{%` "
"and `%}`."
msgstr ""
"<a name=\"config_tags\" href=\"#config_tags\">#</a> **opening_tag** and "
"**closing_tag**: Las etiquetas de apertura y cierre. Por defecto son `{%` y "
"`%}`."

msgid ""
"The rest of the options will define the default values passed to arguments "
"of directives and are documented in the [reference](#reference)."
msgstr ""
"El resto de las opciones definirán los valores por defecto pasados a los "
"argumentos de las directivas y están documentados en la "
"[referencia](#reference)."
17 changes: 13 additions & 4 deletions locale/fr/README.md
Expand Up @@ -31,17 +31,26 @@ plugins:
> Assurez-vous de définir `include-markdown` avant d'autres plugins qui
pourraient entrer en conflit, comme [`mkdocs-macros-plugin`][mkdocs-macros-plugin-link].

### Balises d'ouverture et de fermeture personnalisées
### Configuration

Les balises d'ouverture et de fermeture par défaut sont `{%` et `%}`. Vous
pouvez changer ces balises avec les paramètres de configuration `opening_tag` et
`closing_tag`:
Le comportement global du plugin peut être personnalisé dans la configuration.

- <a name="config_tags" href="#config_tags">#</a> **opening_tag** and **closing_tag**:
Les balises d'ouverture et de fermeture par défaut. Par défaut sont `{%` et `%}`.

Le reste des options définira les valeurs par défaut passées aux arguments des
directives et sont documentées dans la [référence](#reference).

```yaml
plugins:
- include-markdown:
opening_tag: "{!"
closing_tag: "!}"
encoding: ascii
preserve_includer_indent: false
dedent: true
trailing_newlines: false
comments: false
```

### Référence
Expand Down
36 changes: 25 additions & 11 deletions locale/fr/README.md.po
Expand Up @@ -305,17 +305,6 @@ msgstr ""
"peuvent être entourés de guillemets doubles `\"` ou simples `'`, qui peuvent"
" être échappés en leur ajoutant un caractère `\\` comme `\\\"` et `\\'`."

msgid "Custom opening and closing tags"
msgstr "Balises d'ouverture et de fermeture personnalisées"

msgid ""
"The default opening and closing tags are `{%` and `%}`. You can change this "
"default with the configuration fields `opening_tag` and `closing_tag`:"
msgstr ""
"Les balises d'ouverture et de fermeture par défaut sont `{%` et `%}`. Vous "
"pouvez changer ces balises avec les paramètres de configuration "
"`opening_tag` et `closing_tag`:"

msgid ""
"<a name=\"include-markdown_encoding\" href=\"#include-"
"markdown_encoding\">#</a> **encoding** (*utf-8*): Specify the encoding of "
Expand All @@ -333,3 +322,28 @@ msgstr ""
"<a name=\"include_encoding\" href=\"#include_encoding\">#</a> **encoding** "
"(*utf-8*): Spécifiez l'encodage du fichier inclus. S'il n'est pas défini, "
"`utf-8` sera utilisé."

msgid "Configuration"
msgstr "Configuration"

msgid ""
"<a name=\"config_tags\" href=\"#config_tags\">#</a> **opening_tag** and "
"**closing_tag**: The default opening and closing tags. By default are `{%` "
"and `%}`."
msgstr ""
"<a name=\"config_tags\" href=\"#config_tags\">#</a> **opening_tag** and "
"**closing_tag**: Les balises d'ouverture et de fermeture par défaut. Par "
"défaut sont `{%` et `%}`."

msgid ""
"The global behaviour of the plugin can be customized in the configuration."
msgstr ""
"Le comportement global du plugin peut être personnalisé dans la "
"configuration."

msgid ""
"The rest of the options will define the default values passed to arguments "
"of directives and are documented in the [reference](#reference)."
msgstr ""
"Le reste des options définira les valeurs par défaut passées aux arguments "
"des directives et sont documentées dans la [référence](#reference)."
2 changes: 1 addition & 1 deletion mkdocs_include_markdown_plugin/__init__.py
@@ -1,2 +1,2 @@
__title__ = 'mkdocs_include_markdown_plugin'
__version__ = '3.7.1'
__version__ = '3.8.0'
57 changes: 57 additions & 0 deletions mkdocs_include_markdown_plugin/config.py
@@ -0,0 +1,57 @@
import mkdocs.config.config_options


CONFIG_DEFAULTS = {
'opening_tag': '{%',
'closing_tag': '%}',
'encoding': 'utf-8',
'preserve_includer_indent': True,
'dedent': False,
'trailing_newlines': True,
'comments': True,
}

CONFIG_SCHEME = (
(
'opening_tag',
mkdocs.config.config_options.Type(
str, default=CONFIG_DEFAULTS['opening_tag'],
),
),
(
'closing_tag',
mkdocs.config.config_options.Type(
str, default=CONFIG_DEFAULTS['closing_tag'],
),
),
(
'encoding',
mkdocs.config.config_options.Type(
str, default=CONFIG_DEFAULTS['encoding'],
),
),
(
'preserve_includer_indent',
mkdocs.config.config_options.Type(
bool, default=CONFIG_DEFAULTS['preserve_includer_indent'],
),
),
(
'dedent',
mkdocs.config.config_options.Type(
bool, default=CONFIG_DEFAULTS['dedent'],
),
),
(
'trailing_newlines',
mkdocs.config.config_options.Type(
bool, default=CONFIG_DEFAULTS['trailing_newlines'],
),
),
(
'comments',
mkdocs.config.config_options.Type(
bool, default=CONFIG_DEFAULTS['comments'],
),
),
)

0 comments on commit 3a4c332

Please sign in to comment.