Skip to content

Commit 610421e

Browse files
authoredJul 7, 2021
feat: pass markdown for hint message on field (#5584)
1 parent b362c56 commit 610421e

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed
 

‎packages/netlify-cms-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"react-hot-loader": "^4.8.0",
5050
"react-immutable-proptypes": "^2.1.0",
5151
"react-is": "16.13.1",
52+
"react-markdown": "^6.0.2",
5253
"react-modal": "^3.8.1",
5354
"react-polyglot": "^0.7.0",
5455
"react-redux": "^7.2.0",

‎packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import styled from '@emotion/styled';
88
import { partial, uniqueId } from 'lodash';
99
import { connect } from 'react-redux';
1010
import { FieldLabel, colors, transitions, lengths, borders } from 'netlify-cms-ui-default';
11+
import ReactMarkdown from 'react-markdown';
1112

1213
import { resolveWidget, getEditorComponents } from '../../../lib/registry';
1314
import { clearFieldErrors, tryLoadEntry, validateMetaField } from '../../../actions/entries';
@@ -328,7 +329,23 @@ class EditorControl extends React.Component {
328329
/>
329330
{fieldHint && (
330331
<ControlHint active={isSelected || this.state.styleActive} error={hasErrors}>
331-
{fieldHint}
332+
<ReactMarkdown
333+
allowedElements={['a', 'strong', 'em']}
334+
unwrapDisallowed={true}
335+
components={{
336+
// eslint-disable-next-line no-unused-vars
337+
a: ({ node, ...props }) => (
338+
<a
339+
{...props}
340+
target="_blank"
341+
rel="noopener noreferrer"
342+
style={{ color: 'inherit' }}
343+
/>
344+
),
345+
}}
346+
>
347+
{fieldHint}
348+
</ReactMarkdown>
332349
</ControlHint>
333350
)}
334351
</ControlContainer>

‎website/content/docs/widgets.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ Widgets are specified as collection fields in the Netlify CMS `config.yml` file.
1010

1111
To see working examples of all of the built-in widgets, try making a 'Kitchen Sink' collection item on the [CMS demo site](https://cms-demo.netlify.com). (No login required: click the login button and the CMS will open.) You can refer to the demo [configuration code](https://github.com/netlify/netlify-cms/blob/master/dev-test/config.yml) to see how each field was configured.
1212

13-
1413
## Common widget options
1514

1615
The following options are available on all fields:
1716

1817
- `required`: specify as `false` to make a field optional; defaults to `true`
19-
- `hint`: optionally add helper text directly below a widget. Useful for including instructions.
18+
- `hint`: optionally add helper text directly below a widget. Useful for including instructions. Accepts markdown for bold, italic, and links.
2019
- `pattern`: add field validation by specifying a list with a [regex pattern](https://regexr.com/) and an error message; more extensive validation can be achieved with [custom widgets](../custom-widgets/#advanced-field-validation)
2120
- **Example:**
2221
```yaml

‎yarn.lock

+74-5
Original file line numberDiff line numberDiff line change
@@ -3678,6 +3678,11 @@
36783678
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.4.tgz#453e27c6930d66380b4c121e7d5e361c5c2d921b"
36793679
integrity sha512-zfyYsDTK1HTGYXU3fTiM76+om93HcFtsZd2M0bO/CL4DiETV7mSa/pIVN/6+G3esOqEMdg2An5cHHbK5t+9w+A==
36803680

3681+
"@types/unist@^2.0.3":
3682+
version "2.0.5"
3683+
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.5.tgz#fdd299f23205c3455af88ce618dd65c14cb73e22"
3684+
integrity sha512-wnra4Vw9dopnuybR6HBywJ/URYpYrKLoepBTEtgfJup8Ahoi2zJECPP2cwiXp7btTvOT2CULv87aQRA4eZSP6g==
3685+
36813686
"@types/url-join@^4.0.0":
36823687
version "4.0.0"
36833688
resolved "https://registry.yarnpkg.com/@types/url-join/-/url-join-4.0.0.tgz#72eff71648a429c7d4acf94e03780e06671369bd"
@@ -10095,6 +10100,11 @@ init-package-json@^2.0.2:
1009510100
validate-npm-package-license "^3.0.4"
1009610101
validate-npm-package-name "^3.0.0"
1009710102

10103+
inline-style-parser@0.1.1:
10104+
version "0.1.1"
10105+
resolved "https://registry.yarnpkg.com/inline-style-parser/-/inline-style-parser-0.1.1.tgz#ec8a3b429274e9c0a1f1c4ffa9453a7fef72cea1"
10106+
integrity sha512-7NXolsK4CAS5+xvdj5OMMbI962hU/wvwoxk+LWR9Ek9bVtyuuYScDN6eS0rUm6TxApFpw7CX1o4uJzcd4AyD3Q==
10107+
1009810108
inquirer@6.5.0:
1009910109
version "6.5.0"
1010010110
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.5.0.tgz#2303317efc9a4ea7ec2e2df6f86569b734accf42"
@@ -12172,6 +12182,13 @@ mdast-util-definitions@^1.2.0, mdast-util-definitions@^1.2.3:
1217212182
dependencies:
1217312183
unist-util-visit "^1.0.0"
1217412184

12185+
mdast-util-definitions@^4.0.0:
12186+
version "4.0.0"
12187+
resolved "https://registry.yarnpkg.com/mdast-util-definitions/-/mdast-util-definitions-4.0.0.tgz#c5c1a84db799173b4dcf7643cda999e440c24db2"
12188+
integrity sha512-k8AJ6aNnUkB7IE+5azR9h81O5EQ/cTDXtWdMq9Kk5KcEW/8ritU5CeLg/9HhOC++nALHBlaogJ5jz0Ybk3kPMQ==
12189+
dependencies:
12190+
unist-util-visit "^2.0.0"
12191+
1217512192
mdast-util-from-markdown@^0.8.0:
1217612193
version "0.8.5"
1217712194
resolved "https://registry.yarnpkg.com/mdast-util-from-markdown/-/mdast-util-from-markdown-0.8.5.tgz#d1ef2ca42bc377ecb0463a987910dae89bd9a28c"
@@ -12190,6 +12207,20 @@ mdast-util-phrasing@^2.0.0:
1219012207
dependencies:
1219112208
unist-util-is "^4.0.0"
1219212209

12210+
mdast-util-to-hast@^10.2.0:
12211+
version "10.2.0"
12212+
resolved "https://registry.yarnpkg.com/mdast-util-to-hast/-/mdast-util-to-hast-10.2.0.tgz#61875526a017d8857b71abc9333942700b2d3604"
12213+
integrity sha512-JoPBfJ3gBnHZ18icCwHR50orC9kNH81tiR1gs01D8Q5YpV6adHNO9nKNuFBCJQ941/32PT1a63UF/DitmS3amQ==
12214+
dependencies:
12215+
"@types/mdast" "^3.0.0"
12216+
"@types/unist" "^2.0.0"
12217+
mdast-util-definitions "^4.0.0"
12218+
mdurl "^1.0.0"
12219+
unist-builder "^2.0.0"
12220+
unist-util-generated "^1.0.0"
12221+
unist-util-position "^3.0.0"
12222+
unist-util-visit "^2.0.0"
12223+
1219312224
mdast-util-to-hast@^4.0.0:
1219412225
version "4.0.0"
1219512226
resolved "https://registry.yarnpkg.com/mdast-util-to-hast/-/mdast-util-to-hast-4.0.0.tgz#d8467ce28ea73b4648667bc389aa39dfa9f67f18"
@@ -12239,7 +12270,7 @@ mdn-data@2.0.4:
1223912270
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
1224012271
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
1224112272

12242-
mdurl@^1.0.1, mdurl@~1.0.1:
12273+
mdurl@^1.0.0, mdurl@^1.0.1, mdurl@~1.0.1:
1224312274
version "1.0.1"
1224412275
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
1224512276
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
@@ -14816,7 +14847,7 @@ react-is@16.13.1, react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-i
1481614847
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
1481714848
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
1481814849

14819-
react-is@^17.0.1:
14850+
react-is@^17.0.0, react-is@^17.0.1:
1482014851
version "17.0.2"
1482114852
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
1482214853
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
@@ -14826,6 +14857,25 @@ react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
1482614857
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
1482714858
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
1482814859

14860+
react-markdown@^6.0.2:
14861+
version "6.0.2"
14862+
resolved "https://registry.yarnpkg.com/react-markdown/-/react-markdown-6.0.2.tgz#d89be45c278b1e5f0196f851fffb11e30c69f027"
14863+
integrity sha512-Et2AjXAsbmPP1nLQQRqmVgcqzfwcz8uQJ8VAdADs8Nk/aaUA0YeU9RDLuCtD+GwajCnm/+Iiu2KPmXzmD/M3vA==
14864+
dependencies:
14865+
"@types/hast" "^2.0.0"
14866+
"@types/unist" "^2.0.3"
14867+
comma-separated-tokens "^1.0.0"
14868+
prop-types "^15.7.2"
14869+
property-information "^5.0.0"
14870+
react-is "^17.0.0"
14871+
remark-parse "^9.0.0"
14872+
remark-rehype "^8.0.0"
14873+
space-separated-tokens "^1.1.0"
14874+
style-to-object "^0.3.0"
14875+
unified "^9.0.0"
14876+
unist-util-visit "^2.0.0"
14877+
vfile "^4.0.0"
14878+
1482914879
react-modal@^3.8.1:
1483014880
version "3.14.3"
1483114881
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.14.3.tgz#7eb7c5ec85523e5843e2d4737cc17fc3f6aeb1c0"
@@ -15458,6 +15508,13 @@ remark-rehype@^4.0.0:
1545815508
dependencies:
1545915509
mdast-util-to-hast "^4.0.0"
1546015510

15511+
remark-rehype@^8.0.0:
15512+
version "8.1.0"
15513+
resolved "https://registry.yarnpkg.com/remark-rehype/-/remark-rehype-8.1.0.tgz#610509a043484c1e697437fa5eb3fd992617c945"
15514+
integrity sha512-EbCu9kHgAxKmW1yEYjx3QafMyGY3q8noUbNUI5xyKbaFP89wbhDrKxyIQNukNYthzjNHZu6J7hwFg7hRm1svYA==
15515+
dependencies:
15516+
mdast-util-to-hast "^10.2.0"
15517+
1546115518
remark-stringify@^6.0.4:
1546215519
version "6.0.4"
1546315520
resolved "https://registry.yarnpkg.com/remark-stringify/-/remark-stringify-6.0.4.tgz#16ac229d4d1593249018663c7bddf28aafc4e088"
@@ -16426,7 +16483,7 @@ source-map@^0.7.3:
1642616483
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
1642716484
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
1642816485

16429-
space-separated-tokens@^1.0.0:
16486+
space-separated-tokens@^1.0.0, space-separated-tokens@^1.1.0:
1643016487
version "1.1.5"
1643116488
resolved "https://registry.yarnpkg.com/space-separated-tokens/-/space-separated-tokens-1.1.5.tgz#85f32c3d10d9682007e917414ddc5c26d1aa6899"
1643216489
integrity sha512-q/JSVd1Lptzhf5bkYm4ob4iWPjx0KiRe3sRFBNrVqbJkFaBm5vbbowy1mymoPNLRa52+oadOhJ+K49wsSeSjTA==
@@ -16916,6 +16973,13 @@ style-search@^0.1.0:
1691616973
resolved "https://registry.yarnpkg.com/style-search/-/style-search-0.1.0.tgz#7958c793e47e32e07d2b5cafe5c0bf8e12e77902"
1691716974
integrity sha1-eVjHk+R+MuB9K1yv5cC/jhLneQI=
1691816975

16976+
style-to-object@^0.3.0:
16977+
version "0.3.0"
16978+
resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.3.0.tgz#b1b790d205991cc783801967214979ee19a76e46"
16979+
integrity sha512-CzFnRRXhzWIdItT3OmF8SQfWyahHhjq3HwcMNCNLn+N7klOOqPjMeG/4JSu77D7ypZdGvSzvkrbyeTMizz2VrA==
16980+
dependencies:
16981+
inline-style-parser "0.1.1"
16982+
1691916983
stylelint-config-recommended@^3.0.0:
1692016984
version "3.0.0"
1692116985
resolved "https://registry.yarnpkg.com/stylelint-config-recommended/-/stylelint-config-recommended-3.0.0.tgz#e0e547434016c5539fe2650afd58049a2fd1d657"
@@ -17822,7 +17886,7 @@ unified@^7.0.0, unified@^7.1.0:
1782217886
vfile "^3.0.0"
1782317887
x-is-string "^0.1.0"
1782417888

17825-
unified@^9.1.0:
17889+
unified@^9.0.0, unified@^9.1.0:
1782617890
version "9.2.1"
1782717891
resolved "https://registry.yarnpkg.com/unified/-/unified-9.2.1.tgz#ae18d5674c114021bfdbdf73865ca60f410215a3"
1782817892
integrity sha512-juWjuI8Z4xFg8pJbnEZ41b5xjGUWGHqXALmBZ3FC3WX0PIx1CZBIIJ6mXbYMcf6Yw4Fi0rFUTA1cdz/BglbOhA==
@@ -17879,6 +17943,11 @@ unist-builder@^1.0.1, unist-builder@^1.0.3:
1787917943
dependencies:
1788017944
object-assign "^4.1.0"
1788117945

17946+
unist-builder@^2.0.0:
17947+
version "2.0.3"
17948+
resolved "https://registry.yarnpkg.com/unist-builder/-/unist-builder-2.0.3.tgz#77648711b5d86af0942f334397a33c5e91516436"
17949+
integrity sha512-f98yt5pnlMWlzP539tPc4grGMsFaQQlP/vM396b00jngsiINumNmsY8rkXjfoi1c6QaM8nQ3vaGDuoKWbe/1Uw==
17950+
1788217951
unist-util-find-after@^3.0.0:
1788317952
version "3.0.0"
1788417953
resolved "https://registry.yarnpkg.com/unist-util-find-after/-/unist-util-find-after-3.0.0.tgz#5c65fcebf64d4f8f496db46fa8fd0fbf354b43e6"
@@ -17893,7 +17962,7 @@ unist-util-find-all-after@^3.0.2:
1789317962
dependencies:
1789417963
unist-util-is "^4.0.0"
1789517964

17896-
unist-util-generated@^1.1.0:
17965+
unist-util-generated@^1.0.0, unist-util-generated@^1.1.0:
1789717966
version "1.1.6"
1789817967
resolved "https://registry.yarnpkg.com/unist-util-generated/-/unist-util-generated-1.1.6.tgz#5ab51f689e2992a472beb1b35f2ce7ff2f324d4b"
1789917968
integrity sha512-cln2Mm1/CZzN5ttGK7vkoGw+RZ8VcUH6BtGbq98DDtRGquAAOXig1mrBQYelOwMXYS8rK+vZDyyojSjp7JX+Lg==

0 commit comments

Comments
 (0)
Please sign in to comment.