macdown icon indicating copy to clipboard operation
macdown copied to clipboard

$ sign in text causes issues

Open pageaffairs opened this issue 10 years ago • 46 comments

Ran into an odd thing today where if you have two $ signs within your text, the text in between them greys out and MD syntax no longer works visually (it still previews OK). E.g.

Lorem ipsum dolor sit amet $20, consectetur adipisicing elit. Debitis cum blanditiis omnis eligendi repellat.

## Heading

porro quisquam iste sapiente assumenda, dicta, odit libero nihil? Quasi, $50 harum molestias explicabo ullam praesentium soluta.

Produces this:

test

pageaffairs avatar Nov 05 '15 04:11 pageaffairs

Same here with macdown 0.5.2/0.5.3 & Mac OS X 10.11.1

erickyim avatar Nov 08 '15 02:11 erickyim

Using Version 0.5.3 (697) on El Capitan 10.11.1 (15B42). Can confirm this problem.

wenbert avatar Nov 18 '15 01:11 wenbert

It may be confusing it with inline math

See in the preferences -> rendering -> Tex-like math syntax if it's activated as well as the child use dollar sign

laughingrice avatar Nov 18 '15 16:11 laughingrice

@laughingrice Interesting—although those options aren't activated in my case.

pageaffairs avatar Nov 18 '15 22:11 pageaffairs

Unfortunately this is currently not fixable because we are not able to tweak editor highlighting dynamically like the previewing pane. I have been looking for a better syntax highlighter without luck for a while now.

uranusjr avatar Jan 30 '16 11:01 uranusjr

(I submitted the previous comment prematurely.)

A cruel workaround is to make dollar signs escapable, i.e. you can write Apple is \$5. Orange \$4. This is compatible with other Markdown renderers too.

uranusjr avatar Jan 30 '16 11:01 uranusjr

A cruel workaround is to make dollar signs escapable

Heh, not a bad solution, and better than nothing. Thanks for following up. :-)

pageaffairs avatar Jan 30 '16 11:01 pageaffairs

I have also this issue, but escaping the $ doesn't change anything in the Markdown side: macdown-dollar

nhoizey avatar Jan 31 '16 22:01 nhoizey

:+1: on hoping for a fix here...it causes total havoc when trying to document anything in the PHP world :grimacing:

aeromusek avatar Mar 11 '16 18:03 aeromusek

@aeromusek This should be fixed, yes, but I think you’re better off putting code in (inline) code blocks. This will display fine:

Read the `$_POST` to `$me`.

uranusjr avatar Mar 18 '16 00:03 uranusjr

@uranusjr thanks for the follow-up. You're right — it's only fixed when the $ symbol is inside backticks. screen shot 2016-03-17 at 9 21 51 pm

aeromusek avatar Mar 18 '16 01:03 aeromusek

Within code is fine, but the problem is when marking price $ 99.99.

kevinfilteau avatar Mar 18 '16 14:03 kevinfilteau

Like @nhoizey, escaping does not solve the problem for me. I've actually started using the word 'dollars' after the number, when inline, or putting '(in dollars)' after the header for tables.

rupe avatar Jun 01 '16 05:06 rupe

This is very frustrating to me. I have a document created with Mou, which causes the issues described here:

captura de pantalla 2016-08-30 a las 8 33 02

The thing is that if I copy that text into a new file, everything looks good:

captura de pantalla 2016-08-30 a las 8 33 36

The copy paste thing works sometimes. I think it starts to do weird things when there are multiple dollar signs into the same document,

yepes avatar Aug 30 '16 06:08 yepes

I am also experiencing this issue. A lot of the Markdown that I write includes pricing information which makes the documents toggle between colors - somewhat negating the syntax highlighting feature.

Like @nhoizey and @rupe, escaping does not solve the problem for me. Similar to the workaround that @rupe proposed,I have started using USD instead of $ or $ but that is less than ideal.

2016-09-29-macdown

pierow2k avatar Sep 29 '16 15:09 pierow2k

Also experiencing the issue with price information in blog posts I attempt to write with MacDown.

CNG avatar Dec 05 '16 22:12 CNG

I'm experiencing the same issue but I found a workaround.

I'm using the HTML number code $ for $.

alienresident avatar Jan 05 '17 21:01 alienresident

@alienresident — Heh, good solution. :-)

pageaffairs avatar Jan 05 '17 21:01 pageaffairs

So where are we on this? (And by "we", I of course mean "you". ;-) )

Jmuccigr avatar Feb 16 '17 01:02 Jmuccigr

@Jmuccigr I just read through this thread. Among the three approaches:

bare dollar sign

MacDown doesn't work with this, but I don't think it' a good way to write bare dollar sign, because on many Markdown system that supports math with $, this will mess things up. It's difficult to decide whether a dollar sign means "the beginning of math" or "a plain dollar sign", for example in

Do you mean $14 or $40?

and in

Clearly $110_2 = 6_{10}$ (subscript for base in numeral system).

HTML entities

Works perfectly in MacDown, and will surely work in any editor/renderer. The code is not readable though.

escape by backslash

I like this approach and believe MacDown should support this. I didn't research much, but I believe most editors and renderers should work with it. Currently preview pane in MacDown works great, but syntax highlight fails (as noted by @nhoizey). I'm not familiar enough to code to decide whether it belongs to upstream (PEG in this case); I tried their sample Cocoa app, which doesn't seem to highlight math at all.

FranklinYu avatar Feb 16 '17 05:02 FranklinYu

It's interesting to me that the renderer handles it fine (as does pandoc), while the editor doesn't. Clearly there's a fairly good algorithm for determining the difference between currency and math.

That said, surely MacDown should support \ escaping (everywhere?).

Jmuccigr avatar Feb 16 '17 15:02 Jmuccigr

Clearly there's a fairly good algorithm for determining the difference between currency and math.

@Jmuccigr Did you mean the bare dollar sign or the escaped dollar sign?

FranklinYu avatar Feb 17 '17 00:02 FranklinYu

Bare.

Jmuccigr avatar Feb 17 '17 00:02 Jmuccigr

Then the MacDown renderer didn't handles it fine. I'll try Pandoc to see its behavior.

FranklinYu avatar Feb 17 '17 00:02 FranklinYu

Pandoc restrict the conversion to math into

The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math.

Therefore

We know what $ E = m c^2 $ means.

won't work. By Pandoc's choice I guess very few users do this; if that's the case, we can just copy this behavior.

FranklinYu avatar Feb 17 '17 00:02 FranklinYu

I may be confused here. :-) For me, the left side of a MacDown window (the editor, right?) doesn't handle the $ right, but the right side (the renderer, right?) does. This is with the tex-math option checked and $ as inline delimiter checked as well.

The pandoc rule seems pretty good to me. There are some edge cases, but supporting -escaping should handle those.

Jmuccigr avatar Feb 17 '17 02:02 Jmuccigr

That's different from what I saw. My MacDown converts this

Do you mean $14 or $40?

into HTML

<p>Do you mean \(14 or \)40?</p>

which is rendered by MathJax as

dollar-sign

FranklinYu avatar Feb 17 '17 03:02 FranklinYu

Sorry, you're right.

I think I was observing the treatment of multiple $ in the text with tex-math off, not on. There the editor highlights the text, but the renderer leaves it alone.

Jmuccigr avatar Feb 17 '17 04:02 Jmuccigr

BTW, it would be nice if the editor would not do any syntax highlighting when the tex-math option in the prefs is unchecked.

Jmuccigr avatar Feb 17 '17 21:02 Jmuccigr

For what it’s worth, I think the need for a simple $ sign is probably greater than the need for Maths processing.

If I use $ for coding samples (such as for PHP or jQuery), I can wrap the expression in ticks or put it all in a code fence. If not, it shouldn’t be so complicated.

manngo avatar Jun 12 '17 04:06 manngo