Skip to content

Instantly share code, notes, and snippets.

@atomize
Forked from paulirish/data-markdown.user.js
Created March 28, 2019 20:36
Show Gist options
  • Select an option

  • Save atomize/31fba13f3c3c064f07082f1412e29c37 to your computer and use it in GitHub Desktop.

Select an option

Save atomize/31fba13f3c3c064f07082f1412e29c37 to your computer and use it in GitHub Desktop.

Revisions

  1. @paulirish paulirish revised this gist Mar 14, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion data-markdown.user.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    if (!window.Showdown){
    var scr = document.createElement('script');
    scr.onload = boom;
    scr.src = 'https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js';
    scr.src = 'https://cdn.rawgit.com/showdownjs/showdown/master/src/showdown.js';
    document.body.appendChild(scr);
    return;
    }
  2. @paulirish paulirish revised this gist Apr 24, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion data-markdown.user.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@
    [].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){

    // strip leading whitespace so it isn't evaluated as code
    var text = elem.textContent.replace(/\n\s*\n/g,'\n'),
    var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
    // set indentation level so your markdown can be indented within your HTML
    leadingws = text.match(/^\n?(\s*)/)[1].length,
    regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
  3. @paulirish paulirish revised this gist Feb 12, 2012. 2 changed files with 27 additions and 11 deletions.
    32 changes: 22 additions & 10 deletions data-markdown.user.js
    Original file line number Diff line number Diff line change
    @@ -8,17 +8,29 @@

    // If you're not using this as a userscript just delete from this line up. It's cool, homey.

    [].forEach.call( document.querySelectorAll('[data-markdown]'), function(elem){
    (function boom(){

    if (!window.Showdown){
    var scr = document.createElement('script');
    scr.onload = boom;
    scr.src = 'https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js';
    document.body.appendChild(scr);
    return;
    }

    if (!window.Showdown)
    document.write('<script src="https://raw.github.com/github/' +
    'github-flavored-markdown/gh-pages/scripts/showdown.js">\x3C/script>');
    [].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){

    // strip leading whitespace so it isn't evaluated as code
    var text = elem.textContent.replace(/\n\s*\n/g,'\n'),
    // set indentation level so your markdown can be indented within your HTML
    leadingws = text.match(/^\n?(\s*)/)[1].length,
    regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
    md = text.replace(regex,'\n'),
    html = (new Showdown.converter()).makeHtml(md);

    // strip leading whitespace so it isn't evaluated as code
    var md = elem.textContent.replace(/(^\s+)|(\n\s+)/g,'\n')
    , html = (new Showdown.converter()).makeHtml(md);
    // here, have sum HTML
    elem.innerHTML = html;

    // here, have sum HTML
    elem.innerHTML = html;
    });

    });
    }());
    6 changes: 5 additions & 1 deletion example.html
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,8 @@
    * Member of jQuery Team
    * Developer Relations on Google Chrome team
    </section>
    </div>
    </div>



    <script src="data-markdown.user.js"></script>
  4. @paulirish paulirish revised this gist Nov 7, 2011. 2 changed files with 5 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion data-markdown.user.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    // ==/UserScript==


    // this functions well
    // If you're not using this as a userscript just delete from this line up. It's cool, homey.

    [].forEach.call( document.querySelectorAll('[data-markdown]'), function(elem){

    5 changes: 4 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,9 @@ So the idea is you're operating in an HTML environment but a few shortcuts would
    * It automatically adds [github flavored markdown's](https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js) if it's not already in.
    1. Add `data-markdown` attributes to any tags where you're gonna use markdown within. (see example)

    * This script works fine in your page and can also be used as a userscript. Just click the `raw` link right below to install.

    #### Userscript or script-script
    This script works fine in your page and can also be used as a userscript. Just click the `raw` link right below to install.


    _(As this requires some clientside js and can trigger FOUC, this is not for production use)_
  5. @paulirish paulirish revised this gist Nov 7, 2011. 3 changed files with 27 additions and 13 deletions.
    11 changes: 0 additions & 11 deletions data-markdown.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +0,0 @@

    [].forEach.call( document.querySelectorAll('[data-markdown]'), function(elem){

    // strip leading whitespace so it isn't evaluated as code
    var md = elem.textContent.replace(/(^\s+)|(\n\s+)/g,'\n')
    , html = (new Showdown.converter()).makeHtml(md);

    // here, have sum HTML
    elem.innerHTML = html;

    });
    24 changes: 24 additions & 0 deletions data-markdown.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    // ==UserScript==
    // @name Use Markdown, sometimes, in your HTML.
    // @author Paul Irish <http://paulirish.com/>
    // @link http://git.io/data-markdown
    // @match *
    // ==/UserScript==


    // this functions well

    [].forEach.call( document.querySelectorAll('[data-markdown]'), function(elem){

    if (!window.Showdown)
    document.write('<script src="https://raw.github.com/github/' +
    'github-flavored-markdown/gh-pages/scripts/showdown.js">\x3C/script>');

    // strip leading whitespace so it isn't evaluated as code
    var md = elem.textContent.replace(/(^\s+)|(\n\s+)/g,'\n')
    , html = (new Showdown.converter()).makeHtml(md);

    // here, have sum HTML
    elem.innerHTML = html;

    });
    5 changes: 3 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,10 @@ So the idea is you're operating in an HTML environment but a few shortcuts would

    ### To use:

    1. Drop in [github flavored markdown's](https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js) port of showdown.js into the page (after the content, before other scripts).
    1. Add the following script after that.
    1. Add the following script into your HTML after the content, before other scripts
    * It automatically adds [github flavored markdown's](https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js) if it's not already in.
    1. Add `data-markdown` attributes to any tags where you're gonna use markdown within. (see example)

    * This script works fine in your page and can also be used as a userscript. Just click the `raw` link right below to install.

    _(As this requires some clientside js and can trigger FOUC, this is not for production use)_
  6. @paulirish paulirish revised this gist Nov 6, 2011. 2 changed files with 5 additions and 3 deletions.
    1 change: 0 additions & 1 deletion gistfile1.js → data-markdown.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@


    [].forEach.call( document.querySelectorAll('[data-markdown]'), function(elem){

    // strip leading whitespace so it isn't evaluated as code
    7 changes: 5 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,15 @@

    ## I just put some markdown in ur HTML

    In prototypes and HTML-based slide decks, it's pleasant to write in markdown sometimes. (This is not for production use.)
    In prototypes and HTML-based slide decks, it's pleasant to write in markdown sometimes and avoid all those angle brackets.

    So the idea is you're operating in an HTML environment but a few shortcuts would help so use markdown here and there.

    ### To use:

    1. Drop in [github flavored markdown's](https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js) port of showdown.js into the page (after the content, before other scripts).
    1. Add the following script after that.
    1. Add `data-markdown` attributes to any tags where you're gonna use markdown within. (see example)
    1. Add `data-markdown` attributes to any tags where you're gonna use markdown within. (see example)


    _(As this requires some clientside js and can trigger FOUC, this is not for production use)_
  7. @paulirish paulirish created this gist Nov 6, 2011.
    11 changes: 11 additions & 0 deletions example.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <div class="slide">
    <section class="hbox" data-markdown>
    ## Who Am I?

    * Lead developer of [Modernizr](//modernizr.com)
    * Project lead of [HTML5 Boilerplate](//h5bp.com)
    * I curate that [page of polyfills](//bit.ly/polyfills)
    * Member of jQuery Team
    * Developer Relations on Google Chrome team
    </section>
    </div>
    12 changes: 12 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@


    [].forEach.call( document.querySelectorAll('[data-markdown]'), function(elem){

    // strip leading whitespace so it isn't evaluated as code
    var md = elem.textContent.replace(/(^\s+)|(\n\s+)/g,'\n')
    , html = (new Showdown.converter()).makeHtml(md);

    // here, have sum HTML
    elem.innerHTML = html;

    });
    13 changes: 13 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # *[data-markdown]

    ## I just put some markdown in ur HTML

    In prototypes and HTML-based slide decks, it's pleasant to write in markdown sometimes. (This is not for production use.)

    So the idea is you're operating in an HTML environment but a few shortcuts would help so use markdown here and there.

    ### To use:

    1. Drop in [github flavored markdown's](https://raw.github.com/github/github-flavored-markdown/gh-pages/scripts/showdown.js) port of showdown.js into the page (after the content, before other scripts).
    1. Add the following script after that.
    1. Add `data-markdown` attributes to any tags where you're gonna use markdown within. (see example)