mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-01 19:15:01 +02:00
Desktop: Fixes #8430: Make HTML <br/> tags convert to markdown compatible with the softbreaks setting (#8469)
This commit is contained in:
parent
c70afe3478
commit
ac66332a4e
10
packages/app-cli/tests/html_to_md/linebreaks.html
Normal file
10
packages/app-cli/tests/html_to_md/linebreaks.html
Normal file
@ -0,0 +1,10 @@
|
||||
<h1>Linebreaks</h1>
|
||||
<div><br>-style linebreaks should be replaced with two spaces followed by a
|
||||
newline.<br/>This allows the generated mark<br/>down to render to equivalent HTML
|
||||
even if the <code>markdown.plugin.softbreaks</code> setting is enabled.</div>
|
||||
<pre class="some-code" style="font-family:monospace;"><br>s shouldn't<br/>lead<br/>to trailing spaces in
|
||||
code
|
||||
however.
|
||||
</pre>
|
||||
<p>Because it isn't</p>
|
||||
<div>necessary.<br/><br/><br/><br/>...</div>
|
21
packages/app-cli/tests/html_to_md/linebreaks.md
Normal file
21
packages/app-cli/tests/html_to_md/linebreaks.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Linebreaks
|
||||
|
||||
<br>-style linebreaks should be replaced with two spaces followed by a newline.
|
||||
This allows the generated mark
|
||||
down to render to equivalent HTML even if the `markdown.plugin.softbreaks` setting is enabled.
|
||||
|
||||
```
|
||||
<br>s shouldn't
|
||||
lead
|
||||
to trailing spaces in
|
||||
code
|
||||
however.
|
||||
```
|
||||
|
||||
Because it isn't
|
||||
|
||||
necessary.
|
||||
|
||||
|
||||
|
||||
...
|
@ -23,7 +23,12 @@ export default class HtmlToMd {
|
||||
bulletListMarker: '-',
|
||||
emDelimiter: '*',
|
||||
strongDelimiter: '**',
|
||||
br: '',
|
||||
|
||||
// If soft-breaks are enabled, lines need to end with two or more spaces for
|
||||
// trailing <br/>s to render. See
|
||||
// https://github.com/laurent22/joplin/issues/8430
|
||||
br: ' ',
|
||||
|
||||
disableEscapeContent: 'disableEscapeContent' in options ? options.disableEscapeContent : false,
|
||||
};
|
||||
if (options.convertEmbeddedPdfsToLinks) {
|
||||
|
@ -33,7 +33,10 @@ rules.lineBreak = {
|
||||
filter: 'br',
|
||||
|
||||
replacement: function (content, node, options) {
|
||||
return options.br + '\n'
|
||||
// Code blocks may include <br/>s -- replacing them should not be necessary
|
||||
// in code blocks.
|
||||
const brReplacement = node.isCode ? '' : options.br;
|
||||
return brReplacement + '\n'
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user