Skip to content

Commit

Permalink
fix: html ssr warning (#64)
Browse files Browse the repository at this point in the history
* fix: html ssr warning

BREAKING CHANGE: plugin `collectCss` removed

* docs: update
  • Loading branch information
2nthony authored Jan 5, 2024
1 parent 53b5328 commit ffe6e1e
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 429 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Preview markdown/html.
yarn add @osn/previewer
```

```ts
```jsx
import { HtmlPreviewer, MarkdownPreviewer, renderMentionIdentityUserPlugin } from "@osn/previewer"
import "@osn/previewer/styles.css"

function MentionIdentityUser({ address, network }) {
return <a>{address}</a>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"dev": "vite",
"build:demo": "tsc && vite build",
"build": "tsup --dts --format esm,cjs --clean --inject ./react-import.js ./src",
"build": "tsup --dts --format esm,cjs --clean --inject ./react-import.js ./src/index.ts && cp ./src/styles.css ./dist",
"prepublishOnly": "npm run build"
},
"files": [
Expand Down
28 changes: 13 additions & 15 deletions src/HtmlPreviewer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useEffect, useRef, useState } from "react";
import { Html } from "./components/Html";
import type { HtmlProps, PreviewerProps } from "./types";
import { css } from "styled-components";
import type { PreviewerProps } from "./types";
import { applyPlugins } from "./shared";
import { minHeightPlugin, sanitizeHtmlPlugin, maxLinesPlugin } from "./plugins";
import { sanitizeHtmlPlugin } from "./plugins";

export function HtmlPreviewer(props: PreviewerProps) {
const {
Expand All @@ -15,15 +13,7 @@ export function HtmlPreviewer(props: PreviewerProps) {
maxLines,
} = props;

const resolvedPlugins = [
minHeightPlugin(minHeight),
maxLinesPlugin(maxLines),
...plugins,
sanitizeHtmlPlugin(allowedTags),
];

const extraCss: HtmlProps["extraCss"] = [];
applyPlugins(resolvedPlugins, "collectCss", css, (str) => extraCss.push(str));
const resolvedPlugins = [...plugins, sanitizeHtmlPlugin(allowedTags)];

const ref = useRef<HTMLDivElement>(null);
const [html, setHtml] = useState(content);
Expand All @@ -36,9 +26,17 @@ export function HtmlPreviewer(props: PreviewerProps) {

return (
<div className="osn-previewer" ref={ref}>
<Html
<div
className={className}
$extraCss={extraCss}
style={{
...(maxLines && {
display: "-webkit-box",
"-webkit-line-clamp": maxLines,
"-webkit-box-orient": "vertical",
overflow: "hidden",
}),
...(minHeight && { minHeight }),
}}
dangerouslySetInnerHTML={{ __html: html }}
/>
</div>
Expand Down
201 changes: 0 additions & 201 deletions src/components/Html.tsx

This file was deleted.

Loading

0 comments on commit ffe6e1e

Please sign in to comment.