/** markdeep.js Version 0.06 Copyright 2015, Morgan McGuire, http://casual-effects.com All rights reserved. ------------------------------------------------------------- See http://casual-effects.com/markdeep for documentation on how to use this script make your plain text documents render beautifully in web browsers. Markdeep was created by Morgan McGuire. It extends the work of: - John Gruber's original Markdown - Ben Hollis' Maruku Markdown dialect - Michel Fortin's Markdown Extras dialect - Ivan Sagalaev's highlight.js - Contributors to the above open source projects ------------------------------------------------------------- You may use, extend, and redistribute this code under the terms of the BSD license at https://opensource.org/licenses/BSD-2-Clause. and highlight.js(https://github.com/isagalaev/highlight.js) by Ivan Sagalaev, which is used for code highlighting. Each has their respective license with them. */ /** See http://casual-effects.com/markdeep for @license and documentation. markdeep.min.js version 0.05 Copyright 2015, Morgan McGuire All rights reserved. (BSD 2-clause license) highlight.min.js 8.8.0 from https://highlightjs.org/ Copyright 2006, Ivan Sagalaev All rights reserved. (BSD 3-clause license) */ (function() { 'use strict'; // For minification. This is admittedly scary. var _ = String.prototype; _.rp = _.replace; _.ss = _.substring; /** Enable for debugging to view character bounds in diagrams */ var DEBUG_SHOW_GRID = false; /** Overlay the non-empty characters of the original source in diagrams */ var DEBUG_SHOW_SOURCE = DEBUG_SHOW_GRID; /** Use to suppress passing through text in diagrams */ var DEBUG_HIDE_PASSTHROUGH = DEBUG_SHOW_SOURCE; /** In pixels of lines in diagrams */ var STROKE_WIDTH = 2; /** A box of these denotes a diagram */ var DIAGRAM_MARKER = '*'; // http://stackoverflow.com/questions/1877475/repeat-character-n-times var DIAGRAM_START = Array(5 + 1).join(DIAGRAM_MARKER); function entag(tag, content) { return '<' + tag + '>' + content + '' + tag + '>'; } var BODY_STYLESHEET = entag('style', 'body { max-width: 680px;' + 'margin:auto;' + 'padding:20px;' + 'text-align:justify;' + 'line-height:139%; ' + 'color:#222;' + 'font-family: Palatino,Georgia,"Times New Roman",serif;}'); /** You can embed your own stylesheet AFTER the '; var MARKDEEP_FOOTER = '
'; var DEFAULT_OPTIONS = { mode: 'markdeep', detectMath: true }; var max = Math.max; var min = Math.min; /** Get an option, or return the corresponding value from DEFAULT_OPTIONS */ function option(key) { if (window.markdeepOptions && (window.markdeepOptions[key] !== undefined)) { return window.markdeepOptions[key]; } else if (DEFAULT_OPTIONS[key] !== undefined) { return DEFAULT_OPTIONS[key]; } else { console.warn('Illegal option: "' + key + '"'); return undefined; } } /** Converts <>&" to their HTML escape sequences */ function escapeHTMLEntities(str) { return String(str).rp(/&/g, '&').rp(//g, '>').rp(/"/g, '"'); } /** Restores the original source string's '<' and '>' as entered in the document, before the browser processed it as HTML. There is no way in an HTML document to distinguish an entity that was entered as an entity. */ function unescapeHTMLEntities(str) { // Process & last so that we don't recursively unescape // escaped escape sequences. return str. rp(/</g, '<'). rp(/>/g, '>'). rp(/"/g, '"'). rp(/'/g, "'"). rp(/–/g, '--'). rp(/—/g, '---'). rp(/&/g, '&'); } /** Turn the argument into a legal URL anchor */ function mangle(text) { return encodeURI(text.rp(/\s/g, '').toLowerCase()); } /** Creates a style sheet containing elements like: hn::before { content: counter(h1) "." counter(h2) "." ... counter(hn) " "; counter-increment: hn; } */ function sectionNumberingStylesheet() { var s = ''; for (var i = 1; i <= 6; ++i) { s += 'h' + i + '::before {\ncontent:'; for (var j = 1; j <= i; ++j) { s += 'counter(h' + j + ') "' + ((j < i) ? '.' : ' ') + '" '; } s += ';\ncounter-increment: h' + i + ';}'; } return entag('style', s); } /** \param node A node from an HTML DOM \return A String that is a very good reconstruction of what the original source looked like before the browser tried to correct it to legal HTML. */ function nodeToMarkdeep(node, leaveEscapes) { var source = node.innerHTML; // Markdown uses