Skip to content

Instantly share code, notes, and snippets.

@V-ed
Last active May 19, 2018 14:48
Show Gist options
  • Save V-ed/68e05155a373aed7e8426ef49d956f7d to your computer and use it in GitHub Desktop.
Save V-ed/68e05155a373aed7e8426ef49d956f7d to your computer and use it in GitHub Desktop.
Makes the <pre> element indent at the level of the children and not at the document's level.
$(function(){
$("pre.code").each(function () {
var html = $(this).html();
var blankLen = (html.split('\n')[0].match(/^[\s\t]+/)[0]).length;
$(this).html($.trim(html.replace(eval("/^[\s\t]{" + blankLen + "}/gm"), "")));
});
});
@V-ed
Copy link
Author

V-ed commented May 19, 2018

This is taken and modified from this StackOverflow answer. Long live StackOverflow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment