Skip to content

MarkdownViewer

Displays rendered Markdown and facilitates interaction.
  • Draft
  • Not reviewed for accessibility
import {MarkdownViewer} from '@primer/react/drafts'

The MarkdownViewer displays rendered Markdown and handles interaction (link clicking and checkbox checking/unchecking) with that content.

Examples

Simple Example

Checkbox Interaction Example

Props

MarkdownViewer

NameTypeDefaultDescription
markdownValue
string
The markdown the HTML was rendered from. This is not used for viewing, only as a source for change events.
dangerousRenderHTML
{ __html: string }
Set the rendered HTML of the viewer. To prevent XSS, ensure that the source of this HTML is trusted!
loading
boolean
Show a loading spinner instead of content.
onLinkClick
(event: MouseEvent) => void
Called when the user clicks a link element. This can be used to intercept the click and provide custom routing. Note that this is a native HTML `MouseEvent` and not a `React.ClickEvent`.
openLinksInNewTab
boolean
onChange
(markdown: string) => void | Promise<void>
Called when the user interacts and updates the Markdown. The rendered Markdown is updated eagerly - if the request fails, a rejected Promise should be returned by this handler. In that case, the viewer will revert the visual change. If the change is handled by an async API request (as it typically will be in production code), the viewer should be `disabled` while the request is pending to avoid conflicts. To allow users to check multiple boxes rapidly, the API request should be debounced (an ideal debounce duration is about 1 second).
disabled
boolean
Control whether interaction is disabled.

Status

Alpha

  • Component props and basic example usage of the component are documented on primer.style/react.
  • Component does not have any unnecessary third-party dependencies.
  • Component can adapt to different themes.
  • Component can adapt to different screen sizes.
  • Component has robust unit test coverage (100% where achievable).
  • Component has visual regression coverage of its default and interactive states.
  • Component does not introduce any axe violations.
  • Component has been manually reviewed by the accessibility team and any resulting issues have been addressed.

Beta

  • Component is used in a production application.
  • Common usage examples are documented on primer.style/react.
  • Common usage examples are documented in storybook stories.
  • Component has been reviewed by a systems designer and any resulting issues have been addressed.
  • Component does not introduce any performance regressions.

Stable

  • Component API has been stable with no breaking changes for at least one month.
  • Feedback on API usability has been sought from developers using the component and any resulting issues have been addressed.
  • Component has corresponding design guidelines documented in the interface guidelines.
  • Component has corresponding Figma component in the Primer Web library.
  • Tooling (such as linters, codemods, etc.) exists to prevent further use of alternatives.
Edit this page on GitHub
4 contributorscolebemisjoshblackiancandersoniansan5653
Last edited by colebemis on January 24, 2023