Skip to content

Commit

Permalink
fix: Fix markdown "break on newline" configurability (#236)
Browse files Browse the repository at this point in the history
Previously, `"break-on-newline": True` was part of the default markdown
options. The user could override the configuration value, thus turning
it into `"break-on-newline": False`, but unfortunately the markdown2
library ignores the value of the option, and always sets it to `True` if
the key is passed in.

The `break-on-newline` extra is deprecated, there is a new option since
2.4.11: `breaks` https://github.com/trentm/python-markdown2/wiki/breaks
Unfortunately, markdown2 overrides the `breaks.on_newline` configuration
if `break-on-newline` is present in the extras, meaning that this
doesn't work for disabling "break on newline" either.

This means that right now there is _no_ way for the users of jsfh to
disable line breaks on newlines. To fix this, remove `break-on-newline`
from the default markdown options. If (and only if) the `breaks` config
is _not_ set by the user, a `breaks` config is added to the defaults
that inserts line breaks on newlines by default.

---------

Co-authored-by: Denis Blanchette <[email protected]>
  • Loading branch information
threema-danilo and dblanchette authored Nov 29, 2024
1 parent 11ede01 commit c0c9d09
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 84 deletions.
4 changes: 2 additions & 2 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
"cssclass": "highlight jumbotron"
},
"tables": null,
"break-on-newline": true
"breaks": {"on_newline": true, "on_backslash": true}
},
"description": "[Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions. `description_is_markdown` must be true for this to have any effect.\n\n**WARNING**\nAdding an extra, even if the value is false, will activate it. For example `{\"break-on-newline\": false}` will activate the `break-on-newline` extra.",
"description": "(Only used with `description_is_markdown`)\n[Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions.",
"examples": [
{
"fenced-code-blocks": {
Expand Down
8 changes: 3 additions & 5 deletions docs/examples/examples_flat_default/Configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -745,18 +745,16 @@ <h2 class="mb-0">
d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"
/>
</svg>
<a href="#markdown_options">markdown_options</a></div><span class="badge badge-dark value-type">Type: object</span> <span class="badge badge-success default-value">Default: {"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "break-on-newline": true}</span><br/>
<a href="#markdown_options">markdown_options</a></div><span class="badge badge-dark value-type">Type: object</span> <span class="badge badge-success default-value">Default: {"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "breaks": {"on_newline": true, "on_backslash": true}}</span><br/>







<p><a href="https://github.com/trentm/python-markdown2/wiki/Extras">Markdown 2 options</a> for the descriptions. <code>description_is_markdown</code> must be true for this to have any effect.</p>

<p><strong>WARNING</strong><br />
Adding an extra, even if the value is false, will activate it. For example <code>{"break-on-newline": false}</code> will activate the <code>break-on-newline</code> extra.</p>
<p>(Only used with <code>description_is_markdown</code>)<br />
<a href="https://github.com/trentm/python-markdown2/wiki/Extras">Markdown 2 options</a> for the descriptions.</p>



Expand Down
17 changes: 4 additions & 13 deletions docs/examples/examples_js_default/Configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -720,19 +720,10 @@ <h2 class="mb-0">
d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"
/>
</svg>
<a href="#markdown_options" onclick="anchorLink('markdown_options')">markdown_options</a></div><span class="badge badge-dark value-type">Type: object</span> <span class="badge badge-success default-value">Default: {"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "break-on-newline": true}</span><br/>
<div class="description collapse" id="collapseDescription_markdown_options">
<p><a href="https://github.com/trentm/python-markdown2/wiki/Extras">Markdown 2 options</a> for the descriptions. <code>description_is_markdown</code> must be true for this to have any effect.</p>

<p><strong>WARNING</strong><br />
Adding an extra, even if the value is false, will activate it. For example <code>{"break-on-newline": false}</code> will activate the <code>break-on-newline</code> extra.</p>

</div>
<div>
<a class="collapse-description-link collapsed" data-toggle="collapse" href="#collapseDescription_markdown_options"
aria-expanded="false" aria-controls="collapseDescriptionmarkdown_options"
></a>
</div>
<a href="#markdown_options" onclick="anchorLink('markdown_options')">markdown_options</a></div><span class="badge badge-dark value-type">Type: object</span> <span class="badge badge-success default-value">Default: {"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "breaks": {"on_newline": true, "on_backslash": true}}</span><br/>
<span class="description"><p>(Only used with <code>description_is_markdown</code>)<br />
<a href="https://github.com/trentm/python-markdown2/wiki/Extras">Markdown 2 options</a> for the descriptions.</p>
</span>



Expand Down
17 changes: 4 additions & 13 deletions docs/examples/examples_js_offline_default/Configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -720,19 +720,10 @@ <h2 class="mb-0">
d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"
/>
</svg>
<a href="#markdown_options" onclick="anchorLink('markdown_options')">markdown_options</a></div><span class="badge badge-dark value-type">Type: object</span> <span class="badge badge-success default-value">Default: {"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "break-on-newline": true}</span><br/>
<div class="description collapse" id="collapseDescription_markdown_options">
<p><a href="https://github.com/trentm/python-markdown2/wiki/Extras">Markdown 2 options</a> for the descriptions. <code>description_is_markdown</code> must be true for this to have any effect.</p>

<p><strong>WARNING</strong><br />
Adding an extra, even if the value is false, will activate it. For example <code>{"break-on-newline": false}</code> will activate the <code>break-on-newline</code> extra.</p>

</div>
<div>
<a class="collapse-description-link collapsed" data-toggle="collapse" href="#collapseDescription_markdown_options"
aria-expanded="false" aria-controls="collapseDescriptionmarkdown_options"
></a>
</div>
<a href="#markdown_options" onclick="anchorLink('markdown_options')">markdown_options</a></div><span class="badge badge-dark value-type">Type: object</span> <span class="badge badge-success default-value">Default: {"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "breaks": {"on_newline": true, "on_backslash": true}}</span><br/>
<span class="description"><p>(Only used with <code>description_is_markdown</code>)<br />
<a href="https://github.com/trentm/python-markdown2/wiki/Extras">Markdown 2 options</a> for the descriptions.</p>
</span>



Expand Down
20 changes: 9 additions & 11 deletions docs/examples/examples_md_default/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Configuration parameters can be provided in several ways:
| - [show_toc](#show_toc ) | No | boolean | No | - | Whether to render table of contents. |
| - [examples_as_yaml](#examples_as_yaml ) | No | boolean | No | - | Whether to display examples as YAML instead of JSON |
| - [old_anchor_links](#old_anchor_links ) | No | boolean | No | - | Generate HTML ids for anchor links without special characters (keep only letters, digits, \`_\`, and \`-\`).<br /><br />This is the old behaviour and is only needed for browsers that do not support HTML 5. |
| - [markdown_options](#markdown_options ) | No | object | No | - | [Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions. \`description_is_markdown\` must be true for this to have any effect.<br /><br />**WARNING**<br />Adding an extra, even if the value is false, will activate it. For example \`{"break-on-newline": false}\` will activate the \`break-on-newline\` extra. |
| - [markdown_options](#markdown_options ) | No | object | No | - | (Only used with \`description_is_markdown\`)<br />[Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions. |
| - [template_md_options](#template_md_options ) | No | object | No | - | specific options to md template |
| - [with_footer](#with_footer ) | No | boolean | No | - | Whether to show the footer linking to the library repo and with the generation datetime |
| - [footer_show_time](#footer_show_time ) | No | boolean | No | - | Whether the footer should display the generation time |
Expand Down Expand Up @@ -291,17 +291,15 @@ This is the old behaviour and is only needed for browsers that do not support HT

## <a name="markdown_options"></a>18. Property `JSON Schema for Humans configuration file > markdown_options`

| | |
| ------------------------- | ------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Required** | No |
| **Additional properties** | [[Any type: allowed]](# "Additional Properties of any type are allowed.") |
| **Default** | `{"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "break-on-newline": true}` |
| | |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Required** | No |
| **Additional properties** | [[Any type: allowed]](# "Additional Properties of any type are allowed.") |
| **Default** | `{"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "breaks": {"on_newline": true, "on_backslash": true}}` |

**Description:** [Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions. `description_is_markdown` must be true for this to have any effect.

**WARNING**
Adding an extra, even if the value is false, will activate it. For example `{"break-on-newline": false}` will activate the `break-on-newline` extra.
**Description:** (Only used with `description_is_markdown`)
[Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions.

**Example:**

Expand Down
20 changes: 9 additions & 11 deletions docs/examples/examples_md_nested_default/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,15 @@ This is the old behaviour and is only needed for browsers that do not support HT
</summary>
<blockquote>

| | |
| ------------------------- | ------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Required** | No |
| **Additional properties** | [[Any type: allowed]](# "Additional Properties of any type are allowed.") |
| **Default** | `{"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "break-on-newline": true}` |

**Description:** [Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions. `description_is_markdown` must be true for this to have any effect.

**WARNING**
Adding an extra, even if the value is false, will activate it. For example `{"break-on-newline": false}` will activate the `break-on-newline` extra.
| | |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Required** | No |
| **Additional properties** | [[Any type: allowed]](# "Additional Properties of any type are allowed.") |
| **Default** | `{"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "breaks": {"on_newline": true, "on_backslash": true}}` |

**Description:** (Only used with `description_is_markdown`)
[Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions.

**Example:**

Expand Down
18 changes: 8 additions & 10 deletions docs/examples/examples_md_nested_with_badges/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,14 @@ This is the old behaviour and is only needed for browsers that do not support HT
</summary>
<blockquote>

| | |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Any type: allowed](https://img.shields.io/badge/Any%20type-allowed-green)](# "Additional Properties of any type are allowed.") |
| **Default** | `{"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "break-on-newline": true}` |

**Description:** [Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions. `description_is_markdown` must be true for this to have any effect.

**WARNING**
Adding an extra, even if the value is false, will activate it. For example `{"break-on-newline": false}` will activate the `break-on-newline` extra.
| | |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Any type: allowed](https://img.shields.io/badge/Any%20type-allowed-green)](# "Additional Properties of any type are allowed.") |
| **Default** | `{"fenced-code-blocks": {"cssclass": "highlight jumbotron"}, "tables": null, "breaks": {"on_newline": true, "on_backslash": true}}` |

**Description:** (Only used with `description_is_markdown`)
[Markdown 2 options](https://github.com/trentm/python-markdown2/wiki/Extras) for the descriptions.

**Example:**

Expand Down
Loading

0 comments on commit c0c9d09

Please sign in to comment.