@happeouikit/content-renderer 3.1.6 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ import { CopyToClipboardButton } from "@happeouikit/copy-to-clipboard-button";
19
19
  import { BodyUI, sansFamily } from "@happeouikit/typography";
20
20
  import { margin200, media, padding200 } from "@happeouikit/layout";
21
21
  import { active, gray04, gray07, gray09, lighten, warn } from "@happeouikit/colors";
22
- import { toHtml, loadCodeFont, decodeHtmlEntities, removeSpecialCharacters, toSafeText } from "./utils";
22
+ import { toHtml, loadCodeFont, decodeHtmlEntities, removeSpecialCharacters, toSafeText, addColorSpanAfterColorCodes } from "./utils";
23
23
  import { ELEMENT_TYPE_PRE, ELEMENT_TYPE_CODE, HIGHLIGHJS_CSS, HIGHLIGHJS_JS, CODE_BLOCK_AVAILABLE_LANGUAGES } from "./constants";
24
24
  import { jsx as _jsx } from "react/jsx-runtime";
25
25
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -36,7 +36,9 @@ var ContentRenderer = function ContentRenderer(_ref) {
36
36
  decodeHtmlEntitiesOnRender = _ref.decodeHtmlEntitiesOnRender,
37
37
  forceDefaultLinkTarget = _ref.forceDefaultLinkTarget,
38
38
  _ref$inheritBrandingS = _ref.inheritBrandingStyles,
39
- inheritBrandingStyles = _ref$inheritBrandingS === void 0 ? false : _ref$inheritBrandingS;
39
+ inheritBrandingStyles = _ref$inheritBrandingS === void 0 ? false : _ref$inheritBrandingS,
40
+ _ref$addColorBlocks = _ref.addColorBlocks,
41
+ addColorBlocks = _ref$addColorBlocks === void 0 ? false : _ref$addColorBlocks;
40
42
  var element = useRef({});
41
43
  var _useState = useState([]),
42
44
  _useState2 = _slicedToArray(_useState, 2),
@@ -128,11 +130,14 @@ var ContentRenderer = function ContentRenderer(_ref) {
128
130
  var safeText = useMemo(function () {
129
131
  var lowercaseType = type && typeof type === "string" ? type.toLowerCase() : "html";
130
132
  var transformedContent = lowercaseType === "text" ? toSafeText("<p>".concat(content, "</p>")) : toHtml(content, lowercaseType);
133
+ if (addColorBlocks) {
134
+ transformedContent = addColorSpanAfterColorCodes(transformedContent);
135
+ }
131
136
  if (decodeHtmlEntitiesOnRender) {
132
137
  transformedContent = decodeHtmlEntities(transformedContent);
133
138
  }
134
139
  return transformedContent;
135
- }, [content, type, decodeHtmlEntitiesOnRender]);
140
+ }, [content, type, addColorBlocks, decodeHtmlEntitiesOnRender]);
136
141
 
137
142
  // Use dangerouslySetInnerHTML as there might be nested <p>'s header etc
138
143
  // This requires that all content is run through the toSafeText filter
@@ -173,7 +178,7 @@ var Wrapper = styled(BodyUI).attrs({
173
178
  }).withConfig({
174
179
  displayName: "ContentRenderer__Wrapper",
175
180
  componentId: "sc-1mleu9k-1"
176
- })(["", " h1.highlight,h2.highlight,h3.highlight,h4.highlight,h5.highlight,h6.highlight{border-radius:6px;position:relative;:after{content:\" \";position:absolute;top:-8px;bottom:-8px;left:-8px;right:-8px;border-radius:6px;border:5px solid ", ";}}pre{border-radius:4px;background:", ";padding:8px;margin-bottom:10px;overflow:auto;white-space:pre;position:relative;overflow:visible;*:not(p){font-weight:inherit;font-family:\"IBM Plex Mono\",monospace !important;}.content-copy-btn{position:absolute;top:0;right:0;padding:", " 0;}:hover button{opacity:1;}}.mention{border-radius:0.2em;background-color:#fff5cc;border:1px solid #fff5cc;color:#0f1621;font-weight:400;&:hover{text-decoration:none;border:1px solid #fabd24;}}.extraMention{cursor:inherit;}", " ", " img[type=\"custom-emoji\"]{height:1em;display:inline;vertical-align:middle;margin:0;}}"], function (_ref2) {
181
+ })(["", " h1.highlight,h2.highlight,h3.highlight,h4.highlight,h5.highlight,h6.highlight{border-radius:6px;position:relative;:after{content:\" \";position:absolute;top:-8px;bottom:-8px;left:-8px;right:-8px;border-radius:6px;border:5px solid ", ";}}pre{border-radius:4px;background:", ";padding:8px;margin-bottom:10px;overflow:auto;white-space:pre;position:relative;overflow:visible;*:not(p){font-weight:inherit;font-family:\"IBM Plex Mono\",monospace !important;}.content-copy-btn{position:absolute;top:0;right:0;padding:", " 0;}:hover button{opacity:1;}}.mention{border-radius:0.2em;background-color:#fff5cc;border:1px solid #fff5cc;color:#0f1621;font-weight:400;&:hover{text-decoration:none;border:1px solid #fabd24;}}.extraMention{cursor:inherit;}.color-block{display:inline-block;width:18px;height:18px;margin-left:2px;transform:translateY(4px);margin-right:2px;border-radius:4px;border:1px solid var(--color-gray100);}", " ", "}"], function (_ref2) {
177
182
  var createAnchors = _ref2.createAnchors;
178
183
  return createAnchors ? "\n h1, h2, h3, h4, h5, h6 {\n display: flex;\n align-items: center;\n :hover button {\n opacity: 0.4;\n }\n }\n " : "";
179
184
  }, lighten(warn, 0.8), gray09, padding200, function (_ref3) {
@@ -201,7 +206,8 @@ ContentRenderer.propTypes = {
201
206
  createAnchors: PropTypes.bool,
202
207
  forceDefaultLinkTarget: PropTypes.bool,
203
208
  useHashAutoscroll: PropTypes.bool,
204
- hashAutoscrollTopMargin: PropTypes.number
209
+ hashAutoscrollTopMargin: PropTypes.number,
210
+ addColorBlocks: PropTypes.bool
205
211
  };
206
212
  ContentRenderer.defaultProps = {
207
213
  content: "",
@@ -211,6 +217,7 @@ ContentRenderer.defaultProps = {
211
217
  createAnchors: false,
212
218
  useHashAutoscroll: true,
213
219
  forceDefaultLinkTarget: false,
214
- hashAutoscrollTopMargin: 0
220
+ hashAutoscrollTopMargin: 0,
221
+ addColorBlocks: false
215
222
  };
216
223
  export default ContentRenderer;
@@ -50,6 +50,7 @@ function getConverter() {
50
50
  converter.setOption("strikethrough", true); // <del>
51
51
  converter.setOption("tables", true); // <table>
52
52
  converter.setOption("openLinksInNewWindow", true);
53
+ converter.setOption("disableForced4SpacesIndentedSublists", true);
53
54
  return converter;
54
55
  }
55
56
  export default getConverter();
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import linkifyHtml from "linkifyjs/html";
5
5
  import xss from "xss";
6
6
  import { decode as decodeHtmlEntities } from "html-entities";
@@ -42,6 +42,17 @@ var toSafeText = function toSafeText(text) {
42
42
  }).replace(/&nbsp;/g, " ").replace(/\u2060/g, ""); // Replaces a hidden character that resulted in a "?"-character in backend
43
43
  };
44
44
 
45
+ /**
46
+ * Adds spans with `color-block` class after color codes hex, rgb and rgba
47
+ */
48
+ var addColorSpanAfterColorCodes = function addColorSpanAfterColorCodes() {
49
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
50
+ var colorRegex = /#(?:[0-9a-fA-F]{3}){1,2}|\brgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)|\brgba\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d*(?:\.\d+)?\s*\)/gi;
51
+ return text.replace(colorRegex, function (match) {
52
+ return "".concat(match, "<span class=\"color-block\" style=\"background-color: ").concat(match, ";\"></span>");
53
+ });
54
+ };
55
+
45
56
  /**
46
57
  * @name toHtml
47
58
  * @description Converts markdown to html, adds space to end of String
@@ -99,4 +110,4 @@ var removeSpecialCharacters = function removeSpecialCharacters() {
99
110
  str.replace(/[^\u0000-\u007E]/g, "")
100
111
  );
101
112
  };
102
- export { toHtml, toSafeText, loadCodeFont, decodeHtmlEntities, getNearestRelativeParent, removeSpecialCharacters };
113
+ export { toHtml, toSafeText, loadCodeFont, decodeHtmlEntities, getNearestRelativeParent, removeSpecialCharacters, addColorSpanAfterColorCodes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happeouikit/content-renderer",
3
- "version": "3.1.6",
3
+ "version": "3.2.0",
4
4
  "description": "Rendering html and markdown content",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
@@ -23,8 +23,8 @@
23
23
  "linkifyjs": "^2.1.8",
24
24
  "loadjs": "^4.2.0",
25
25
  "react-dom": "^17.0.2",
26
- "showdown": "^1.9.0",
27
- "xss": "^1.0.6"
26
+ "showdown": "^2.1.0",
27
+ "xss": "^1.0.14"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "prop-types": "^15.6.2",
@@ -33,5 +33,6 @@
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
- }
36
+ },
37
+ "gitHead": "4e26a409cb4a6ab360f8458d1c6b66cdd8c81d5a"
37
38
  }
package/CHANGELOG.md DELETED
@@ -1,239 +0,0 @@
1
- # Changelog
2
-
3
- ## 3.1.6
4
-
5
- - [Fixed] emoji size for all renderers
6
-
7
- ## 3.1.5
8
-
9
- - [Fixed] margin for custom-emoji
10
-
11
- ## 3.1.4
12
-
13
- - [Fixed] styles for custom-emoji
14
-
15
- ## 3.1.3
16
-
17
- - [Add] styles for custom-emoji
18
-
19
- ## 3.1.2
20
-
21
- - [Add] img type data attribute
22
-
23
- ## 3.1.1
24
-
25
- - [Remove] @universe dependencies
26
-
27
- ## 3.0.10
28
-
29
- - [Fixed] paragraph styles
30
-
31
- ## 3.0.9
32
-
33
- - [Fixed] paragraph styles
34
-
35
- ## 3.0.8
36
-
37
- - Publish
38
-
39
- ## 3.0.7
40
-
41
- - Publish
42
-
43
- ## 3.0.6
44
-
45
- - [Added] Support for user defined font families and weights
46
-
47
- ## 3.0.5
48
-
49
- - Publish
50
-
51
- ## 3.0.4
52
-
53
- - [Fixed] ContentRenderer should now render content without applying links to domain-like text.
54
- - [Updated] Updated ContentRenderer unit test with Testing Linkify hyper-link Features.
55
-
56
- ## 3.0.3
57
-
58
- - [Added] Added prop `forceDefaultLinkTarget` that will force external links with `target="_blank"` and removes `target` from internal links.
59
-
60
- ## 3.0.2
61
-
62
- - [Fixed] ContentRenderer now applies styling options from Pages
63
-
64
- ## 3.0.1
65
-
66
- - [Fixed] ContentRenderer should now deal with all kinds of xss
67
-
68
- ## 3.0.0
69
-
70
- - [Fixed] the xss converter now accepts a whiteList for CSS properties that includes vertical-align
71
- - [Updated] new dependencies updates: React 17 and and Styled Components 5
72
-
73
- ## 2.0.1
74
-
75
- - [Added] Changed type to uppercase and to handle both upper and lowercase. Add warning if lowecase is used.
76
- - [Added] Handle widgetType=`page` by removing forced styles from component.
77
-
78
- ## 2.0.0
79
-
80
- - [Breaking change] Links rendered from markdown content now always open in a new tab (not configurable).
81
-
82
- ## 1.0.48
83
-
84
- - [Fixed] Decode HTML entites causing crashes
85
-
86
- ## 1.0.46
87
-
88
- - [Fixed] Use correct font-family for all the tags inside paragraphs and list elements etc.
89
-
90
- ## 1.0.45
91
-
92
- - [Fixed] Removed some padding for tables without borders
93
-
94
- ## 1.0.44
95
-
96
- - [Fixed] Removed special characteds from content copying
97
-
98
- ## 1.0.43
99
-
100
- - [Fixed] Moved to ReactDOM for rendering extra buttons
101
- - [Added] Ability to include anchor links & buttons
102
- - [Added] Ability to auto-scroll to anchors
103
-
104
- ## 1.0.42
105
-
106
- - [Fixed] Remove bolding from links
107
-
108
- ## 1.0.37
109
-
110
- - [Fixed] Get correct parent for copy button
111
-
112
- ## 1.0.36
113
-
114
- - [Fixed] Improved code block styles
115
-
116
- ## 1.0.35
117
-
118
- - [Fixed] important fonts
119
-
120
- ## 1.0.34
121
-
122
- - [Fixed] use custom fonts for all tags inside h1, h2, h3
123
-
124
- ## 1.0.33
125
-
126
- - [Fixed] Code block
127
-
128
- ## 1.0.30
129
-
130
- - [Fixed] enforce font style to content
131
-
132
- ## 1.0.29
133
-
134
- - [Fixed] Modify blockquote styles to match froala's
135
-
136
- ## 1.0.28
137
-
138
- - [Fixed] Default image placement is now left aligned and not centered
139
- - [Fixed] Update frontend-utils dependency
140
-
141
- ## 1.0.27
142
-
143
- - [Add] Rendering of code blocks + adding copy button to code blocks
144
-
145
- ## 1.0.26
146
-
147
- - [Fixed] Embeded videos styles
148
-
149
- ## 1.0.25
150
-
151
- - [Fixed] Removed a href urls
152
-
153
- ## 1.0.24
154
-
155
- - [Fixed] fixed article CSS styles.
156
-
157
- ## 1.0.23
158
-
159
- - [Fixed] update dependencies
160
-
161
- ## 1.0.22
162
-
163
- - [Add] add some props for article content
164
-
165
- ## 1.0.21
166
-
167
- - [Fixed] stop publishing the docs
168
-
169
- ## 1.0.20
170
-
171
- - [Add] Changed some css for @channel and @editor
172
-
173
- ## 1.0.19
174
-
175
- - [Fixed] Changed @team into @channel mentioning
176
-
177
- ## 1.0.18
178
-
179
- - [Add] Support for @team and @editors mentioning.
180
-
181
- ## 1.0.17
182
-
183
- - [Fixed] Styles for heading text.
184
-
185
- ## 1.0.15
186
-
187
- - [Fixed] Type error in the mentions Showdown plugin
188
-
189
- ## 1.0.14
190
-
191
- - [Fixed] Links converted from markdown will now open in a new tab.
192
-
193
- ## 1.0.13
194
-
195
- - [Fixed] Pre element styles are now also applied to Code elements.
196
-
197
- ## 1.0.11
198
-
199
- - [Fixed] Ordered and unordered lists are now aligned, and have correct line-height.
200
-
201
- ## 1.0.10
202
-
203
- - [Fixed] List font size is now 16px.
204
-
205
- ## 1.0.8
206
-
207
- - [Added] CSS styles to mention tags.
208
-
209
- ## 1.0.7
210
-
211
- - [Fixed] Adds class to safe tags for anchor elements.
212
-
213
- ## 1.0.6
214
-
215
- - [Fixed] font stylings of p tags.
216
-
217
- ## 1.0.5
218
-
219
- - [Fixed] Missing dist
220
-
221
- ## 1.0.4
222
-
223
- - [Fixed] Package not updated
224
-
225
- ## 1.0.3
226
-
227
- - [Added] Handle user-mentio html tag
228
-
229
- ## 1.0.2
230
-
231
- - Publish
232
-
233
- ## 1.0.1
234
-
235
- - [Fixed] All children elements will now use the sans-serif font family.
236
-
237
- ## 1.0.0
238
-
239
- - Initial copy from the private kit