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

imprv: Upgrade unified and remark-growi-directive #9048

Merged
merged 117 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
08a54f0
upgrade unified
reiji-h Jun 19, 2024
9c7961b
add vitest for remark-growi-directive package
reiji-h Jun 19, 2024
11886e9
Merge branch 'master' into 148445-148447-upgrade-remark-growi-directive
reiji-h Jun 28, 2024
6150bb7
upgrade to v11
reiji-h Jun 28, 2024
60ec67f
upgrade packages
reiji-h Jun 28, 2024
af4cf0d
clean code
reiji-h Jun 28, 2024
dd5ebb1
update package import
reiji-h Jun 28, 2024
09f3304
Merge branch 'master' into 148445-148447-upgrade-remark-growi-directive
reiji-h Jul 2, 2024
5790001
fix test
reiji-h Jul 5, 2024
a227667
setting avoid ESM error
reiji-h Jul 9, 2024
22bc9b9
delete unused config
reiji-h Jul 9, 2024
7038973
Merge branch 'master' into 148445-148447-upgrade-remark-growi-directive
reiji-h Jul 9, 2024
21a0759
add vitest
reiji-h Jul 12, 2024
e4ec7c9
update vitest
reiji-h Jul 12, 2024
3b6d4dc
use vitest
reiji-h Jul 12, 2024
e30bfa6
Merge pull request #8951 from weseek/148445-148447-upgrade-remark-gro…
yuki-takei Jul 12, 2024
781835f
use vitest
reiji-h Jul 16, 2024
b48d6f4
remove tape package
reiji-h Jul 16, 2024
9a69189
fix unused test
reiji-h Jul 16, 2024
e4eef84
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Jul 16, 2024
be7b7f5
Merge branch 'imprv/148445-upgrade-remark-growi-directive' into imprv…
reiji-h Jul 16, 2024
e58a941
fix code
reiji-h Jul 16, 2024
4935ffb
udpate packages in remark-growi-directive
reiji-h Jul 16, 2024
c2341f2
fix lint
reiji-h Jul 16, 2024
c01ed91
fix packages error
reiji-h Jul 16, 2024
5c10f06
fix packages error
reiji-h Jul 16, 2024
45bbfc7
fix lint in test
reiji-h Jul 16, 2024
c069b65
remove vites import
reiji-h Jul 16, 2024
c66c2e5
fix import react-markdown
reiji-h Jul 16, 2024
04d2721
header cannot receive level
reiji-h Jul 17, 2024
9e0f52d
use import vitest
reiji-h Jul 17, 2024
a5bab3e
Update for dependencies
reiji-h Jul 17, 2024
cc9e1af
Create changeset
yuki-takei Jul 18, 2024
f880aac
Merge pull request #8964 from weseek/imprv/148445-150048-vitest-reamr…
yuki-takei Jul 18, 2024
4d350ef
add type annotation
reiji-h Jul 19, 2024
889b858
remvoe memo for setting components
reiji-h Jul 19, 2024
1288ecd
fix type
reiji-h Jul 19, 2024
a5446a6
split inilnecode in codeblock
reiji-h Jul 19, 2024
59ea1bb
add types
reiji-h Jul 19, 2024
80ef86c
create remark-plugin for inlinecode
reiji-h Jul 19, 2024
0bb2428
update version
reiji-h Jul 19, 2024
f28f5c3
Merge branch 'imprv/148445-upgrade-remark-growi-directive' into imprv…
reiji-h Jul 19, 2024
0744ab4
udpate version
reiji-h Jul 19, 2024
d95903c
fix import
reiji-h Jul 26, 2024
d6ef5fb
fix import
reiji-h Jul 26, 2024
60ffe04
Detect inline code blocks
reiji-h Jul 26, 2024
0e6b0c4
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Jul 26, 2024
aaddbb6
Merge branch 'imprv/148445-upgrade-remark-growi-directive' into imprv…
reiji-h Jul 26, 2024
bccc12d
fix import type
reiji-h Aug 2, 2024
b593ce3
need types annotation of growi-directive
reiji-h Aug 2, 2024
2b40ee5
add strict types
reiji-h Aug 2, 2024
b0d357a
fix type error
reiji-h Aug 2, 2024
50c37d1
needs growi-directive types
reiji-h Aug 2, 2024
17015d9
fix import type
reiji-h Aug 2, 2024
d1e0475
add types
reiji-h Aug 2, 2024
3bd9672
use memo component in ReactMarkdown
reiji-h Aug 2, 2024
6f4f271
ReactMarkdown Components is not React.Memo
reiji-h Aug 2, 2024
4742b45
add Processer type
reiji-h Aug 2, 2024
caaed9b
use React.memo component in ReactMarkdown
reiji-h Aug 2, 2024
0de8aaf
use option argument
reiji-h Aug 6, 2024
14ba9e7
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Aug 6, 2024
c988e5f
remove lint warning
reiji-h Aug 6, 2024
12d13bd
use ts
reiji-h Aug 6, 2024
1c74bf6
can use js from ts
reiji-h Aug 6, 2024
f93de4c
add visit type
reiji-h Aug 13, 2024
6fd1338
fix package usage and type
reiji-h Aug 13, 2024
f6d4dba
change type
reiji-h Aug 13, 2024
6d67d7b
set exports
reiji-h Aug 13, 2024
cb0567b
add types
reiji-h Aug 13, 2024
1ebc618
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Aug 13, 2024
eded44b
Merge branch 'imprv/148445-upgrade-remark-growi-directive' into imprv…
reiji-h Aug 13, 2024
0f319d9
Merge branch 'imprv/148445-upgrade-remark-growi-directive' into impv/…
reiji-h Aug 13, 2024
7856b53
Merge branch 'imprv/148445-15079-update-dependencies' into impv/14844…
reiji-h Aug 13, 2024
2c8488a
fix path
reiji-h Aug 13, 2024
580e6c4
fix path
reiji-h Aug 13, 2024
b317766
fix lint error
reiji-h Aug 13, 2024
0c37e3c
fix lint error
reiji-h Aug 13, 2024
bb6140f
fix lint error
reiji-h Aug 13, 2024
5230a7d
fix Attribute type
yuki-takei Aug 13, 2024
9d35745
fix test
yuki-takei Aug 13, 2024
95a7f41
Merge pull request #9027 from weseek/fix/type-and-linting
reiji-h Aug 23, 2024
2ba18f2
add codeblock sanitize
reiji-h Aug 23, 2024
761c3b9
use value key for attachmentName
reiji-h Aug 23, 2024
62c9640
fix type check
reiji-h Aug 23, 2024
14cad0f
dont use declare
reiji-h Aug 23, 2024
1d245b9
add codeblock sanitize
reiji-h Aug 23, 2024
1e55f4c
use value key for attachmentName
reiji-h Aug 23, 2024
c699127
fix type check
reiji-h Aug 23, 2024
8165837
dont use declare
reiji-h Aug 23, 2024
b283795
Revert "fix: Type and linting for updating hast-util-sanitize"
reiji-h Aug 23, 2024
352ba8b
Merge pull request #9040 from weseek/revert-9027-fix/type-and-linting
reiji-h Aug 23, 2024
3ebb6fc
fix miss revert
reiji-h Aug 23, 2024
8370a73
Revert "dont use declare"
reiji-h Aug 23, 2024
9796bd5
Revert "fix type check"
reiji-h Aug 23, 2024
8af4a61
Revert "use value key for attachmentName"
reiji-h Aug 23, 2024
5bb6b66
Revert "add codeblock sanitize"
reiji-h Aug 23, 2024
50b3706
copy file structure from mdast-util-directive
reiji-h Aug 23, 2024
15941d6
add export
reiji-h Aug 23, 2024
e3b5ebe
change file type
reiji-h Aug 26, 2024
4309cfa
fix import path
reiji-h Aug 26, 2024
7d0a6fa
Merge pull request #8995 from weseek/imprv/148445-15079-update-depend…
yuki-takei Aug 26, 2024
81863d7
use postbuild and declaration
reiji-h Aug 26, 2024
1834459
use shx
reiji-h Aug 26, 2024
de819f5
Merge pull request #9025 from weseek/impv/148445-151932-add-type-rema…
reiji-h Aug 26, 2024
8539b98
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Aug 26, 2024
ef58cdc
fix package version
reiji-h Sep 3, 2024
cb59b3e
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Sep 3, 2024
486f4b3
change class: math to katex
reiji-h Sep 4, 2024
43620c1
fix test
reiji-h Sep 4, 2024
51b322d
Revert "fix test"
reiji-h Sep 4, 2024
1f94711
Merge pull request #9062 from weseek/imprv/148445-153459-fix-github-a…
miya Sep 5, 2024
c5fb911
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Sep 6, 2024
4defcaa
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Sep 10, 2024
00b2ac6
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Sep 11, 2024
d89c40f
fix package update
reiji-h Sep 11, 2024
1cc6b5f
add typecheck
reiji-h Sep 11, 2024
70f3003
Merge branch 'master' into imprv/148445-upgrade-remark-growi-directive
reiji-h Sep 13, 2024
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
5 changes: 5 additions & 0 deletions .changeset/real-onions-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@growi/remark-growi-directive": minor
---

Convert unit test by tape to Vitest
8 changes: 8 additions & 0 deletions apps/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const getTranspilePackages = () => {
'emoticon',
'direction', // for hast-util-select
'bcp-47-match', // for hast-util-select
'parse-entities',
'character-reference-invalid',
'is-hexadecimal',
'is-alphabetical',
'is-alphanumerical',
'github-slugger',
'html-url-attributes',
'estree-util-is-identifier-name',
...listPrefixedPackages(['remark-', 'rehype-', 'hast-', 'mdast-', 'micromark-', 'unist-']),
];

Expand Down
28 changes: 14 additions & 14 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"extensible-custom-error": "^0.0.7",
"form-data": "^4.0.0",
"graceful-fs": "^4.1.11",
"hast-util-select": "^5.0.5",
"hast-util-select": "^6.0.2",
"helmet": "^4.6.0",
"http-errors": "^2.0.0",
"i18next": "^23.10.1",
Expand Down Expand Up @@ -171,7 +171,7 @@
"react-error-boundary": "^3.1.4",
"react-i18next": "^14.1.0",
"react-image-crop": "^8.3.0",
"react-markdown": "^8.0.7",
"react-markdown": "^9.0.1",
"react-multiline-clamp": "^2.0.0",
"react-scroll": "^1.8.7",
"react-stickynode": "^4.1.1",
Expand All @@ -180,18 +180,18 @@
"reactstrap": "^9.2.2",
"reconnecting-websocket": "^4.4.0",
"redis": "^3.0.2",
"rehype-katex": "^6.0.2",
"rehype-raw": "^6.1.1",
"rehype-sanitize": "^5.0.1",
"rehype-slug": "^5.0.1",
"rehype-katex": "^7.0.0",
"rehype-raw": "^7.0.0",
"rehype-sanitize": "^6.0.0",
"rehype-slug": "^6.0.0",
"rehype-toc": "^3.0.2",
"remark-breaks": "^3.0.2",
"remark-emoji": "^3.0.2",
"remark-frontmatter": "^4.0.1",
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"remark-toc": "^8.0.1",
"remark-wiki-link": "^1.0.4",
"remark-breaks": "^4.0.0",
"remark-emoji": "^5.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-math": "^6.0.0",
"remark-toc": "^9.0.0",
"remark-wiki-link": "^2.0.1",
"sanitize-filename": "^1.6.3",
"socket.io": "^4.7.5",
"stream-to-promise": "^3.0.0",
Expand Down Expand Up @@ -273,7 +273,7 @@
"react-hotkeys": "^2.0.0",
"react-input-autosize": "^3.0.0",
"react-toastify": "^9.1.3",
"rehype-rewrite": "^3.0.6",
"rehype-rewrite": "^4.0.2",
"replacestream": "^4.0.3",
"sass": "^1.53.0",
"simple-load-script": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('/Sandbox/Math is successfully loaded', async({ page }) => {
await page.goto('/Sandbox/Math');

// Expect the Math-specific elements to be present
await expect(page.locator('.math').first()).toBeVisible();
await expect(page.locator('.katex').first()).toBeVisible();
});

test('Sandbox with edit is successfully loaded', async({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('/Sandbox/math is successfully loaded', async({ page }) => {
await page.goto('/Sandbox/Math');

// Check if the math elements are visible
await expect(page.locator('.math').first()).toBeVisible();
await expect(page.locator('.katex').first()).toBeVisible();
});

test('Access to /me page', async({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/client/components/Page/SlideRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
import type { Options as ReactMarkdownOptions } from 'react-markdown';

import { usePresentationViewOptions } from '~/stores/renderer';

Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/client/components/PagePresentationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSlidesByFrontmatter } from '@growi/presentation/dist/services';
import { LoadingSpinner } from '@growi/ui/dist/components';
import { useFullScreen } from '@growi/ui/dist/utils';
import dynamic from 'next/dynamic';
import type { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
import type { Options as ReactMarkdownOptions } from 'react-markdown';
import {
Modal, ModalBody,
} from 'reactstrap';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useCallback, useEffect, useState } from 'react';

import type EventEmitter from 'events';

import type { Element } from 'hast';
import { useRouter } from 'next/router';
import type { Element } from 'react-markdown/lib/rehype-filter';

import { NextLink } from '~/components/ReactMarkdownComponents/NextLink';
import {
Expand Down Expand Up @@ -54,13 +54,12 @@ const EditLink = (props: EditLinkProps): JSX.Element => {
type HeaderProps = {
children: React.ReactNode,
node: Element,
level: number,
id?: string,
}

export const Header = (props: HeaderProps): JSX.Element => {
const {
node, id, children, level,
node, id, children,
} = props;

const { data: isGuestUser } = useIsGuestUser();
Expand All @@ -73,7 +72,7 @@ export const Header = (props: HeaderProps): JSX.Element => {

const [isActive, setActive] = useState(false);

const CustomTag = `h${level}` as keyof JSX.IntrinsicElements;
const CustomTag = node.tagName as keyof JSX.IntrinsicElements;

const activateByHash = useCallback((url: string) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback } from 'react';

import type EventEmitter from 'events';

import type { Element } from 'react-markdown/lib/rehype-filter';
import type { Element } from 'hast';

import {
useIsGuestUser, useIsReadOnlyUser, useIsSharedUser, useShareLinkId,
Expand All @@ -23,8 +23,7 @@ type TableWithEditButtonProps = {
className?: string
}

export const TableWithEditButton = React.memo((props: TableWithEditButtonProps): JSX.Element => {

const TableWithEditButtonNoMemorized = (props: TableWithEditButtonProps): JSX.Element => {
const { children, node, className } = props;

const { data: isGuestUser } = useIsGuestUser();
Expand Down Expand Up @@ -61,5 +60,6 @@ export const TableWithEditButton = React.memo((props: TableWithEditButtonProps):
</table>
</div>
);
});
TableWithEditButton.displayName = 'TableWithEditButton';
};
TableWithEditButtonNoMemorized.displayName = 'TableWithEditButton';
export const TableWithEditButton = React.memo(TableWithEditButtonNoMemorized) as typeof TableWithEditButtonNoMemorized;
15 changes: 10 additions & 5 deletions apps/app/src/client/services/renderer/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as addLineNumberAttribute from '~/services/renderer/rehype-plugins/add-
import * as keywordHighlighter from '~/services/renderer/rehype-plugins/keyword-highlighter';
import * as relocateToc from '~/services/renderer/rehype-plugins/relocate-toc';
import * as attachment from '~/services/renderer/remark-plugins/attachment';
import * as codeBlock from '~/services/renderer/remark-plugins/codeblock';
import * as plantuml from '~/services/renderer/remark-plugins/plantuml';
import * as xsvToTable from '~/services/renderer/remark-plugins/xsv-to-table';
import {
Expand Down Expand Up @@ -71,7 +72,7 @@ export const generateViewOptions = (
remarkPlugins.push(breaks);
}

const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
getCommonSanitizeOption(config),
presentation.sanitizeOption,
Expand All @@ -80,6 +81,7 @@ export const generateViewOptions = (
attachment.sanitizeOption,
lsxGrowiDirective.sanitizeOption,
refsGrowiDirective.sanitizeOption,
codeBlock.sanitizeOption,
)]
: () => {};

Expand Down Expand Up @@ -129,9 +131,10 @@ export const generateTocOptions = (config: RendererConfig, tocNode: HtmlElementN
// add remark plugins
// remarkPlugins.push();

const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
getCommonSanitizeOption(config),
codeBlock.sanitizeOption,
)]
: () => {};

Expand Down Expand Up @@ -176,7 +179,7 @@ export const generateSimpleViewOptions = (
remarkPlugins.push(breaks);
}

const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
getCommonSanitizeOption(config),
presentation.sanitizeOption,
Expand All @@ -185,6 +188,7 @@ export const generateSimpleViewOptions = (
attachment.sanitizeOption,
lsxGrowiDirective.sanitizeOption,
refsGrowiDirective.sanitizeOption,
codeBlock.sanitizeOption,
)]
: () => {};

Expand Down Expand Up @@ -227,7 +231,7 @@ export const generatePresentationViewOptions = (
const { rehypePlugins } = options;


const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
addLineNumberAttribute.sanitizeOption,
)]
Expand Down Expand Up @@ -265,7 +269,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
remarkPlugins.push(breaks);
}

const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
getCommonSanitizeOption(config),
drawio.sanitizeOption,
Expand All @@ -274,6 +278,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
lsxGrowiDirective.sanitizeOption,
refsGrowiDirective.sanitizeOption,
addLineNumberAttribute.sanitizeOption,
codeBlock.sanitizeOption,
)]
: () => {};

Expand Down
18 changes: 12 additions & 6 deletions apps/app/src/components/ReactMarkdownComponents/CodeBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ReactNode } from 'react';

import type { CodeComponent, CodeProps } from 'react-markdown/lib/ast-to-react';
import { PrismAsyncLight } from 'react-syntax-highlighter';
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';

Expand Down Expand Up @@ -45,7 +44,8 @@ function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactN
// see: https://github.com/weseek/growi/pull/7484
//
// Note: You can also remove this code if the user requests to see the code highlighted in Prism as-is.
const isSimpleString = Array.isArray(children) && children.length === 1 && typeof children[0] === 'string';

const isSimpleString = typeof children === 'string' || (Array.isArray(children) && children.length === 1 && typeof children[0] === 'string');
if (!isSimpleString) {
return (
<div style={oneDark['pre[class*="language-"]']}>
Expand All @@ -67,13 +67,19 @@ function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactN
);
}

export const CodeBlock: CodeComponent = ({ inline, className, children }: CodeProps) => {
type CodeBlockProps = {
children: ReactNode,
className?: string,
inline?: string, // "" or undefined
}

if (inline) {
return <code className={`code-inline ${className ?? ''}`}>{children}</code>;
}
export const CodeBlock = (props: CodeBlockProps): JSX.Element => {

// TODO: set border according to the value of 'customize:highlightJsStyleBorder'
const { className, children, inline } = props;
if (inline != null) {
return <code className={`code-inline ${className ?? ''}`}>{children}</code>;
}

const match = /language-(\w+)(:?.+)?/.exec(className || '');
const lang = match && match[1] ? match[1] : '';
Expand Down
10 changes: 5 additions & 5 deletions apps/app/src/features/mermaid/services/mermaid.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Schema as SanitizeOption } from 'hast-util-sanitize';
import { Plugin } from 'unified';
import { Node } from 'unist';
import type { Code } from 'mdast';
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';

function rewriteNode(node: Node) {
function rewriteNode(node: Code) {
// replace node
const data = node.data ?? (node.data = {});
data.hName = 'mermaid';
}

export const remarkPlugin: Plugin = function() {
return (tree) => {
visit(tree, (node) => {
if (node.type === 'code' && node.lang === 'mermaid') {
visit(tree, 'code', (node: Code) => {
if (node.lang === 'mermaid') {
rewriteNode(node);
}
});
Expand Down
7 changes: 2 additions & 5 deletions apps/app/src/interfaces/renderer-options.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import type { ComponentType } from 'react';

import type { SpecialComponents } from 'react-markdown/lib/ast-to-react';
import type { NormalComponents } from 'react-markdown/lib/complex-types';
import type { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
import type { Options as ReactMarkdownOptions, Components } from 'react-markdown';
import type { PluggableList } from 'unified';

export type RendererOptions = Omit<ReactMarkdownOptions, 'remarkPlugins' | 'rehypePlugins' | 'components' | 'children'> & {
remarkPlugins: PluggableList,
rehypePlugins: PluggableList,
components?:
| Partial<
Omit<NormalComponents, keyof SpecialComponents>
& SpecialComponents
Components
& {
[elem: string]: ComponentType<any>,
}
Expand Down
4 changes: 3 additions & 1 deletion apps/app/src/interfaces/services/rehype-sanitize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Attributes } from 'hast-util-sanitize/lib';
import type { defaultSchema } from 'hast-util-sanitize';

type Attributes = typeof defaultSchema.attributes;

export const RehypeSanitizeType = {
RECOMMENDED: 'Recommended',
Expand Down
9 changes: 9 additions & 0 deletions apps/app/src/services/renderer/recommended-whitelist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('recommended-whitelist', () => {

test('.attributes should return data attributes', () => {
expect(attributes).not.toBeNull();

assert(attributes != null);

expect(Object.keys(attributes)).includes('*');
expect(attributes['*']).includes('alt');
expect(attributes['*']).includes('align');
Expand All @@ -25,12 +28,18 @@ describe('recommended-whitelist', () => {

test('.attributes should return iframe attributes', () => {
expect(attributes).not.toBeNull();

assert(attributes != null);

expect(Object.keys(attributes)).includes('iframe');
expect(attributes.iframe).includes('src');
});

test('.attributes should return video attributes', () => {
expect(attributes).not.toBeNull();

assert(attributes != null);

expect(Object.keys(attributes)).includes('video');
expect(attributes.iframe).includes('src');
});
Expand Down
3 changes: 2 additions & 1 deletion apps/app/src/services/renderer/recommended-whitelist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defaultSchema } from 'hast-util-sanitize';
import type { Attributes } from 'hast-util-sanitize/lib';
import deepmerge from 'ts-deepmerge';

type Attributes = typeof defaultSchema.attributes;

/**
* reference: https://meta.stackexchange.com/questions/1777/what-html-tags-are-allowed-on-stack-exchange-sites,
* https://github.com/jch/html-pipeline/blob/70b6903b025c668ff3c02a6fa382031661182147/lib/html/pipeline/sanitization_filter.rb#L41
Expand Down
5 changes: 2 additions & 3 deletions apps/app/src/services/renderer/rehype-plugins/add-class.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// See: https://github.com/martypdx/rehype-add-classes for the original implementation.
// Re-implemeted in TypeScript.
import type { Nodes as HastNode, Element, Properties } from 'hast';
import { selectAll } from 'hast-util-select';
import type { Node as HastNode, Element } from 'hast-util-select/lib/types';
import { Properties } from 'hast-util-select/lib/types';
import { Plugin } from 'unified';
import type { Plugin } from 'unified';

export type SelectorName = string; // e.g. 'h1'
export type ClassName = string; // e.g. 'header'
Expand Down
Loading
Loading