Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Initial commit
Ondra Urbanae56569416d4
diff --git a/package.json b/package.jsonindex 2bd4f45ea..0a356e86a 100644--- a/package.json+++ b/package.json@@ -1,100 +1,102 @@{- "name": "apify",- "version": "0.13.0",- "description": "The scalable web crawling and scraping library for JavaScript. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",- "engines": {- "node": ">=8.14.0"- },- "main": "build/index.js",- "keywords": [- "apify",- "headless",- "chrome",- "puppeteer",- "selenium",- "crawler",- "scraper"- ],- "author": {- "name": "Apify",- "email": "[email protected]",- "url": "https://apify.com"- },- "contributors": [- "Jan Curn <[email protected]>",- "Marek Trunkat <[email protected]>",- "Ondra Urban <[email protected]>"- ],- "license": "Apache-2.0",- "repository": {- "type": "git",- "url": "git+https://github.com/apifytech/apify-js"- },- "bugs": {- "url": "https://github.com/apifytech/apify-js/issues"- },- "homepage": "https://sdk.apify.com/",- "files": [- "build"- ],- "scripts": {- "build": "rm -rf ./build && babel src --out-dir build",- "build-docs": "npm run clean && npm run build && node ./website/tools/build_docs.js",- "build-readme": "node ./tools/build_readme.js",- "test": "npm run build && nyc --reporter=html --reporter=text mocha --timeout 60000 --require @babel/register --recursive --exit",- "prepare": "npm run build",- "prepublishOnly": "(test $RUNNING_FROM_SCRIPT || (echo \"You must use publish.sh instead of 'npm publish' directly!\"; exit 1)) && npm test && npm run lint",- "clean": "rm -rf build",- "lint": "npm run build && ./node_modules/.bin/eslint ./src ./test",- "lint:fix": "./node_modules/.bin/eslint ./src ./test --ext .js,.jsx --fix"- },- "dependencies": {- "@apify/ps-tree": "^1.1.3",- "apify-client": "^0.5.7",- "apify-shared": "^0.1.23",- "bluebird": "^3.5.3",- "cheerio": "^1.0.0-rc.2",- "content-type": "^1.0.4",- "fs-extra": "^7.0.1",- "jquery": "^3.3.1",- "mime": "^2.3.1",- "proxy-chain": "^0.2.5",- "request": "^2.88.0",- "request-promise-native": "^1.0.5",- "rimraf": "^2.6.2",- "underscore": "^1.9.1",- "ws": "^6.1.2",- "xregexp": "^4.2.4"- },- "devDependencies": {- "@babel/cli": "^7.0.0",- "@babel/core": "^7.0.0",- "@babel/preset-env": "^7.0.0",- "@babel/register": "^7.0.0",- "basic-auth-parser": "^0.0.2",- "chai": "^4.2.0",- "chai-as-promised": "^7.1.1",- "chai-subset": "^1.6.0",- "eslint": "^5.9.0",- "eslint-config-airbnb": "^17.1.0",- "eslint-config-airbnb-base": "^13.1.0",- "eslint-plugin-import": "^2.14.0",- "eslint-plugin-jsx-a11y": "^6.1.2",- "eslint-plugin-promise": "^4.0.1",- "eslint-plugin-react": "^7.11.1",- "jsdoc": "^3.5.5",- "jsdoc-export-default-interop": "^0.3.1",- "mocha": "^5.2.0",- "nyc": "^13.3.0",- "portastic": "^1.0.1",- "proxy": "^0.2.4",- "sinon": "^7.1.1",- "sinon-stub-promise": "^4.0.0",- "tmp": "^0.0.33",- "why-is-node-running": "^2.0.3"- },- "optionalDependencies": {- "puppeteer": "1.13.0",- "selenium-webdriver": "^3.6.0"- }+ "name": "apify",+ "version": "0.13.0",+ "description": "The scalable web crawling and scraping library for JavaScript. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",+ "engines": {+ "node": ">=8.14.0"+ },+ "main": "build/index.js",+ "keywords": [+ "apify",+ "headless",+ "chrome",+ "puppeteer",+ "selenium",+ "crawler",+ "scraper"+ ],+ "author": {+ "name": "Apify",+ "email": "[email protected]",+ "url": "https://apify.com"+ },+ "contributors": [+ "Jan Curn <[email protected]>",+ "Marek Trunkat <[email protected]>",+ "Ondra Urban <[email protected]>"+ ],+ "license": "Apache-2.0",+ "repository": {+ "type": "git",+ "url": "git+https://github.com/apifytech/apify-js"+ },+ "bugs": {+ "url": "https://github.com/apifytech/apify-js/issues"+ },+ "homepage": "https://sdk.apify.com/",+ "files": [+ "build"+ ],+ "scripts": {+ "build": "rm -rf ./build && babel src --out-dir build",+ "build-docs": "npm run clean && npm run build && node ./website/tools/build_docs.js",+ "build-readme": "node ./tools/build_readme.js",+ "test": "npm run build && nyc --reporter=html --reporter=text mocha --timeout 60000 --require @babel/register --recursive --exit",+ "prepare": "npm run build",+ "prepublishOnly": "(test $RUNNING_FROM_SCRIPT || (echo \"You must use publish.sh instead of 'npm publish' directly!\"; exit 1)) && npm test && npm run lint",+ "clean": "rm -rf build",+ "lint": "npm run build && ./node_modules/.bin/eslint ./src ./test",+ "lint:fix": "./node_modules/.bin/eslint ./src ./test --ext .js,.jsx --fix"+ },+ "dependencies": {+ "@apify/ps-tree": "^1.1.3",+ "apify-client": "^0.5.7",+ "apify-shared": "^0.1.23",+ "bluebird": "^3.5.3",+ "cheerio": "^1.0.0-rc.2",+ "content-type": "^1.0.4",+ "express": "^4.16.4",+ "fs-extra": "^7.0.1",+ "jquery": "^3.3.1",+ "mime": "^2.3.1",+ "proxy-chain": "^0.2.5",+ "request": "^2.88.0",+ "request-promise-native": "^1.0.5",+ "rimraf": "^2.6.2",+ "socket.io": "^2.2.0",+ "underscore": "^1.9.1",+ "ws": "^6.1.2",+ "xregexp": "^4.2.4"+ },+ "devDependencies": {+ "@babel/cli": "^7.0.0",+ "@babel/core": "^7.0.0",+ "@babel/preset-env": "^7.0.0",+ "@babel/register": "^7.0.0",+ "basic-auth-parser": "^0.0.2",+ "chai": "^4.2.0",+ "chai-as-promised": "^7.1.1",+ "chai-subset": "^1.6.0",+ "eslint": "^5.9.0",+ "eslint-config-airbnb": "^17.1.0",+ "eslint-config-airbnb-base": "^13.1.0",+ "eslint-plugin-import": "^2.14.0",+ "eslint-plugin-jsx-a11y": "^6.1.2",+ "eslint-plugin-promise": "^4.0.1",+ "eslint-plugin-react": "^7.11.1",+ "jsdoc": "^3.5.5",+ "jsdoc-export-default-interop": "^0.3.1",+ "mocha": "^5.2.0",+ "nyc": "^13.3.0",+ "portastic": "^1.0.1",+ "proxy": "^0.2.4",+ "sinon": "^7.1.1",+ "sinon-stub-promise": "^4.0.0",+ "tmp": "^0.0.33",+ "why-is-node-running": "^2.0.3"+ },+ "optionalDependencies": {+ "puppeteer": "1.13.0",+ "selenium-webdriver": "^3.6.0"+ }}diff --git a/src/live_view/index.html b/src/live_view/index.htmlnew file mode 100644index 000000000..01a16ab1c--- /dev/null+++ b/src/live_view/index.html@@ -0,0 +1,80 @@+<!doctype html>+<html>+<head>+ <title>Live view</title>+ <style>+ body {+ font-family: sans-serif;+ }+ img#screenshotImg {+ width: 100%+ }+ .urlDiv {+ margin-bottom: 8px;+ }+ </style>+ <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.slim.js"></script>+ <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>+ <script src="./init-last-snapshot.js"></script>+ <link href="./prism.css" rel="stylesheet" />+ <script>+ function showSnapshot(snapshot) {+ if (!snapshot) return;+ $('#pageUrl').text(snapshot.pageUrl).attr('href', snapshot.pageUrl);+ $('#htmlContent').text(snapshot.htmlContent);+ $('#screenshotImg').attr('src', `./screenshot?index=${snapshot.screenshotIndex}`);+ $('#waitContainer').hide();+ $('#snapshotContainer').show();+ Prism.highlightAll();+ }+ $(function () {+ var socket = io();+ socket.on('snapshot', showSnapshot);+ socket.on('connect', function() {+ console.log('Client ID: ' + socket.id);+ });+ // Show initial snapshot obtained from /init-last-snapshot.js+ showSnapshot(window.lastSnapshot);+ $('#screenshotLink').click(function (event) {+ event.preventDefault();+ $('#screenshotDiv').show();+ $('#htmlDiv').hide();+ });+ $('#htmlLink').click(function () {+ event.preventDefault();+ $('#screenshotDiv').hide();+ $('#htmlDiv').show();+ });+ });+ </script>+</head>+<body>++<script src="./prism.js"></script>++<p id="waitContainer">+ Waiting for the snapshot...<br>+ <img src="./loading.gif"/>+</p>++<div id="snapshotContainer" style="display: none">+ <div class="urlDiv">+ URL: <a href="#" id="pageUrl" target="_blank" rel="noopener noreferrer"></a>+ </div>++ <div style="width: 100%">+ <a href="#" id="screenshotLink">Screenshot</a> | <a href="#" id="htmlLink">HTML</a>++ <div id="screenshotDiv">+ <img id="screenshotImg" src="./loading.gif"/>+ </div>++ <div id="htmlDiv" style="display: none; font-size: 13px;">+ <pre><code id="htmlContent" class="language-html"></code></pre>+ </div>+ </div>+</div>+++</body>+</html>diff --git a/src/live_view/live_view_server.js b/src/live_view/live_view_server.jsnew file mode 100644index 000000000..6b097a8a5--- /dev/null+++ b/src/live_view/live_view_server.js@@ -0,0 +1,117 @@+const http = require('http');+const fs = require('fs');+const express = require('express');+const socketio = require('socket.io');+const utils = require('apify-shared/utilities');+const log = require('apify-shared/log');+const { ENV_VARS, LOCAL_ENV_VARS } = require('apify-shared/consts');++const DELETE_SCREENSHOT_FILE_TIMEOUT_MILLIS = 10 * 1000;++class LiveViewServer {+ constructor() {+ const containerPort = process.env[ENV_VARS.CONTAINER_PORT] || LOCAL_ENV_VARS[ENV_VARS.CONTAINER_PORT];++ this.port = parseInt(containerPort, 10);+ if (!(this.port >= 0 && this.port <= 65535)) {+ throw new Error(`Cannot start LiveViewServer - invalid port specified by the ${+ ENV_VARS.CONTAINER_PORT} environment variable (was "${containerPort}").`);+ }+ this.liveViewUrl = process.env[ENV_VARS.CONTAINER_URL] || LOCAL_ENV_VARS[ENV_VARS.CONTAINER_URL];++ // Snapshot data+ this.lastSnapshot = null;+ this.lastScreenshotIndex = 0;+ this.screenshotIndexToFilePath = {};++ // Setup HTTP server and Express router+ this.httpServer = http.createServer();+ this.app = express();++ this.app.use('/', express.static(__dirname));++ // Serves a JS file with the last snapshot, so the the client can immediately show something+ this.app.get('/init-last-snapshot.js', (req, res) => {+ res.set('Content-Type', 'text/javascript');+ res.send(`window.lastSnapshot = ${JSON.stringify(this.lastSnapshot, null, 2)};`);+ });++ // Serves JPEG with the last screenshot+ this.app.get('/screenshot', (req, res) => {+ const screenshotIndex = req.query.index;+ const filePath = this.screenshotIndexToFilePath[screenshotIndex];+ if (!filePath) {+ return res.status(404).send('Oops, there is no such screenshot.');+ }+ // TODO: Limit snapshot sizes to avoid choking the system (was 5MB),+ // return replacement image if too large+ res.sendFile(filePath);+ });++ this.app.all('*', (req, res) => {+ res.status(404).send('Nothing here');+ });++ this.httpServer.on('request', this.app);++ // Socket.io server used to send snapshots to client+ this.clientCount = 0;+ this.socketio = socketio(this.httpServer);+ this.socketio.on('connection', (socket) => {+ this.clientCount++;+ log.info('Live view client connected', { clientId: socket.id });+ socket.on('disconnect', (reason) => {+ this.clientCount--;+ log.info('Live view client disconnected', { clientId: socket.id, reason });+ });+ });+ }++ /**+ * Starts the HTTP server.+ */+ async start() {+ await utils.promisifyServerListen(this.httpServer)(this.port);+ log.info('Live view web server started', { publicUrl: this.liveViewUrl });+ }++ /**+ * To be called when the snapshot of screen and HTML content was saved.+ */+ async pushSnapshot(screenshotFilePath, htmlContent, pageUrl) {+ log.info('LiveViewServer.pushSnapshot()', { pageUrl });++ const prevScreenshotIndex = this.lastScreenshotIndex;++ this.lastScreenshotIndex++;+ this.lastSnapshot = {+ pageUrl,+ htmlContent,+ screenshotIndex: this.lastScreenshotIndex+ };+ this.screenshotIndexToFilePath[this.lastScreenshotIndex] = screenshotFilePath;++ // Send new snapshot to clients+ log.info('Sending live view snapshot', { snapshot: this.lastSnapshot });+ this.socketio.emit('snapshot', this.lastSnapshot);++ // Delete screenshot after a while, maybe some client still wants to download it+ const prevFilePath = this.screenshotIndexToFilePath[prevScreenshotIndex];+ if (prevFilePath) {+ setTimeout(() => {+ delete this.screenshotIndexToFilePath[prevScreenshotIndex];+ log.debug('Deleting screenshot', { path: prevFilePath });+ fs.unlink(prevFilePath, (err) => {+ if (err) log.exception(err, 'Cannot delete file', { path: prevFilePath });+ });+ }, DELETE_SCREENSHOT_FILE_TIMEOUT_MILLIS);+ }+ };++ hasClients() {+ return this.clientCount > 0;+ }+}+++module.exports = LiveViewServer;diff --git a/src/live_view/loading.gif b/src/live_view/loading.gifnew file mode 100644index 000000000..0424aa4ffBinary files /dev/null and b/src/live_view/loading.gif differdiff --git a/src/live_view/prism.css b/src/live_view/prism.cssnew file mode 100644index 000000000..742f8bbc1--- /dev/null+++ b/src/live_view/prism.css@@ -0,0 +1,140 @@+/* PrismJS 1.15.0+https://prismjs.com/download.html#themes=prism&languages=markup */+/**+ * prism.js default theme for JavaScript, CSS and HTML+ * Based on dabblet (http://dabblet.com)+ * @author Lea Verou+ */++code[class*="language-"],+pre[class*="language-"] {+ color: black;+ background: none;+ text-shadow: 0 1px white;+ font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;+ text-align: left;+ white-space: pre;+ word-spacing: normal;+ word-break: normal;+ word-wrap: normal;+ line-height: 1.5;++ -moz-tab-size: 4;+ -o-tab-size: 4;+ tab-size: 4;++ -webkit-hyphens: none;+ -moz-hyphens: none;+ -ms-hyphens: none;+ hyphens: none;+}++pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,+code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {+ text-shadow: none;+ background: #b3d4fc;+}++pre[class*="language-"]::selection, pre[class*="language-"] ::selection,+code[class*="language-"]::selection, code[class*="language-"] ::selection {+ text-shadow: none;+ background: #b3d4fc;+}++@media print {+ code[class*="language-"],+ pre[class*="language-"] {+ text-shadow: none;+ }+}++/* Code blocks */+pre[class*="language-"] {+ padding: 1em;+ margin: .5em 0;+ overflow: auto;+}++:not(pre) > code[class*="language-"],+pre[class*="language-"] {+ background: #f5f2f0;+}++/* Inline code */+:not(pre) > code[class*="language-"] {+ padding: .1em;+ border-radius: .3em;+ white-space: normal;+}++.token.comment,+.token.prolog,+.token.doctype,+.token.cdata {+ color: slategray;+}++.token.punctuation {+ color: #999;+}++.namespace {+ opacity: .7;+}++.token.property,+.token.tag,+.token.boolean,+.token.number,+.token.constant,+.token.symbol,+.token.deleted {+ color: #905;+}++.token.selector,+.token.attr-name,+.token.string,+.token.char,+.token.builtin,+.token.inserted {+ color: #690;+}++.token.operator,+.token.entity,+.token.url,+.language-css .token.string,+.style .token.string {+ color: #9a6e3a;+ background: hsla(0, 0%, 100%, .5);+}++.token.atrule,+.token.attr-value,+.token.keyword {+ color: #07a;+}++.token.function,+.token.class-name {+ color: #DD4A68;+}++.token.regex,+.token.important,+.token.variable {+ color: #e90;+}++.token.important,+.token.bold {+ font-weight: bold;+}+.token.italic {+ font-style: italic;+}++.token.entity {+ cursor: help;+}diff --git a/src/live_view/prism.js b/src/live_view/prism.jsnew file mode 100644index 000000000..f41b0c15f--- /dev/null+++ b/src/live_view/prism.js@@ -0,0 +1,4 @@+/* PrismJS 1.15.0+https://prismjs.com/download.html#themes=prism&languages=markup */+var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(e){function t(e,t,a,n,r){this.type=e,this.content=t,this.alias=a,this.length=0|(n||"").length,this.greedy=!!r}var a=/\blang(?:uage)?-([\w-]+)\b/i,n=0,r={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function(e){return e instanceof t?new t(e.type,r.util.encode(e.content),e.alias):"Array"===r.util.type(e)?e.map(r.util.encode):e.replace(/&/g,"&").replace(/</g,"<").replace(/\u00a0/g," ")},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++n}),e.__id},clone:function l(e,t){var a,n,i=r.util.type(e);switch(t=t||{},i){case"Object":if(n=r.util.objId(e),t[n])return t[n];a={},t[n]=a;for(var o in e)e.hasOwnProperty(o)&&(a[o]=l(e[o],t));return a;case"Array":return n=r.util.objId(e),t[n]?t[n]:(a=[],t[n]=a,e.forEach(function(e,n){a[n]=l(e,t)}),a);default:return e}}},languages:{extend:function(e,t){var a=r.util.clone(r.languages[e]);for(var n in t)a[n]=t[n];return a},insertBefore:function(e,t,a,n){n=n||r.languages;var i=n[e],l={};for(var o in i)if(i.hasOwnProperty(o)){if(o==t)for(var s in a)a.hasOwnProperty(s)&&(l[s]=a[s]);a.hasOwnProperty(o)||(l[o]=i[o])}var u=n[e];return n[e]=l,r.languages.DFS(r.languages,function(t,a){a===u&&t!=e&&(this[t]=l)}),l},DFS:function o(e,t,a,n){n=n||{};var i=r.util.objId;for(var l in e)if(e.hasOwnProperty(l)){t.call(e,l,e[l],a||l);var s=e[l],u=r.util.type(s);"Object"!==u||n[i(s)]?"Array"!==u||n[i(s)]||(n[i(s)]=!0,o(s,t,l,n)):(n[i(s)]=!0,o(s,t,null,n))}}},plugins:{},highlightAll:function(e,t){r.highlightAllUnder(document,e,t)},highlightAllUnder:function(e,t,a){var n={callback:a,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};r.hooks.run("before-highlightall",n);for(var i,l=n.elements||e.querySelectorAll(n.selector),o=0;i=l[o++];)r.highlightElement(i,t===!0,n.callback)},highlightElement:function(t,n,i){for(var l,o,s=t;s&&!a.test(s.className);)s=s.parentNode;s&&(l=(s.className.match(a)||[,""])[1].toLowerCase(),o=r.languages[l]),t.className=t.className.replace(a,"").replace(/\s+/g," ")+" language-"+l,t.parentNode&&(s=t.parentNode,/pre/i.test(s.nodeName)&&(s.className=s.className.replace(a,"").replace(/\s+/g," ")+" language-"+l));var u=t.textContent,g={element:t,language:l,grammar:o,code:u},c=function(e){g.highlightedCode=e,r.hooks.run("before-insert",g),g.element.innerHTML=g.highlightedCode,r.hooks.run("after-highlight",g),r.hooks.run("complete",g),i&&i.call(g.element)};if(r.hooks.run("before-sanity-check",g),!g.code)return r.hooks.run("complete",g),void 0;if(r.hooks.run("before-highlight",g),!g.grammar)return c(r.util.encode(g.code)),void 0;if(n&&e.Worker){var h=new Worker(r.filename);h.onmessage=function(e){c(e.data)},h.postMessage(JSON.stringify({language:g.language,code:g.code,immediateClose:!0}))}else c(r.highlight(g.code,g.grammar,g.language))},highlight:function(e,a,n){var i={code:e,grammar:a,language:n};return r.hooks.run("before-tokenize",i),i.tokens=r.tokenize(i.code,i.grammar),r.hooks.run("after-tokenize",i),t.stringify(r.util.encode(i.tokens),i.language)},matchGrammar:function(e,a,n,i,l,o,s){for(var u in n)if(n.hasOwnProperty(u)&&n[u]){if(u==s)return;var g=n[u];g="Array"===r.util.type(g)?g:[g];for(var c=0;c<g.length;++c){var h=g[c],d=h.inside,f=!!h.lookbehind,p=!!h.greedy,m=0,y=h.alias;if(p&&!h.pattern.global){var v=h.pattern.toString().match(/[imuy]*$/)[0];h.pattern=RegExp(h.pattern.source,v+"g")}h=h.pattern||h;for(var k=i,b=l;k<a.length;b+=a[k].length,++k){var w=a[k];if(a.length>e.length)return;if(!(w instanceof t)){if(p&&k!=a.length-1){h.lastIndex=b;var A=h.exec(e);if(!A)break;for(var P=A.index+(f?A[1].length:0),O=A.index+A[0].length,x=k,N=b,j=a.length;j>x&&(O>N||!a[x].type&&!a[x-1].greedy);++x)N+=a[x].length,P>=N&&(++k,b=N);if(a[k]instanceof t)continue;S=x-k,w=e.slice(b,N),A.index-=b}else{h.lastIndex=0;var A=h.exec(w),S=1}if(A){f&&(m=A[1]?A[1].length:0);var P=A.index+m,A=A[0].slice(m),O=P+A.length,E=w.slice(0,P),_=w.slice(O),C=[k,S];E&&(++k,b+=E.length,C.push(E));var M=new t(u,d?r.tokenize(A,d):A,y,A,p);if(C.push(M),_&&C.push(_),Array.prototype.splice.apply(a,C),1!=S&&r.matchGrammar(e,a,n,k,b,!0,u),o)break}else if(o)break}}}}},tokenize:function(e,t){var a=[e],n=t.rest;if(n){for(var i in n)t[i]=n[i];delete t.rest}return r.matchGrammar(e,a,t,0,0,!1),a},hooks:{all:{},add:function(e,t){var a=r.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=r.hooks.all[e];if(a&&a.length)for(var n,i=0;n=a[i++];)n(t)}},Token:t};if(e.Prism=r,t.stringify=function(e,a,n){if("string"==typeof e)return e;if("Array"===r.util.type(e))return e.map(function(n){return t.stringify(n,a,e)}).join("");var i={type:e.type,content:t.stringify(e.content,a,n),tag:"span",classes:["token",e.type],attributes:{},language:a,parent:n};if(e.alias){var l="Array"===r.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(i.classes,l)}r.hooks.run("wrap",i);var o=Object.keys(i.attributes).map(function(e){return e+'="'+(i.attributes[e]||"").replace(/"/g,""")+'"'}).join(" ");return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+(o?" "+o:"")+">"+i.content+"</"+i.tag+">"},!e.document)return e.addEventListener?(r.disableWorkerMessageHandler||e.addEventListener("message",function(t){var a=JSON.parse(t.data),n=a.language,i=a.code,l=a.immediateClose;e.postMessage(r.highlight(i,r.languages[n],n)),l&&e.close()},!1),r):r;var i=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return i&&(r.filename=i.src,r.manual||i.hasAttribute("data-manual")||("loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(r.highlightAll):window.setTimeout(r.highlightAll,16):document.addEventListener("DOMContentLoaded",r.highlightAll))),r}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism);+Prism.languages.markup={comment:/<!--[\s\S]*?-->/,prolog:/<\?[\s\S]+?\?>/,doctype:/<!DOCTYPE[\s\S]+?>/i,cdata:/<!\[CDATA\[[\s\S]*?]]>/i,tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s\/>])))+)?\s*\/?>/i,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i,inside:{punctuation:[/^=/,{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.languages.markup.tag.inside["attr-value"].inside.entity=Prism.languages.markup.entity,Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Prism.languages.xml=Prism.languages.extend("markup",{}),Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup;