atom / markdown-preview

📝 Markdown preview in Atom
MIT License
1.23k stars 358 forks source link

Previewing Markdown Failed #579

Closed jhongiv closed 3 years ago

jhongiv commented 4 years ago

Prerequisites

Description

Steps to Reproduce

Expected behavior:

Actual behavior:

Reproduces how often: always at first time preview. Sometimes second time preview is ok

Versions

Atom 1.47.0 markdown-preview 0.160.2

Additional Information

Previewing Markdown Failed r.trim is not a function

prxg22 commented 4 years ago

I've got the same error on Atom 1.48.0

renemarcelo commented 4 years ago

Sometimes second time preview is ok

I was able to trigger first render only by making a first action on the page (add newline, remove newline; renders correct.)

angela-d commented 4 years ago

This has persisted for the last 3 releases for me. Current: 1.49.0 Debian 9, 4.9.0-12-amd64

markdown-failed

Only stuff in the console log is for ruby aligner, don't see anything particularly related to this.

ghowen commented 4 years ago

It is still broken in Atom 1.49.0 on MacOS 10.15.6 when trying to display the default Jekyll start page.

Bildschirmfoto 2020-07-22 um 17 24 43

@renemarcelo 's tip did work though. Thanks.

beltex commented 4 years ago

Just to update.

Same issue still on Atom 1.50.0 with macOS 10.15.6 and markdown-preview 0.160.2. @renemarcelo's workaround still works though.

j75 commented 4 years ago

Same problem on Atom 1.50.0 on Ubuntu Mate 18.04.

gosukiwi commented 4 years ago

Same here, 1.50.0 on Windows 10

andrewpavlenko commented 4 years ago

Can't reproduce this issue when running atom in dev mode. The only one place where trim() invokes in this extension is here https://github.com/atom/markdown-preview/blob/ae9f2e6e26015379eb138d991e3852b66ff16231/lib/renderer.js#L93 I think the issue may be caused by cherrio or dompurify, but here are no any errors in console output.

gosukiwi commented 4 years ago

Huh, same here. It works when running in dev mode, but in regular mode it crashes with the r.trim error.

Cheerio seems to be up to date, but DOMPurify is at version 1.0.10. Maybe it needs to be upgraded? Still it would be better to track the issue first, I guess.

j75 commented 4 years ago

Yes, I confirm that starting atom --dev <my markdown file> I may correctly display the markdown (my version is 1.51.0 on Ubuntu 20.04). My install says that all packages are updated - and I don't see anything about any cherrio or DOMPurify package (?), how could they be seen if there are installed?

MaxLenormand commented 4 years ago

Same error on 1.51.0 on Ubuntu 18.04

nachoalonso commented 4 years ago

As a workaround, running apm install markdown-preview solved the problem for me.

If you then run apm uninstall markdown-preview you get the error again.

This is strange because apm view markdown-preview shows I am on version 0.160.2 both when running the built-in and the community version of the package.

angela-d commented 4 years ago

I just tried @nachoalonso tip on Debian 10 and it seems to have solved it for me, too!

Very odd! but thanks! :smile:

alehaa commented 3 years ago

However, this seems to trigger the deprecation cop:

You have the core package "markdown-preview" installed as a community package.

DaisySh commented 3 years ago

Weird, but It works for openSUSE Tumbleweed (20201014) and Atom 1.52

webuxr commented 3 years ago

Same issue here "r.trim is not a function" with Atom 1.52.0x64 on MacOS Catalina 10.15.7.

Atom : 1.52.0 Electron: 6.1.12 Chrome : 76.0.3809.146 Node : 12.4.0

Figured I'd subscribe to this thread since I'm now troubleshooting.

webuxr commented 3 years ago

Also, here's the README.md file I was trying to preview when the error appeared. README.txt

Please note, since GitHub does not support uploading .md files, I changed to extension to .txt.

seelphedvr commented 3 years ago

I just had the same problem today, but it only shows when using the shortcut ctrl+shift+M. If I go to Packages>Preview HTML>Enable Preview it works. How odd.

j75 commented 3 years ago

Where do you have that? I only have Packages -> Markdown preview -> Toggle as you may see in the attached screenshot. 2020-11-05_22-22

racciari commented 3 years ago

Same problem on MacOS 10.15.7, Atom 1.52.0 and markdown-preview 0.160.2

wlwl2 commented 3 years ago

https://discuss.atom.io/t/version-1-4-7-and-markdown-preview/74943/16?u=wlwl2

There's a fix for it here. This is only temporary of course. I'm guessing that it's getting confused between Github Flavored Markdown and regular Markdown- I have to emphasize that this is totally a quick guess though.

Toolbar/Packages/markdown and selected Toggle GitHub style

Edit (21 Nov 2020): It's not working well. I have to keep toggling it on and off to fix the error now.

See my latest comment on using another package as a solution (if you don't mind using a non-official package with more features for markdown preview). https://github.com/atom/markdown-preview/issues/579#issuecomment-731472497

webuxr commented 3 years ago

I tried this workaround. While it did work, as @wlwl2 mentioned, its only a temporary fix. I mean, selecting GitHub flavored (styled) markdown does get past the r.trim error (allowing the package to work), this certainly seems to be connected to the package’s theming functionlaity.

j75 commented 3 years ago

There's a workaround though (1.52.0):

  1. you display the markdown file,
  2. then you type (on Linux at least) Ctrl + M to get the preview,
  3. the window is splitted and on the right one (Previewing Markdown Failed) you have the infamous message r.trim is not a function,
  4. now you close the window that shows the markdown file and by magic the preview window shows the markdown correctly rendered!

I also noticed that in my ~/.atom/config.cson file I have

  "markdown-preview":
    useGitHubStyle: true
seelphedvr commented 3 years ago

Mine appears a little further down the list in Packages. I am running Atom in a win10 machine, same version 1.52.0 image

wlwl2 commented 3 years ago

If you don't mind using a better package to view markdown here is a clean fix (for now):

Windows 10.0.19041 Build 19041, Atom Version 1.53.0

  1. Install markdown-preview-plus (v 4.8.4).

  2. It will automatically disable markdown-preview. Just make sure that markdown-preview from Core Packages is disabled.

  3. Change Settings:

Packages that can affect preview rendering:

Change from fonts to *.

I don't consider this optional even though it is, because I want the default atom markdown preview fonts restored.

Preview position synchronization behavior:

Check Sync preview position when text in editor changes.

Check Sync preview position when text editor is scrolled.

Check Sync editor position when preview is scrolled.

These 3 checkboxes are optional, but you should try them out first.

linucks commented 3 years ago

Same issue here: Mac OSX: 10.14.6 Atom: 1.53.0 x86

nikahmadz commented 3 years ago

Same here. Windows 10 Atom: 1.53.0 x64

I need to press Ctrl+Shift+M (three times: error, close, normal)

sjhuskey commented 3 years ago

The message "Previewing Markdown Failed r.trim is not a function" appears the first time I toggle Markdown Preview on, but the second time the content is rendered as expected. The same happens each time I quit Atom and restart it.

Mac 10.15.7 Atom: 1.53.0 x64

eddelbuettel commented 3 years ago

Just for the record, still there with

Ubuntu 20.10 Atom 1.53

and package markdown-preview-plus works around it (thanks, @wlwl2) (but it is odd that it imposes a new CSS..., oh well).

Neustradamus commented 3 years ago

I have the same problem!

sarahbhaskaran commented 3 years ago

I had this problem and it went away when I put spaces between [the pound symbols] and [the header] i.e. instead of ##Title I changed it to ## Title

j75 commented 3 years ago

Same problem on Ubuntu 20.04 and atom 1.54.0 x64 ;-(

chagelstein commented 3 years ago

Right clicking on a file and choosing "Markdown Preview" worked Microsoft Windows [Version 10.0.19042.746] Atom 1.54.0

darkn3rd commented 3 years ago

This reproduces a 100% for what seems like over a year now. Clean install on Ubuntu or macOS, create markdown file (file.md) and preview. If you make a small edit, like adding a space, it then suddenly works.

OS Version

ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H15

Atom Version

Atom    : 1.54.0
Electron: 6.1.12
Chrome  : 76.0.3809.146
Node    : 12.4.0
eddelbuettel commented 3 years ago

IIRC the smal edit is not needed. Just requesting the render twice works the second time.

j75 commented 3 years ago

I confirm (on Ubuntu 20.04 with atom 1.54.0) - not twice but three times! The second time the rendering window closes, and the third time it renders markdown correctly.

madler commented 3 years ago

Still there six months later. Atom 1.54.0, macOS 11.1.

I downloaded this specifically to edit and preview markdown. Entirely useless.

borisbLL commented 3 years ago

I noticed recently this behavior and I didn't have any issue at all before, since my last Desktop setup: I put it out there, maybe it helps somebody else as well with this nasty issue (at least who is running Ubuntu/snaps - maybe @eddelbuettel , @j75 this could be helpful..):

I came to this issue #579 in desperation and ran @nachoalonso workaround with the community package. https://github.com/atom/markdown-preview/issues/579#issuecomment-705827134 worked well but my atom App icon disappeared from the OS bar (that's where I thought about Ubuntu snaps! like "ups I did it again"-style by Britney Spears)..

I am not sure yet why or how and you probably know better, but I believe it may be linked to the way Ubuntu handles snaps and apps confinement - specifically this atom snap.

in /var/lib/snapd/desktop/applications/atom_atom.desktop change Icon=/snap/atom/263/usr/share/pixmaps/atom.png to Icon=/snap/atom/current/usr/share/pixmaps/atom.png

where for me: /snap/atom/263/ was an old snap that was magically deleted by the system :man_shrugging: /snap/atom/270/ was a stale snap /snap/atom/271/ was my latest and current one. /snap/atom/current is a symlink in /snap/atom/ that points to the latest snap running on your system for that app (in my case it was 271).

This did the trick and popped back up the Atom icon.

CTRL+SHIFT+M works again and beautifully (no r.trim error) :tada: :sunglasses:

ah one last note, you may want to consider refreshing your snaps and/or deleting the old stales ones if they are left laying around.

refs (and credits :pray: go to:) @nachoalonso (obviously for his first fix)
@majcherek2048 (for his reply on an old post https://github.com/atom/atom/issues/9667 that sparked the idea that led me to this fix the icon issue @daviwil for his post and explanation on https://github.com/atom/atom/blob/master/packages/dalek/README.md

PS: I know I know! it's not a fix but just another workaround.. I do confide though in the dev community to understand the issue and maybe get it fixed.. let me know if this helped you too..

jhongiv commented 3 years ago

Thank you all for the answers ... I absolutely forgot this issue and now I find so many answers ... I have tried @nachoalonso solution, and it worked when restarting atom ... thank you very much ...

eddelbuettel commented 3 years ago

I don't use the snap (but a standard .deb) and still have the problem so closing this seems premature.

Neustradamus commented 3 years ago

The problem is solved? If not, this issue must not be closed.

eddelbuettel commented 3 years ago

It is not. As I wrote. I can write it again.

Demo

$ echo "## Headline" > testfile.md
$ atom testfile.md 
$ # now pressing Control-M in the editor on `testfile.md`

Result

image

I am not sure how much clearer we can make this.

j75 commented 3 years ago

As a workaround, running apm install markdown-preview solved the problem for me.

Yes, that works for me too (on Ubuntu 20.04 + Atom 1.54.0 x64), but when installing I noticed the following message :

The markdown-preview package is bundled with Atom and should not be explicitly installed.
You can run `apm uninstall markdown-preview` to uninstall it and then the version bundled
with Atom will be used.
Installing markdown-preview to ~/.atom/packages

So I would rather say that there's something wrong with the bundled package...

eddelbuettel commented 3 years ago

I am apparently using the bundled version, which is the one that fails:

$ dpkg -l | grep markdown-preview
$ apm uninstall markdown-preview
Uninstalling markdown-preview ✗
Failed to delete markdown-preview: No package.json found at /home/edd/.atom/packages/markdown-preview/package.json
$ 
eddelbuettel commented 3 years ago

But you are right: doing the opposite of what the message says works:

$ apm uninstall markdown-preview
Uninstalling markdown-preview ✗
Failed to delete markdown-preview: No package.json found at /home/edd/.atom/packages/markdown-preview/package.json
$ apm install markdown-preview
The markdown-preview package is bundled with Atom and should not be explicitly installed.
You can run `apm uninstall markdown-preview` to uninstall it and then the version bundled
with Atom will be used.
Installing markdown-preview to /home/edd/.atom/packages ✓
$

So if we

then things appear to work. At last. Thanks for the help!

j75 commented 3 years ago

For me, this is not solving a bug but just a way of avoiding it!

eddelbuettel commented 3 years ago

Completely agree. It requires an additional installation of the same package rather than, as I had done for a while, of an alternate package (namely markdown-preview-plus). I like the default look better, so this beats hitting C-m three times...

You'd think that someone with the resources of GitHub (and, hence, Microsoft) could fix this eventually...

rugk commented 3 years ago

…cough well, guess GitHub MS has other priorities editors/IDEs now. Apparently…

Guymer commented 3 years ago

I still experience this on 1.54.0 on macOS Big Sur 11.2.1 (why did the ticket get closed?) I too can avoid it by typing a single character and forcing the preview to re-render, but as @j75 said: that is simply avoiding the bug, not fixing it.

rickalex21 commented 3 years ago

This is still a problem, I don't want to use plugins but I think I'm going to have to. This is my first time using atom.

For some strange reason, it started working when I was about to open an issue.