strapdown icon indicating copy to clipboard operation
strapdown copied to clipboard

Load from text file using jquery

Open aemxn opened this issue 9 years ago • 2 comments

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?

aemxn avatar Jun 04 '16 01:06 aemxn

strapdown.js must run after. :/

joedf avatar Jun 05 '16 23:06 joedf

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.

dmelo avatar Jun 29 '16 12:06 dmelo