Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(markdown): remove breaks option #79

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/HtmlPreviewer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useRef, useState } from "react";
import type { PreviewerProps } from "./types";
import type { HtmlPreviewerProps } from "./types";
import { applyPlugins } from "./shared";
import { sanitizeHtmlPlugin } from "./plugins";

export function HtmlPreviewer(props: PreviewerProps) {
export function HtmlPreviewer(props: HtmlPreviewerProps = {}) {
const {
plugins = [],
content = "",
Expand Down
19 changes: 10 additions & 9 deletions src/MarkdownPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import { useEffect, useState } from "react";

import { HtmlPreviewer } from "./HtmlPreviewer";
import { applyPlugins } from "./shared";
import { PreviewerProps } from "./types";
import { MarkdownPreviewerProps } from "./types";
import { highlightCodeExtension } from "./extensions/highlightCode";

const marked = new Marked();

marked.use(highlightCodeExtension());

export function MarkdownPreviewer(props: PreviewerProps) {
const { plugins = [], content = "", className = "", ...restProps } = props;
export function MarkdownPreviewer(props: MarkdownPreviewerProps = {}) {
const {
plugins = [],
content = "",
className = "",
markedOptions = {},
...restProps
} = props;

const renderer = new Renderer();

const markedOptions: MarkedOptions = {
breaks: true,
renderer,
};
markedOptions.renderer = markedOptions.renderer || new Renderer();

applyPlugins(plugins, "markedOptions", markedOptions);

Expand Down
9 changes: 8 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import type { MarkedOptions } from "marked";

export type PreviewerProps = {
export type MarkdownPreviewerProps = {
plugins?: Plugin[];
/**
* @description The content to preview
Expand All @@ -21,8 +21,15 @@ export type PreviewerProps = {
* @description Max lines of markdown/html content displayed, ellipsis rest
*/
maxLines?: number | string;

/**
* @description Options for marked
*/
markedOptions?: MarkedOptions;
};

export type HtmlPreviewerProps = Omit<MarkdownPreviewerProps, "markedOptions">;

export type Plugin = {
/**
* @description Plugin name, unique
Expand Down