neutronX / django-markdownx

Comprehensive Markdown plugin built for Django
https://neutronx.github.io/django-markdownx/
Other
863 stars 153 forks source link

Preview not working on outside admin (on frontend) #108

Closed eriktelepovsky closed 6 years ago

eriktelepovsky commented 6 years ago

Hi.

I have successfully configured markdown field and it works fine in the admin:

image

I also use it in my custom form on frontend, but unfortunately, the preview does not work. I can see the requests in the "Network" tab in the Google Chrome Developer Tools and I see the response is correctly returned:

image

I debugged markdown.js file at line 477:

xhr.success = function (response) {
    console.log('success');
    console.log(response);
    properties.preview.innerHTML = response;
    properties.editor = updateHeight(properties.editor);
    utils_1.triggerCustomEvent('markdownx.update', properties.parent, [response]);
};

and the result is, that "response" variable is always null:

image

Any idea what can cause the issue?

pip:

Django==2.0.2
django-markdownx==2.0.22
xenatisch commented 6 years ago

You debugged an intertwined, compiled JavaScript file. The Request class is fine - I wrote it 2 or 3 years ago, and I have since used it in many, many projects. If there is a problem, it's not there; at least not in that method.

eriktelepovsky commented 6 years ago

Any idea where should I look elsewhere? The interesting fact is, the preview works in the Django admin but not on the frontend. But I can see the requests are being fired and the HTTP responses have correct content.

xenatisch commented 6 years ago

You have edited the wrong file. That file will be overwritten the moment someone recompiles the TypeScript file, which is the source code for the part of the API that is written in JavaScript .

That said, I am still unclear what your problem is. Give me a proper outline in the following order:

xenatisch commented 6 years ago

Here is the Request class, and here is the part you edited. It does nothing, until it is assigned to something.

What you need to do is to find out where the potential problem lies in markdownx.ts file.

eriktelepovsky commented 6 years ago

Yes, I understand it will be overwritten, I just wanted to point to the issue. I think it will be easier to demonstrate using screen recording. Please look into my video I just uploaded:

https://youtu.be/UEs6Hurr9BM

Btw. I haven't edited the part you pointed to, I edited the compiled output of this part:

https://github.com/neutronX/django-markdownx/blob/master/static-src/markdownx/js/markdownx.ts#L703

I can't figure out why the original code doesn't work by default in my project.

Thank you.

xenatisch commented 6 years ago

The question is, why is it working in one place, but not the other! Any terminal outputs?

eriktelepovsky commented 6 years ago

Nothing suspicious in output :/ My guess is a conflict with some other JavaScript library I use in my project on the frontend, because your testapp works fine for me. I'll investigate it.

adi- commented 6 years ago

Any updates?

adi- commented 6 years ago

No additional info... closing.