BenjaminHoegh / ParsedownExtended

ParsedownExtended is an extention for Parsedown, offering additional features and functionalities.
https://benjaminhoegh.github.io/ParsedownExtended
MIT License
37 stars 7 forks source link

Inline math eats newlines #65

Open TheWiseMan opened 6 months ago

TheWiseMan commented 6 months ago

Describe the bug

When using inline math, it breaks the markup after :

$C=(1,0,1,0;)$, $CA=(0,1,0,1;)$, $CA^2=(b,0,a,0;)$, $CA^3=(0,b,0,a;)$

> La matrice d'observabilité s'écrit donc :

image

The same can be observed with lists and titles

Expected Behavior

No response

Code of Conduct

TheWiseMan commented 6 months ago

(just updated to 1.2.7, this issue didn't exist in 1.2.3)

BenjaminHoegh commented 6 months ago

Interesting, I take a look

BenjaminHoegh commented 6 months ago

how does your setting look like?

TheWiseMan commented 6 months ago
$Parser->setSetting('math', [
        'inline' => [
            'delimiters' => [
                //['left' => '\\(', 'right' => '\\)'],
                ['left' => '$', 'right' => '$'],
            ],
            "enabled" => true
        ],
        'block' => [
            'delimiters' => [
                ['left' => '$$', 'right' => '$$'],
                ['left' => '\\begin{equation}', 'right' => '\\end{equation}'],
                ['left' => '\\begin{align}', 'right' => '\\end{align}'],
                ['left' => '\\begin{alignat}', 'right' => '\\end{alignat}'],
                ['left' => '\\begin{gather}', 'right' => '\\end{gather}'],
                ['left' => '\\begin{CD}', 'right' => '\\end{CD}'],
                ['left' => '\\[', 'right' => '\\]'],
            ],
            "enabled" => true
        ],
        "enabled" => true
    ]);

    $Parser->setSetting('diagrams', true);
    $Parser->setSetting('typographer', false);

    $Parser->setSetting('emphasis', [
        'bold' => true,  // Enable bold emphasis
        'italic' => true, // Enable italic emphasis,
        "subscript" => false,
        "superscript" => true,
        // Specify other emphasis styles as needed
    ]);
    $Parser->setSetting('smarty', [
    'substitutions' => [
        'left-double-quote' => '"', // Double bottom quote
        'right-double-quote' => '"', // Double top quote
        "ndash"=> '–',
        "mdash" =>'—',
        "left-single-quote" => "'",
        "right-single-quote" => "'",
        "left-angle-quote" => '«',
        "right-angle-quote" => '»',
        "ellipses"=> "..."
    ],

    "enabled" => true
    ]);

It looks like it does not remove newlines, but math destroys the formatting blocks it's in.

BenjaminHoegh commented 6 months ago

Hmmm can't seem to replicate it. I know that ParsedownExtra has a issue with definitions lists there can break the formatting for all other elements if not 100% correctly typed, but don't know if you have that in your markdown

Skærmbillede 2024-03-16 kl  17 09 58 Skærmbillede 2024-03-16 kl  17 07 42

Also you could use setSettings so you don't need to specify every setting separately

$Parser->setSettings([
  'math' => [
      'inline' => [
          'delimiters' => [
              //['left' => '\\(', 'right' => '\\)'],
              ['left' => '$', 'right' => '$'],
          ],
      ],
      'block' => [
          'delimiters' => [
              ['left' => '$$', 'right' => '$$'],
              ['left' => '\\begin{equation}', 'right' => '\\end{equation}'],
              ['left' => '\\begin{align}', 'right' => '\\end{align}'],
              ['left' => '\\begin{alignat}', 'right' => '\\end{alignat}'],
              ['left' => '\\begin{gather}', 'right' => '\\end{gather}'],
              ['left' => '\\begin{CD}', 'right' => '\\end{CD}'],
              ['left' => '\\[', 'right' => '\\]'],
          ],
      ],
  ],
  'diagrams' => true,
  'typographer' => false,
  'emphasis' => [
      'bold' => true,  // Enable bold emphasis
      'italic' => true, // Enable italic emphasis,
      "subscript" => false,
      "superscript" => true,
  ],
  'smarty' => [
      'substitutions' => [
          'left-double-quote' => '"', // Double bottom quote
          'right-double-quote' => '"', // Double top quote
          "ndash" => '–',
          "mdash" => '—',
          "left-single-quote" => "'",
          "right-single-quote" => "'",
          "left-angle-quote" => '«',
          "right-angle-quote" => '»',
          "ellipses" => "..."
      ],
  ]
]);
TheWiseMan commented 6 months ago

I just found a test case if that helps. It seems to be the fault of block math.

$$Y=ubrace(1,0,1,0;)_CX$$

- $C=(1,0,1,0;)$
- $CA=(0,1,0,1;)$
- $CA^2=(b,0,a,0;)$
- $CA^3=(0,b,0,a;)$

The above breaks but :

- $C=(1,0,1,0;)$
- $CA=(0,1,0,1;)$
- $CA^2=(b,0,a,0;)$
- $CA^3=(0,b,0,a;)$

seems to work.

BenjaminHoegh commented 6 months ago

Should be fixed in 1.2.9

if it continue to give you trouble let me now :)

TheWiseMan commented 6 months ago

Doesn't seem to work, I will avoid math blocks for now. Thanks for your rapid support.

(as a fix I set the double dollar delimiters as inline, and made a change to my js math processor)

BenjaminHoegh commented 6 months ago

Doesn't seem to work, I will avoid math blocks for now. Thanks for your rapid support.

(as a fix I set the double dollar delimiters as inline, and made a change to my js math processor)

So the issue is only present when using single dollar delimiters for inline?

Also just to help me investigate the issue, what PHP version, Parsedown version, ParsedownExnteded are you using? and if you are using ParsedownExtra, what version of that too

TheWiseMan commented 6 months ago

The issue only occurs with the double dollar delimiters for blocks, here are the versions i am using

Isn't the issue a priority problem where the delimiters for inline math are parsed before the delimiters for block math ?