MCPcopy Create free account
hub / github.com/hackmdio/codimd / postProcess

Function postProcess

public/js/extra.js:760–796  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

758
759// only static transform should be here
760export function postProcess (code) {
761 const result = $(`<div>${code}</div>`)
762 // process style tags
763 result.find('style').each((key, value) => {
764 let html = $(value).html()
765 // unescape > symbel inside the style tags
766 html = html.replace(/&gt;/g, '>')
767 // remove css @import to prevent XSS
768 html = html.replace(/@import url\(([^)]*)\);?/gi, '')
769 $(value).html(html)
770 })
771 // link should open in new window or tab
772 // also add noopener to prevent clickjacking
773 // See details: https://mathiasbynens.github.io/rel-noopener/
774 result.find('a:not([href^="#"]):not([target])').attr('target', '_blank').attr('rel', 'noopener')
775 // update continue line numbers
776 const linenumberdivs = result.find('.gutter.linenumber').toArray()
777 for (let i = 0; i < linenumberdivs.length; i++) {
778 if ($(linenumberdivs[i]).hasClass('continue')) {
779 const startnumber = linenumberdivs[i - 1] ? parseInt($(linenumberdivs[i - 1]).find('> span').last().attr('data-linenumber')) : 0
780 $(linenumberdivs[i]).find('> span').each((key, value) => {
781 $(value).attr('data-linenumber', startnumber + key + 1)
782 })
783 }
784 }
785 // show yaml meta paring error
786 if (md.metaError) {
787 var warning = result.find('div#meta-error')
788 if (warning && warning.length > 0) {
789 warning.text(md.metaError)
790 } else {
791 warning = $(`<div id="meta-error" class="alert alert-warning">${escapeHTML(md.metaError)}</div>`)
792 result.prepend(warning)
793 }
794 }
795 return result
796}
797window.postProcess = postProcess
798
799var domevents = Object.getOwnPropertyNames(document).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(Object.getPrototypeOf(document)))).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(window))).filter(function (i) {

Callers 2

pretty.jsFile · 0.90
updateViewInnerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected