arturadib / strapdown

Instant and elegant Markdown documents in the browser
http://strapdownjs.com
MIT License
2.48k stars 410 forks source link

Load from text file using jquery #67

Open aemxn opened 8 years ago

aemxn commented 8 years ago

Hey guys. Is there a way to load markdown plain text from a text file using jquery .get?

Here's my code for reference:

<!doctype html>
<html>
    <div id="article"></div>

<script src="http://strapdownjs.com/v/0.2/strapdown.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $.get("mytextfile.txt", function(data) {
        var markdown = "<xmp theme=\"readable\" style=\"display:none;\">";
        markdown += data;
        markdown += "</xmp>";

        $("#article").html(markdown);
    });
});
</script>
</html>

This doesn't seem to work. Console log returns TypeError: markdownEl is undefined. Any idea how to fix this?

joedf commented 8 years ago

strapdown.js must run after. :/

dmelo commented 8 years ago

Hi. I had a similar issue. So I wrapped strapdown.js into a function that I can call when it is convenient. Here is my fork https://github.com/dmelo/strapdown/tree/dmelo .

Now, you have to call window.strapdown() to make it parse the markdown. I will make a PR as soon as I implement it on a backward compatible way.