Giter Site home page Giter Site logo

Comments (4)

xenatisch avatar xenatisch commented on June 16, 2024

Right, so you want to reinitialise MarkdownX then.

Here's the code that initialises the process when DOM has loaded.

My understanding is that you want to reinitialise this, which means you want to run this part again:

docReady(() => {

    const ELEMENTS = document.getElementsByClassName('markdownx');

    return Object.keys(ELEMENTS).map(key => {

        let element = ELEMENTS[key],
            editor  = element.querySelector('.markdownx-editor'),
            preview = element.querySelector('.markdownx-preview');

        // Only add the new MarkdownX instance to fields that have no MarkdownX instance yet.
        if (!editor.hasAttribute('data-markdownx-init'))
            return new MarkdownX(element, editor, preview)

    });

});

from django-markdownx.

drkane avatar drkane commented on June 16, 2024

I'd also like to do this. When I've tried to replicate something similar to the above I've struggled because MarkdownX isn't available globally when I import static('markdownx/js/markdownx.js') - I think this is due to the way the exports are compiled from typescript.

I've tried everything I can think of to import MarkdownX from markdownx.js into another file and can't get it to work.

One option could be to set "module": "es2015" or similar in the tsconfig.json but not sure if this would have knock on effects elsewhere. See next comment

from django-markdownx.

drkane avatar drkane commented on June 16, 2024

Just done some playing around on a fork of the repository. What worked for me to be able to import MarkdownX was to add -o markdownx to the browserify flags as part of the npm run build:js command. This adds the ability to import as markdownx, with globals.markdownx added if no other import option is available.

I found I could then include static('markdownx/js/markdownx.min.js') and use return new markdownx.MarkdownX(element, editor, preview) to initialise a markdownx field after the DOM had loaded.

I'll do a pull request for the change to the build step - but not sure if this is the right approach.

from django-markdownx.

digitalWestie avatar digitalWestie commented on June 16, 2024

Thanks @xenatisch that approach makes sense 👍

from django-markdownx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.