├── .babelrc ├── test ├── tests-entry.js ├── webpack.config.js └── richtext.spec.js ├── .travis.yml ├── src ├── index.js └── richtext.js ├── bower.json ├── package.json ├── webpack.config.js ├── .npmignore ├── .gitignore ├── README.md └── dist ├── prismic-dom.min.js └── prismic-dom.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } -------------------------------------------------------------------------------- /test/tests-entry.js: -------------------------------------------------------------------------------- 1 | const context = require.context('./', true, /\.spec\.js$/); 2 | context.keys().forEach(context); 3 | module.exports = context; 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '10' 4 | - '12' 5 | - '13' 6 | - '14' 7 | os: 8 | - linux 9 | before_script: 10 | - yarn test 11 | script: 12 | - yarn run build 13 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const PrismicHelpers = require('@prismicio/helpers'); 2 | const RichText = require('./richtext'); 3 | 4 | const { Date, Link } = PrismicHelpers 5 | 6 | module.exports = { 7 | Date, 8 | Link, 9 | RichText, 10 | } 11 | -------------------------------------------------------------------------------- /test/webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const path = require('path'); 3 | 4 | const config = { 5 | entry: path.resolve(__dirname, 'tests-entry'), 6 | output: { 7 | path: path.resolve(__dirname, '..', 'test-build'), 8 | filename: 'test-bundle.js' 9 | }, 10 | target: 'node', 11 | }; 12 | 13 | module.exports = config; 14 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prismic-dom", 3 | "description": "render prismic json fragments in HTML", 4 | "main": "dist/prismic-dom.min.js", 5 | "license": "ISC", 6 | "homepage": "https://github.com/prismicio/prismic-dom", 7 | "ignore": [ 8 | "**/.*", 9 | "node_modules", 10 | "bower_components", 11 | "test", 12 | "tests" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prismic-dom", 3 | "version": "2.2.7", 4 | "description": "Set of helpers to manage Prismic data", 5 | "main": "dist/prismic-dom.min.js", 6 | "scripts": { 7 | "build": "webpack --debug && webpack -p", 8 | "dev": "webpack -d --watch", 9 | "prepublish": "npm run build", 10 | "pretest": "webpack --config test/webpack.config.js", 11 | "test": "mocha test-build/test-bundle.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/prismicio/prismic-dom.git" 16 | }, 17 | "author": "Prismic (https://prismic.io)", 18 | "license": "Apache-2.0", 19 | "bugs": { 20 | "url": "https://github.com/prismicio/prismic-dom/issues" 21 | }, 22 | "homepage": "https://github.com/prismicio/prismic-dom#readme", 23 | "dependencies": { 24 | "@prismicio/helpers": "^1.0.4", 25 | "@prismicio/richtext": "^1.1.0", 26 | "escape-html": "1.0.3" 27 | }, 28 | "devDependencies": { 29 | "@babel/core": "^7.9.0", 30 | "@babel/preset-env": "^7.9.5", 31 | "babel-loader": "^8.1.0", 32 | "chai": "^4.2.0", 33 | "mocha": "^7.0.1", 34 | "webpack": "^4.42.1", 35 | "webpack-cli": "^3.3.11", 36 | "yargs": "^15.1.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'), 2 | path = require('path'), 3 | yargs = require('yargs'); 4 | 5 | var libraryName = 'PrismicDOM', 6 | fileName = 'prismic-dom', 7 | plugins = [], 8 | outputFile; 9 | 10 | if (yargs.argv.p) { 11 | outputFile = fileName + '.min.js'; 12 | } else { 13 | outputFile = fileName + '.js'; 14 | } 15 | 16 | var config = { 17 | target: 'node', 18 | entry: [ 19 | __dirname + '/src/index.js' 20 | ], 21 | output: { 22 | path: path.join(__dirname, '/dist'), 23 | filename: outputFile, 24 | library: libraryName, 25 | libraryTarget: 'umd', 26 | umdNamedDefine: true, 27 | globalObject: 'typeof self !== \'undefined\' ? self : this' 28 | }, 29 | module: { 30 | rules: [ 31 | { 32 | test: /\.js$/, 33 | exclude: /(node_modules|bower_components)/, 34 | use: { 35 | loader: 'babel-loader' 36 | } 37 | }, 38 | { 39 | test: /\.json$/, 40 | use: 'json-loader' 41 | } 42 | ] 43 | }, 44 | resolve: { 45 | alias:{ 46 | "@root": path.resolve( __dirname, './src' ) 47 | }, 48 | extensions: ['.js'] 49 | }, 50 | mode: yargs.argv.p ? 'production' : 'development', 51 | plugins: plugins, 52 | optimization: { minimize: !!yargs.argv.p }, 53 | }; 54 | 55 | module.exports = config; 56 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/node,macos,intellij,visualstudiocode 2 | 3 | ### Intellij ### 4 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 5 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 6 | 7 | # User-specific stuff: 8 | .idea/**/workspace.xml 9 | .idea/**/tasks.xml 10 | .idea/dictionaries 11 | 12 | # Sensitive or high-churn files: 13 | .idea/**/dataSources/ 14 | .idea/**/dataSources.ids 15 | .idea/**/dataSources.xml 16 | .idea/**/dataSources.local.xml 17 | .idea/**/sqlDataSources.xml 18 | .idea/**/dynamic.xml 19 | .idea/**/uiDesigner.xml 20 | 21 | # Gradle: 22 | .idea/**/gradle.xml 23 | .idea/**/libraries 24 | 25 | # CMake 26 | cmake-build-debug/ 27 | 28 | # Mongo Explorer plugin: 29 | .idea/**/mongoSettings.xml 30 | 31 | ## File-based project format: 32 | *.iws 33 | 34 | ## Plugin-specific files: 35 | 36 | # IntelliJ 37 | /out/ 38 | 39 | # mpeltonen/sbt-idea plugin 40 | .idea_modules/ 41 | 42 | # JIRA plugin 43 | atlassian-ide-plugin.xml 44 | 45 | # Cursive Clojure plugin 46 | .idea/replstate.xml 47 | 48 | # Crashlytics plugin (for Android Studio and IntelliJ) 49 | com_crashlytics_export_strings.xml 50 | crashlytics.properties 51 | crashlytics-build.properties 52 | fabric.properties 53 | 54 | ### Intellij Patch ### 55 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 56 | 57 | # *.iml 58 | # modules.xml 59 | # .idea/misc.xml 60 | # *.ipr 61 | 62 | # Sonarlint plugin 63 | .idea/sonarlint 64 | 65 | ### macOS ### 66 | *.DS_Store 67 | .AppleDouble 68 | .LSOverride 69 | 70 | # Icon must end with two \r 71 | Icon 72 | 73 | # Thumbnails 74 | ._* 75 | 76 | # Files that might appear in the root of a volume 77 | .DocumentRevisions-V100 78 | .fseventsd 79 | .Spotlight-V100 80 | .TemporaryItems 81 | .Trashes 82 | .VolumeIcon.icns 83 | .com.apple.timemachine.donotpresent 84 | 85 | # Directories potentially created on remote AFP share 86 | .AppleDB 87 | .AppleDesktop 88 | Network Trash Folder 89 | Temporary Items 90 | .apdisk 91 | 92 | ### Node ### 93 | # Logs 94 | logs 95 | *.log 96 | npm-debug.log* 97 | yarn-debug.log* 98 | yarn-error.log* 99 | 100 | # Runtime data 101 | pids 102 | *.pid 103 | *.seed 104 | *.pid.lock 105 | 106 | # Directory for instrumented libs generated by jscoverage/JSCover 107 | lib-cov 108 | 109 | # Coverage directory used by tools like istanbul 110 | coverage 111 | 112 | # nyc test coverage 113 | .nyc_output 114 | 115 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 116 | .grunt 117 | 118 | # Bower dependency directory (https://bower.io/) 119 | bower_components 120 | 121 | # node-waf configuration 122 | .lock-wscript 123 | 124 | # Compiled binary addons (http://nodejs.org/api/addons.html) 125 | build/Release 126 | 127 | # Dependency directories 128 | node_modules/ 129 | jspm_packages/ 130 | 131 | # Typescript v1 declaration files 132 | typings/ 133 | 134 | # Optional npm cache directory 135 | .npm 136 | 137 | # Optional eslint cache 138 | .eslintcache 139 | 140 | # Optional REPL history 141 | .node_repl_history 142 | 143 | # Output of 'npm pack' 144 | *.tgz 145 | 146 | # Yarn Integrity file 147 | .yarn-integrity 148 | 149 | # dotenv environment variables file 150 | .env 151 | 152 | 153 | ### VisualStudioCode ### 154 | .vscode/* 155 | !.vscode/settings.json 156 | !.vscode/tasks.json 157 | !.vscode/launch.json 158 | !.vscode/extensions.json 159 | 160 | # End of https://www.gitignore.io/api/node,macos,intellij,visualstudiocode -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ############################ 2 | 3 | # Created by https://www.gitignore.io/api/node,macos,intellij,visualstudiocode 4 | 5 | ### Intellij ### 6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 7 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 8 | 9 | # User-specific stuff: 10 | .idea/**/workspace.xml 11 | .idea/**/tasks.xml 12 | .idea/dictionaries 13 | 14 | # Sensitive or high-churn files: 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.xml 18 | .idea/**/dataSources.local.xml 19 | .idea/**/sqlDataSources.xml 20 | .idea/**/dynamic.xml 21 | .idea/**/uiDesigner.xml 22 | 23 | # Gradle: 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # CMake 28 | cmake-build-debug/ 29 | 30 | # Mongo Explorer plugin: 31 | .idea/**/mongoSettings.xml 32 | 33 | ## File-based project format: 34 | *.iws 35 | 36 | ## Plugin-specific files: 37 | 38 | # IntelliJ 39 | /out/ 40 | 41 | # mpeltonen/sbt-idea plugin 42 | .idea_modules/ 43 | 44 | # JIRA plugin 45 | atlassian-ide-plugin.xml 46 | 47 | # Cursive Clojure plugin 48 | .idea/replstate.xml 49 | 50 | # Crashlytics plugin (for Android Studio and IntelliJ) 51 | com_crashlytics_export_strings.xml 52 | crashlytics.properties 53 | crashlytics-build.properties 54 | fabric.properties 55 | 56 | ### Intellij Patch ### 57 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 58 | 59 | # *.iml 60 | # modules.xml 61 | # .idea/misc.xml 62 | # *.ipr 63 | 64 | # Sonarlint plugin 65 | .idea/sonarlint 66 | 67 | ### macOS ### 68 | *.DS_Store 69 | .AppleDouble 70 | .LSOverride 71 | 72 | # Icon must end with two \r 73 | Icon 74 | 75 | # Thumbnails 76 | ._* 77 | 78 | # Files that might appear in the root of a volume 79 | .DocumentRevisions-V100 80 | .fseventsd 81 | .Spotlight-V100 82 | .TemporaryItems 83 | .Trashes 84 | .VolumeIcon.icns 85 | .com.apple.timemachine.donotpresent 86 | 87 | # Directories potentially created on remote AFP share 88 | .AppleDB 89 | .AppleDesktop 90 | Network Trash Folder 91 | Temporary Items 92 | .apdisk 93 | 94 | ### Node ### 95 | # Logs 96 | logs 97 | *.log 98 | npm-debug.log* 99 | yarn-debug.log* 100 | yarn-error.log* 101 | 102 | # Runtime data 103 | pids 104 | *.pid 105 | *.seed 106 | *.pid.lock 107 | 108 | # Directory for instrumented libs generated by jscoverage/JSCover 109 | lib-cov 110 | 111 | # Coverage directory used by tools like istanbul 112 | coverage 113 | 114 | # nyc test coverage 115 | .nyc_output 116 | 117 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 118 | .grunt 119 | 120 | # Bower dependency directory (https://bower.io/) 121 | bower_components 122 | 123 | # node-waf configuration 124 | .lock-wscript 125 | 126 | # Compiled binary addons (http://nodejs.org/api/addons.html) 127 | build/Release 128 | 129 | # Dependency directories 130 | node_modules/ 131 | jspm_packages/ 132 | 133 | # Typescript v1 declaration files 134 | typings/ 135 | 136 | # Optional npm cache directory 137 | .npm 138 | 139 | # Optional eslint cache 140 | .eslintcache 141 | 142 | # Optional REPL history 143 | .node_repl_history 144 | 145 | # Output of 'npm pack' 146 | *.tgz 147 | 148 | # Yarn Integrity file 149 | .yarn-integrity 150 | 151 | # dotenv environment variables file 152 | .env 153 | 154 | 155 | ### VisualStudioCode ### 156 | .vscode/* 157 | !.vscode/settings.json 158 | !.vscode/tasks.json 159 | !.vscode/launch.json 160 | !.vscode/extensions.json 161 | 162 | # End of https://www.gitignore.io/api/node,macos,intellij,visualstudiocode 163 | 164 | # Test build 165 | test-build/ 166 | -------------------------------------------------------------------------------- /src/richtext.js: -------------------------------------------------------------------------------- 1 | const PrismicRichText = require('@prismicio/richtext'); 2 | const { Link: LinkHelper } = require('@prismicio/helpers'); 3 | const escapeHtml = require('escape-html'); 4 | 5 | const { Elements } = PrismicRichText; 6 | 7 | function serialize(linkResolver, type, element, content, children) { 8 | switch(type) { 9 | case Elements.heading1: return serializeStandardTag('h1', element, children); 10 | case Elements.heading2: return serializeStandardTag('h2', element, children); 11 | case Elements.heading3: return serializeStandardTag('h3', element, children); 12 | case Elements.heading4: return serializeStandardTag('h4', element, children); 13 | case Elements.heading5: return serializeStandardTag('h5', element, children); 14 | case Elements.heading6: return serializeStandardTag('h6', element, children); 15 | case Elements.paragraph: return serializeStandardTag('p', element, children); 16 | case Elements.preformatted: return serializePreFormatted(element); 17 | case Elements.strong: return serializeStandardTag('strong', element, children); 18 | case Elements.em: return serializeStandardTag('em', element, children); 19 | case Elements.listItem: return serializeStandardTag('li', element, children); 20 | case Elements.oListItem: return serializeStandardTag('li', element, children); 21 | case Elements.list: return serializeStandardTag('ul', element, children); 22 | case Elements.oList: return serializeStandardTag('ol', element, children); 23 | case Elements.image: return serializeImage(linkResolver, element); 24 | case Elements.embed: return serializeEmbed(element); 25 | case Elements.hyperlink: return serializeHyperlink(linkResolver, element, children); 26 | case Elements.label: return serializeLabel(element, children); 27 | case Elements.span: return serializeSpan(content); 28 | default: return ''; 29 | } 30 | } 31 | 32 | function label(element) { 33 | return element.label ? ` class="${element.label}"` : ''; 34 | } 35 | 36 | function serializeStandardTag(tag, element, children) { 37 | return `<${tag}${label(element)}>${children.join('')}`; 38 | } 39 | 40 | function serializePreFormatted(element) { 41 | return `${escapeHtml(element.text)}`; 42 | } 43 | 44 | function serializeImage(linkResolver, element) { 45 | const linkUrl = element.linkTo ? LinkHelper.url(element.linkTo, linkResolver) : null; 46 | const linkTarget = element.linkTo && element.linkTo.target ? `target="${element.linkTo.target}" rel="noopener"` : ''; 47 | const wrapperClassList = [element.label || '', 'block-img']; 48 | const img = `${element.alt ? escapeHtml(element.alt) : ''}`; 49 | 50 | return (` 51 |

52 | ${linkUrl ? `${img}` : img} 53 |

54 | `); 55 | } 56 | 57 | function serializeEmbed(element) { 58 | return (` 59 |
63 | 64 | ${element.oembed.html} 65 |
66 | `); 67 | } 68 | 69 | function serializeHyperlink(linkResolver, element, children) { 70 | const target = element.data.target ? `target="${element.data.target}" rel="noopener"` : ''; 71 | const url = escapeHtml(LinkHelper.url(element.data, linkResolver)); 72 | return `${children.join('')}`; 73 | } 74 | 75 | function serializeLabel(element, children) { 76 | return `${children.join('')}`; 77 | } 78 | 79 | function serializeSpan(content) { 80 | return content ? escapeHtml(content).replace(/\n/g, '
') : ''; 81 | } 82 | 83 | module.exports = { 84 | asText(structuredText, joinString) { 85 | return PrismicRichText.asText(structuredText, joinString); 86 | }, 87 | 88 | asHtml(richText, linkResolver, htmlSerializer) { 89 | const serialized = PrismicRichText.serialize(richText, serialize.bind(null, linkResolver), htmlSerializer); 90 | return serialized.join(''); 91 | }, 92 | 93 | Elements : Elements 94 | }; 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **🚨 Replaced by [`@prismicio/helpers`](https://prismic.io/docs/technical-reference/prismicio-helpers) 📣** 2 | > 3 | > `prismic-dom` is deprecated and replaced by `@prismicio/helpers` v2. All functions from `prismic-dom` have been moved into the more general `@prismicio/helpers` package. Moving forward, only security updates will be released to `prismic-dom`. 4 | > 5 | > See the [`@prismicio/helpers` v2 Migration Guide](https://prismic.io/docs/technologies/prismic-helpers-v2-migration-guide) to learn how to upgrade your project. 6 | 7 | ## JavaScript library with static helpers to render HTML with Prismic API V2 BETA 8 | 9 | [![npm version](https://badge.fury.io/js/prismic-dom.svg)](http://badge.fury.io/js/prismic-dom) 10 | [![Build Status](https://api.travis-ci.org/prismicio/prismic-dom.png)](https://travis-ci.org/prismicio/prismic-dom) 11 | 12 | * The [source code](https://github.com/prismicio/prismic-dom) is on Github. 13 | * The [Changelog](https://github.com/prismicio/prismic-dom/releases) is on Github's releases tab. 14 | 15 | It's meant to work in pair with the prismic-javascript library, a new javascript kit for the prismic API v2 available here: 16 | * [prismic-javascript](https://github.com/prismicio/prismic-javascript) is on Github. 17 | 18 | ### Installation 19 | 20 | #### Prismic Api Endpoint 21 | Your endpoint must contains "v2" at the end, otherwise it means that you're working on the API V1 so this library won't work for you. 22 | 23 | ```javascript 24 | apiEndpoint: your-repo-name.prismic.io/api/v2 25 | ``` 26 | 27 | #### NPM 28 | 29 | ```sh 30 | npm install prismic-dom --save 31 | ``` 32 | 33 | #### CDN 34 | 35 | ``` 36 | https://unpkg.com/prismic-dom 37 | ``` 38 | 39 | (You may need to adapt the version number) 40 | 41 | #### Downloadable version 42 | 43 | On our release page: [https://github.com/prismicio/prismic-dom/releases](https://github.com/prismicio/prismic-dom/releases). 44 | 45 | The kit is universal, it can be used: 46 | 47 | * Server-side with NodeJS 48 | * Client-side as part of your build with Browserify, Webpack 49 | * Client-side with a simple script tag 50 | 51 | ### Demo project 52 | 53 | You can find an integration of prismic content with the new API V2 in the following project: 54 | * [Node.js project](https://github.com/arnaudlewis/prismic-apiv2) 55 | 56 | ### Usage 57 | 58 | With NodeJS, you can expose PrismicDOM directly in your locals to have it in your templates: 59 | ``` javascript 60 | import PrismicDOM from 'prismic-dom'; 61 | 62 | res.locals.DOM = PrismicDOM; 63 | ``` 64 | 65 | Render a RichText: 66 | 67 | * As Html 68 | ```javascript 69 | DOM.RichText.asHtml(mydoc.data.myrichtext, linkResolver) 70 | ``` 71 | 72 | * As Text 73 | ```javascript 74 | DOM.RichText.asText(mydoc.data.myrichtext) 75 | ``` 76 | 77 | Get a URL from a Link fragment of any kind 78 | 79 | ```javascript 80 | //link resolver not required if sure that it's not a document link 81 | DOM.Link.url(mydoc.data.mylink, ctx.linkResolver) 82 | ``` 83 | 84 | Convert a Date as string from the API to an ISO Date: 85 | 86 | ```javascript 87 | DOM.Date(mydoc.data.mydate) 88 | ``` 89 | 90 | #### Install the kit locally 91 | 92 | Source files are in the `src/` directory. You only need [Node.js and npm](http://www.joyent.com/blog/installing-node-and-npm/) 93 | to work on the codebase. 94 | 95 | ``` 96 | npm install 97 | npm run dev 98 | ``` 99 | 100 | #### Documentation 101 | 102 | Please document any new feature or bugfix using the [JSDoc](http://usejsdoc.org/) syntax. You don't need to generate the documentation, we'll do that. 103 | 104 | If you feel an existing area of code is lacking documentation, feel free to write it; but please do so on its own branch and pull-request. 105 | 106 | If you find existing code that is not optimally documented and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request. 107 | 108 | ### License 109 | 110 | This software is licensed under the Apache 2 license, quoted below. 111 | 112 | Copyright 2013-2017 Prismic.io (http://prismic.io). 113 | 114 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 115 | 116 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 117 | -------------------------------------------------------------------------------- /test/richtext.spec.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import RichText from '../src/richtext.js'; 3 | const asText = RichText.asText; 4 | const asHtml = RichText.asHtml; 5 | 6 | const mock = [ 7 | { type: 'paragraph', text: 'A > B', spans: [] }, 8 | { type: 'preformatted', text: '\n TEST\n', spans: [] }, 9 | { 10 | "type": "paragraph", 11 | "text": "This is bold and italic and >:) both.", 12 | "spans": [ 13 | { 14 | "start": 8, 15 | "end": 12, 16 | "type": "strong" 17 | }, 18 | { 19 | "start": 17, 20 | "end": 23, 21 | "type": "em" 22 | }, 23 | { 24 | "start": 28, 25 | "end": 36, 26 | "type": "strong" 27 | }, 28 | { 29 | "start": 28, 30 | "end": 36, 31 | "type": "em" 32 | } 33 | ] 34 | }, 35 | { 36 | "type": "paragraph", 37 | "text": "This is a link with XSS.", 38 | "spans": [{ 39 | "start": 10, 40 | "end": 14, 41 | "type": "hyperlink", 42 | "data": { 43 | "link_type": "Web", 44 | "url": "https://example.org\" onmouseover=\"alert(document.cookie);" 45 | } 46 | }] 47 | }, 48 | { 49 | "type": "paragraph", 50 | "text": "This is a normal link.", 51 | "spans": [{ 52 | "start": 17, 53 | "end": 21, 54 | "type": "hyperlink", 55 | "data": { 56 | "link_type": "Web", 57 | "url": "https://prismic.io" 58 | } 59 | }] 60 | }, 61 | { 62 | "type": "image", 63 | "url": "https://images.prismic.io/200629-sms-hoy/f0a757f6-770d-4eb8-a08b-f1727f1a58e4_guilherme-romano-KI2KaOeT670-unsplash.jpg?auto=compress,format", 64 | "alt": "An \"Atlantic\" Puffin", 65 | "copyright": "\"unsplash\"", 66 | "dimensions": { 67 | "width": 2400, 68 | "height": 1602 69 | } 70 | } 71 | ]; 72 | 73 | describe('asText', function() { 74 | context('applying mock object using default join string (undefined)', function() { 75 | const result = asText(mock); 76 | 77 | // Note: Currently there is '\n ' added to the output. 78 | // See: https://github.com/prismicio/prismic-richtext/issues/7 79 | // Until pull request https://github.com/prismicio/prismic-richtext/pull/8 80 | // is released, we test for the old behaviour. 81 | it('should join blocks with one whitespace (default)', function() { 82 | expect(result).to.equal('A > B \n TEST\n This is bold and italic and >:) both. This is a link with XSS. This is a normal link. '); 83 | }); 84 | }); 85 | 86 | // Until pull request https://github.com/prismicio/prismic-richtext/pull/8 87 | // is released skip the following test... 88 | // context('applying mock object and join string "\\n"', function() { 89 | // const result = asText(mock, '\n'); 90 | 91 | // it('should join blocks with one line break', function() { 92 | // expect(result).to.equal('A > B\n\n TEST\n\nThis is bold and italic and >:) both.'); 93 | // }); 94 | // }); 95 | }); 96 | 97 | describe('asHtml', function() { 98 | context('applying mock object', function() { 99 | const result = asHtml(mock); 100 | 101 | const expectations = [ 102 | '

A > B

', 103 | '
<example>\n  TEST\n</example>
', 104 | '

This is bold and italic and >:) both.

', 105 | '

This is a link with XSS.

', 106 | '

This is a normal link.

', 107 | '

\n An "Atlantic" Puffin\n

' 108 | ]; 109 | 110 | it('should contain the first paragraph with special character escaped', function() { 111 | expect(result).have.string(expectations[0]); 112 | }); 113 | 114 | it('should contain the preformatted element with special character escaped and line breaks preserved', function() { 115 | expect(result).have.string(expectations[1]); 116 | }); 117 | 118 | it('should contain escaped external link', function() { 119 | expect(result).have.string(expectations[3]); 120 | }); 121 | 122 | it('should contain valid external link', function() { 123 | expect(result).have.string(expectations[4]); 124 | }); 125 | 126 | it('should contain valid image', function() { 127 | expect(result).have.string(expectations[5]); 128 | }); 129 | }); 130 | }); -------------------------------------------------------------------------------- /dist/prismic-dom.min.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("PrismicDOM",[],t):"object"==typeof exports?exports.PrismicDOM=t():e.PrismicDOM=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"undefined"!=typeof self&&self,e.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){var r=n(2),o=n(3);e.exports={Link:r,Date:o}},function(e,t,n){e.exports={url:function(e,t){var n=e&&e.value?e.value.document:e;if(e&&[e.type,e.link_type,e._linkType,e.linkType].some((function(e){return e&&["Document","Link.Document","Link.document"].includes(e)}))&&t&&"function"==typeof t){var r=t(n);if(r)return r}return n&&n.url?n.url:""}}},function(e,t){e.exports=function(e){if(!e)return null;var t=24==e.length?"".concat(e.substring(0,22),":").concat(e.substring(22,24)):e;return new Date(t)}}])},function(e,t,n){e.exports=n(2)},function(e,t,n){var r=n(0),o=n(3),i=r.Date,u=r.Link;e.exports={Date:i,Link:u,RichText:o}},function(e,t,n){var r=n(4),o=n(0).Link,i=n(5),u=r.Elements;function c(e,t,n,r,c){switch(t){case u.heading1:return l("h1",n,c);case u.heading2:return l("h2",n,c);case u.heading3:return l("h3",n,c);case u.heading4:return l("h4",n,c);case u.heading5:return l("h5",n,c);case u.heading6:return l("h6",n,c);case u.paragraph:return l("p",n,c);case u.preformatted:return function(e){return"").concat(i(e.text),"")}(n);case u.strong:return l("strong",n,c);case u.em:return l("em",n,c);case u.listItem:case u.oListItem:return l("li",n,c);case u.list:return l("ul",n,c);case u.oList:return l("ol",n,c);case u.image:return function(e,t){var n=t.linkTo?o.url(t.linkTo,e):null,r=t.linkTo&&t.linkTo.target?'target="'.concat(t.linkTo.target,'" rel="noopener"'):"",u=[t.label||"","block-img"],c='').concat(t.alt?i(t.alt):');return'\n

\n ').concat(n?"').concat(c,""):c,"\n

\n ")}(e,n);case u.embed:return function(e){return'\n
\n\n ").concat(e.oembed.html,"\n
\n ")}(n);case u.hyperlink:return function(e,t,n){var r=t.data.target?'target="'.concat(t.data.target,'" rel="noopener"'):"",u=i(o.url(t.data,e));return"').concat(n.join(""),"")}(e,n,c);case u.label:return function(e,t){return"").concat(t.join(""),"")}(n,c);case u.span:return function(e){return e?i(e).replace(/\n/g,"
"):""}(r);default:return""}}function a(e){return e.label?' class="'.concat(e.label,'"'):""}function l(e,t,n){return"<".concat(e).concat(a(t),">").concat(n.join(""),"")}e.exports={asText:function(e,t){return r.asText(e,t)},asHtml:function(e,t,n){return r.serialize(e,c.bind(null,t),n).join("")},Elements:u}},function(e,t,n){"undefined"!=typeof self&&self,e.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t,n){"use strict";var r;function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}Object.defineProperty(t,"__esModule",{value:!0}),t.PRIORITIES=t.NODE_TYPES=void 0;var i={heading1:"heading1",heading2:"heading2",heading3:"heading3",heading4:"heading4",heading5:"heading5",heading6:"heading6",paragraph:"paragraph",preformatted:"preformatted",strong:"strong",em:"em",listItem:"list-item",oListItem:"o-list-item",list:"group-list-item",oList:"group-o-list-item",image:"image",embed:"embed",hyperlink:"hyperlink",label:"label",span:"span"};t.NODE_TYPES=i;var u=(o(r={},i.heading1,4),o(r,i.heading2,4),o(r,i.heading3,4),o(r,i.heading4,4),o(r,i.heading5,4),o(r,i.heading6,4),o(r,i.paragraph,3),o(r,i.preformatted,5),o(r,i.strong,6),o(r,i.em,6),o(r,i.oList,1),o(r,i.list,1),o(r,i.listItem,1),o(r,i.oListItem,1),o(r,i.image,1),o(r,i.embed,1),o(r,i.hyperlink,3),o(r,i.label,4),o(r,i.span,7),r);t.PRIORITIES=u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r,o=n(7),i=n(2),u=n(8),c=n(0),a=(r=n(3))&&r.__esModule?r:{default:r};function l(e,t){for(var n=0;n0)return function(e,t,n){return t.reduce((function(r,o,u){var c=[],a=0===u&&o.start>n.lower,l=u===t.length-1&&n.upper>o.end;if(a){var s=new i.TextNode(n.lower,o.start,e.slice(n.lower,o.start));c=c.concat(s)}else{var f=t[u-1];if(f&&o.start>f.end){var d=e.slice(f.end,o.start),p=new i.TextNode(f.end,o.start,d);c=c.concat(p)}}if(c=c.concat(o),l){var y=new i.TextNode(o.end,n.upper,e.slice(o.end,n.upper));c=c.concat(y)}return r.concat(c)}),[])}(e,d(e,t),n);var r=e.slice(n.lower,n.upper);return[new i.TextNode(n.lower,n.upper,r)]}function d(e,t){var n=function(e){return function(e,t){return t.reduce((function(e,t){var n=(0,o.last)(e);if(n){if(n.some((function(e){return e.isParentOf(t)})))return(0,o.init)(e).concat([n.concat(t)]);var r=(0,o.last)(n);return r&&function(e,t){return e.end>=t.start}(r,t)?(0,o.init)(e).concat([n.concat(t)]):e.concat([[t]])}return[[t]]}),[])}(0,(0,o.sort)(e,(function(e,t){return n=t,e.start-n.start||function(e,t){return e.end-t.end}(e,t);var n})))}((0,o.sort)(t,(function(e,t){return e.start-t.start}))).map(s),r=(0,o.flatten)(n.map((function(t){return function(e,t){var n=t.others.reduce((function(n,r){var o=n.inner,u=n.outer,c=function(e,t,n){return n.startt.end?{inner:i.SpanNode.slice(n,n.start,t.end,e),outer:i.SpanNode.slice(n,t.end,n.end,e)}:{inner:n}}(e,t.elected,r);return{inner:o.concat(c.inner),outer:c.outer?u.concat(c.outer):u}}),{inner:[],outer:[]}),r=n.inner,o=n.outer;return[t.elected.setChildren(f(e,r,t.elected.boundaries()))].concat(d(e,o))}(e,t)})));return(0,o.sort)(r,(function(e,t){return e.start-t.start}))}var p=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,(n=[{key:"fromRichText",value:function(e){return{key:(0,a.default)(),children:e.reduce((function(e,t,n){if(u.RichTextBlock.isEmbedBlock(t.type)||u.RichTextBlock.isImageBlock(t.type))return e.concat(new i.BlockNode(t.type,t));var r=function(e){var t=(e.spans||[]).map((function(t){var n=e.text.slice(t.start,t.end);return new i.SpanNode(t.start,t.end,t.type,n,[],t)})),n={lower:0,upper:e.text.length};return f(e.text,t,n)}(t),c=e[e.length-1];if(u.RichTextBlock.isListItem(t.type)&&c&&c instanceof i.ListBlockNode){var a=new i.ListItemBlockNode(t,r),l=c.addChild(a);return(0,o.init)(e).concat(l)}if(u.RichTextBlock.isOrderedListItem(t.type)&&c&&c instanceof i.OrderedListBlockNode){var s=new i.OrderedListItemBlockNode(t,r),d=c.addChild(s);return(0,o.init)(e).concat(d)}if(u.RichTextBlock.isListItem(t.type)){var p=new i.ListItemBlockNode(t,r),y=new i.ListBlockNode(u.RichTextBlock.emptyList(),[p]);return e.concat(y)}if(u.RichTextBlock.isOrderedListItem(t.type)){var h=new i.OrderedListItemBlockNode(t,r),v=new i.OrderedListBlockNode(u.RichTextBlock.emptyOrderedList(),[h]);return e.concat(v)}return e.concat(new i.BlockNode(t.type,t,r))}),[])}}}])&&l(t,n),e}();t.default=p},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ListBlockNode=t.OrderedListBlockNode=t.OrderedListItemBlockNode=t.ListItemBlockNode=t.BlockNode=t.TextNode=t.SpanNode=t.Node=void 0;var r,o=(r=n(3))&&r.__esModule?r:{default:r},i=n(0);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){for(var n=0;n=e.end}},{key:"setChildren",value:function(e){return new n(this.start,this.end,this.type,this.text,e,this.element)}}],[{key:"slice",value:function(e,t,r,o){return new n(t,r,e.type,o.slice(t,r),e.children,e.element)}}]),n}();t.SpanNode=y;var h=function(e){l(n,y);var t=s(n);function n(e,r,o){d(this,n);var u={type:i.NODE_TYPES.span,start:e,end:r,text:o};return t.call(this,e,r,i.NODE_TYPES.span,o,[],u)}return n}();t.TextNode=h;var v=function(e){l(n,p);var t=s(n);function n(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return d(this,n),t.call(this,e,r,o)}return n}();t.BlockNode=v;var m=function(e){l(n,v);var t=s(n);function n(e,r){return d(this,n),t.call(this,i.NODE_TYPES.listItem,e,r)}return n}();t.ListItemBlockNode=m;var b=function(e){l(n,v);var t=s(n);function n(e,r){return d(this,n),t.call(this,i.NODE_TYPES.oListItem,e,r)}return n}();t.OrderedListItemBlockNode=b;var g=function(e){l(n,v);var t=s(n);function n(e,r){return d(this,n),t.call(this,i.NODE_TYPES.oList,e,r)}return a(n,[{key:"addChild",value:function(e){var t=this.children.concat(e);return new n(this.element,t)}}]),n}();t.OrderedListBlockNode=g;var x=function(e){l(n,v);var t=s(n);function n(e,r){return d(this,n),t.call(this,i.NODE_TYPES.list,e,r)}return a(n,[{key:"addChild",value:function(e){var t=this.children.concat(e);return new n(this.element,t)}}]),n}();t.ListBlockNode=x},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)}))}},function(e,t,n){e.exports=n(5)},function(e,t,n){"use strict";var r=c(n(6)),o=c(n(1)),i=c(n(9)),u=n(0);function c(e){return e&&e.__esModule?e:{default:e}}e.exports={asText:r.default,asTree:o.default.fromRichText,serialize:i.default,Elements:u.NODE_TYPES}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default=function(e,t){var n="string"==typeof t?t:" ";return e.map((function(e){return e.text})).join(n)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.init=function(e){return e.slice(0,-1)},t.last=function(e){return e[e.length-1]},t.flatten=function(e){var t=[],n=!0,r=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var c=i.value;Array.isArray(c)?t.push.apply(t,c):t.push(c)}}catch(e){r=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(r)throw o}}return t},t.sort=function(e,t){return function(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t]/;e.exports=function(e){var t,n=""+e,o=r.exec(n);if(!o)return n;var i="",u=0,c=0;for(u=o.index;ut.end?{inner:i.SpanNode.slice(n,n.start,t.end,e),outer:i.SpanNode.slice(n,t.end,n.end,e)}:{inner:n}}(e,t.elected,r);return{inner:o.concat(c.inner),outer:c.outer?u.concat(c.outer):u}},{inner:[],outer:[]}),r=n.inner,o=n.outer;return[t.elected.setChildren(y(e,r,t.elected.boundaries()))].concat(h(e,o))}function d(e){return function(e,t){return t.reduce(function(t,n){var r=(0,o.last)(t);if(r){if(r.some(function(e){return e.isParentOf(n)}))return(0,o.init)(t).concat([r.concat(n)]);var i=(0,o.last)(r);return i&&e(i,n)?(0,o.init)(t).concat([r.concat(n)]):t.concat([[n]])}return[[n]]},[])}(function(e,t){return e.end>=t.start},(0,o.sort)(e,function(e,t){return n=t,e.start-n.start||function(e,t){return e.end-t.end}(e,t);var n}))}function p(e){if(0===e.length)throw new Error(\"Unable to elect node on empty list\");var t=s(e.sort(function(e,t){if(e.isParentOf(t))return-1;if(t.isParentOf(e))return 1;var n=c.PRIORITIES[e.type]-c.PRIORITIES[t.type];return 0===n?e.text.length-t.text.length:n}));return{elected:t[0],others:t.slice(1)}}function y(e,t,n){if(t.length>0)return function(e,t,n){return t.reduce(function(r,o,u){var c=[],a=0===u&&o.start>n.lower,l=u===t.length-1&&n.upper>o.end;if(a){var s=new i.TextNode(n.lower,o.start,e.slice(n.lower,o.start));c=c.concat(s)}else{var f=t[u-1];if(f&&o.start>f.end){var d=e.slice(f.end,o.start),p=new i.TextNode(f.end,o.start,d);c=c.concat(p)}}if(c=c.concat(o),l){var y=new i.TextNode(o.end,n.upper,e.slice(o.end,n.upper));c=c.concat(y)}return r.concat(c)},[])}(e,h(e,t),n);var r=e.slice(n.lower,n.upper);return[new i.TextNode(n.lower,n.upper,r)]}function h(e,t){var n=d((0,o.sort)(t,function(e,t){return e.start-t.start})).map(p),r=(0,o.flatten)(n.map(function(t){return f(e,t)}));return(0,o.sort)(r,function(e,t){return e.start-t.start})}var v=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError(\"Cannot call a class as a function\")}(this,e)}var t,n,r;return t=e,r=[{key:\"fromRichText\",value:function(e){return{key:(0,a.default)(),children:e.reduce(function(e,t,n){if(u.RichTextBlock.isEmbedBlock(t.type)||u.RichTextBlock.isImageBlock(t.type))return e.concat(new i.BlockNode(t.type,t));var r=function(e){var t=(e.spans||[]).map(function(t){var n=e.text.slice(t.start,t.end);return new i.SpanNode(t.start,t.end,t.type,n,[],t)}),n={lower:0,upper:e.text.length};return y(e.text,t,n)}(t),c=e[e.length-1];if(u.RichTextBlock.isListItem(t.type)&&c&&c instanceof i.ListBlockNode){var a=new i.ListItemBlockNode(t,r),l=c.addChild(a);return(0,o.init)(e).concat(l)}if(u.RichTextBlock.isOrderedListItem(t.type)&&c&&c instanceof i.OrderedListBlockNode){var s=new i.OrderedListItemBlockNode(t,r),f=c.addChild(s);return(0,o.init)(e).concat(f)}if(u.RichTextBlock.isListItem(t.type)){var d=new i.ListItemBlockNode(t,r),p=new i.ListBlockNode(u.RichTextBlock.emptyList(),[d]);return e.concat(p)}if(u.RichTextBlock.isOrderedListItem(t.type)){var h=new i.OrderedListItemBlockNode(t,r),v=new i.OrderedListBlockNode(u.RichTextBlock.emptyOrderedList(),[h]);return e.concat(v)}return e.concat(new i.BlockNode(t.type,t,r))},[])}}}],(n=null)&&l(t.prototype,n),r&&l(t,r),e}();t.default=v},function(e,t,n){\"use strict\";Object.defineProperty(t,\"__esModule\",{value:!0}),t.ListBlockNode=t.OrderedListBlockNode=t.OrderedListItemBlockNode=t.ListItemBlockNode=t.BlockNode=t.TextNode=t.SpanNode=t.Node=void 0;var r,o=(r=n(3))&&r.__esModule?r:{default:r},i=n(0);function u(e){return(u=\"function\"==typeof Symbol&&\"symbol\"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&\"function\"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?\"symbol\":typeof e})(e)}function c(e,t){for(var n=0;n=e.end}},{key:\"setChildren\",value:function(e){return new n(this.start,this.end,this.type,this.text,e,this.element)}}],[{key:\"slice\",value:function(e,t,r,o){return new n(t,r,e.type,o.slice(t,r),e.children,e.element)}}]),n}();t.SpanNode=h;var v=function(e){l(n,h);var t=f(n);function n(e,r,o){p(this,n);var u={type:i.NODE_TYPES.span,start:e,end:r,text:o};return t.call(this,e,r,i.NODE_TYPES.span,o,[],u)}return n}();t.TextNode=v;var m=function(e){l(n,y);var t=f(n);function n(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return p(this,n),t.call(this,e,r,o)}return n}();t.BlockNode=m;var b=function(e){l(n,m);var t=f(n);function n(e,r){return p(this,n),t.call(this,i.NODE_TYPES.listItem,e,r)}return n}();t.ListItemBlockNode=b;var x=function(e){l(n,m);var t=f(n);function n(e,r){return p(this,n),t.call(this,i.NODE_TYPES.oListItem,e,r)}return n}();t.OrderedListItemBlockNode=x;var O=function(e){l(n,m);var t=f(n);function n(e,r){return p(this,n),t.call(this,i.NODE_TYPES.oList,e,r)}return a(n,[{key:\"addChild\",value:function(e){var t=this.children.concat(e);return new n(this.element,t)}}]),n}();t.OrderedListBlockNode=O;var g=function(e){l(n,m);var t=f(n);function n(e,r){return p(this,n),t.call(this,i.NODE_TYPES.list,e,r)}return a(n,[{key:\"addChild\",value:function(e){var t=this.children.concat(e);return new n(this.element,t)}}]),n}();t.ListBlockNode=g},function(e,t,n){\"use strict\";Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=function(){var e=(new Date).getTime();return\"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),(\"x\"==t?n:3&n|8).toString(16)})}},function(e,t,n){e.exports=n(5)},function(e,t,n){\"use strict\";var r=c(n(6)),o=c(n(1)),i=c(n(9)),u=n(0);function c(e){return e&&e.__esModule?e:{default:e}}e.exports={asText:r.default,asTree:o.default.fromRichText,serialize:i.default,Elements:u.NODE_TYPES}},function(e,t,n){\"use strict\";Object.defineProperty(t,\"__esModule\",{value:!0}),t.default=void 0;var r=function(e,t){var n=\"string\"==typeof t?t:\" \";return e.map(function(e){return e.text}).join(n)};t.default=r},function(e,t,n){\"use strict\";Object.defineProperty(t,\"__esModule\",{value:!0}),t.init=function(e){return e.slice(0,-1)},t.last=function(e){return e[e.length-1]},t.flatten=function(e){var t=[],n=!0,r=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var c=i.value;Array.isArray(c)?t.push.apply(t,c):t.push(c)}}catch(e){r=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(r)throw o}}return t},t.sort=function(e,t){return function(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t]/;\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = escapeHtml;\n\n/**\n * Escape special characters in the given string of html.\n *\n * @param {string} string The string to escape for inserting into HTML\n * @return {string}\n * @public\n */\n\nfunction escapeHtml(string) {\n var str = '' + string;\n var match = matchHtmlRegExp.exec(str);\n\n if (!match) {\n return str;\n }\n\n var escape;\n var html = '';\n var index = 0;\n var lastIndex = 0;\n\n for (index = match.index; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"';\n break;\n case 38: // &\n escape = '&';\n break;\n case 39: // '\n escape = ''';\n break;\n case 60: // <\n escape = '<';\n break;\n case 62: // >\n escape = '>';\n break;\n default:\n continue;\n }\n\n if (lastIndex !== index) {\n html += str.substring(lastIndex, index);\n }\n\n lastIndex = index + 1;\n html += escape;\n }\n\n return lastIndex !== index\n ? html + str.substring(lastIndex, index)\n : html;\n}\n\n\n//# sourceURL=webpack://PrismicDOM/./node_modules/escape-html/index.js?"); 130 | 131 | /***/ }), 132 | 133 | /***/ "./src/index.js": 134 | /*!**********************!*\ 135 | !*** ./src/index.js ***! 136 | \**********************/ 137 | /*! no static exports found */ 138 | /***/ (function(module, exports, __webpack_require__) { 139 | 140 | eval("var PrismicHelpers = __webpack_require__(/*! @prismicio/helpers */ \"./node_modules/@prismicio/helpers/dist/prismic-helpers.min.js\");\n\nvar RichText = __webpack_require__(/*! ./richtext */ \"./src/richtext.js\");\n\nvar Date = PrismicHelpers.Date,\n Link = PrismicHelpers.Link;\nmodule.exports = {\n Date: Date,\n Link: Link,\n RichText: RichText\n};\n\n//# sourceURL=webpack://PrismicDOM/./src/index.js?"); 141 | 142 | /***/ }), 143 | 144 | /***/ "./src/richtext.js": 145 | /*!*************************!*\ 146 | !*** ./src/richtext.js ***! 147 | \*************************/ 148 | /*! no static exports found */ 149 | /***/ (function(module, exports, __webpack_require__) { 150 | 151 | eval("var PrismicRichText = __webpack_require__(/*! @prismicio/richtext */ \"./node_modules/@prismicio/richtext/dist/prismic-richtext.min.js\");\n\nvar _require = __webpack_require__(/*! @prismicio/helpers */ \"./node_modules/@prismicio/helpers/dist/prismic-helpers.min.js\"),\n LinkHelper = _require.Link;\n\nvar escapeHtml = __webpack_require__(/*! escape-html */ \"./node_modules/escape-html/index.js\");\n\nvar Elements = PrismicRichText.Elements;\n\nfunction serialize(linkResolver, type, element, content, children) {\n switch (type) {\n case Elements.heading1:\n return serializeStandardTag('h1', element, children);\n\n case Elements.heading2:\n return serializeStandardTag('h2', element, children);\n\n case Elements.heading3:\n return serializeStandardTag('h3', element, children);\n\n case Elements.heading4:\n return serializeStandardTag('h4', element, children);\n\n case Elements.heading5:\n return serializeStandardTag('h5', element, children);\n\n case Elements.heading6:\n return serializeStandardTag('h6', element, children);\n\n case Elements.paragraph:\n return serializeStandardTag('p', element, children);\n\n case Elements.preformatted:\n return serializePreFormatted(element);\n\n case Elements.strong:\n return serializeStandardTag('strong', element, children);\n\n case Elements.em:\n return serializeStandardTag('em', element, children);\n\n case Elements.listItem:\n return serializeStandardTag('li', element, children);\n\n case Elements.oListItem:\n return serializeStandardTag('li', element, children);\n\n case Elements.list:\n return serializeStandardTag('ul', element, children);\n\n case Elements.oList:\n return serializeStandardTag('ol', element, children);\n\n case Elements.image:\n return serializeImage(linkResolver, element);\n\n case Elements.embed:\n return serializeEmbed(element);\n\n case Elements.hyperlink:\n return serializeHyperlink(linkResolver, element, children);\n\n case Elements.label:\n return serializeLabel(element, children);\n\n case Elements.span:\n return serializeSpan(content);\n\n default:\n return '';\n }\n}\n\nfunction label(element) {\n return element.label ? \" class=\\\"\".concat(element.label, \"\\\"\") : '';\n}\n\nfunction serializeStandardTag(tag, element, children) {\n return \"<\".concat(tag).concat(label(element), \">\").concat(children.join(''), \"\");\n}\n\nfunction serializePreFormatted(element) {\n return \"\").concat(escapeHtml(element.text), \"\");\n}\n\nfunction serializeImage(linkResolver, element) {\n var linkUrl = element.linkTo ? LinkHelper.url(element.linkTo, linkResolver) : null;\n var linkTarget = element.linkTo && element.linkTo.target ? \"target=\\\"\".concat(element.linkTo.target, \"\\\" rel=\\\"noopener\\\"\") : '';\n var wrapperClassList = [element.label || '', 'block-img'];\n var img = \"\\\"\").concat(element.alt\");\n return \"\\n

\\n \").concat(linkUrl ? \"\").concat(img, \"\") : img, \"\\n

\\n \");\n}\n\nfunction serializeEmbed(element) {\n return \"\\n
\\n\\n \").concat(element.oembed.html, \"\\n
\\n \");\n}\n\nfunction serializeHyperlink(linkResolver, element, children) {\n var target = element.data.target ? \"target=\\\"\".concat(element.data.target, \"\\\" rel=\\\"noopener\\\"\") : '';\n var url = escapeHtml(LinkHelper.url(element.data, linkResolver));\n return \"\").concat(children.join(''), \"\");\n}\n\nfunction serializeLabel(element, children) {\n return \"\").concat(children.join(''), \"\");\n}\n\nfunction serializeSpan(content) {\n return content ? escapeHtml(content).replace(/\\n/g, '
') : '';\n}\n\nmodule.exports = {\n asText: function asText(structuredText, joinString) {\n return PrismicRichText.asText(structuredText, joinString);\n },\n asHtml: function asHtml(richText, linkResolver, htmlSerializer) {\n var serialized = PrismicRichText.serialize(richText, serialize.bind(null, linkResolver), htmlSerializer);\n return serialized.join('');\n },\n Elements: Elements\n};\n\n//# sourceURL=webpack://PrismicDOM/./src/richtext.js?"); 152 | 153 | /***/ }), 154 | 155 | /***/ 0: 156 | /*!****************************!*\ 157 | !*** multi ./src/index.js ***! 158 | \****************************/ 159 | /*! no static exports found */ 160 | /***/ (function(module, exports, __webpack_require__) { 161 | 162 | eval("module.exports = __webpack_require__(/*! D:\\Libraries\\Desktop\\prismic\\sdk\\dom/src/index.js */\"./src/index.js\");\n\n\n//# sourceURL=webpack://PrismicDOM/multi_./src/index.js?"); 163 | 164 | /***/ }) 165 | 166 | /******/ }); 167 | }); --------------------------------------------------------------------------------