problem with preview and @diplodoc/transform

Đang mở
#776 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, markdown, react, typescript

Hướng nghiên cứu

Start with src/editor.tsx and src/SplitModePreview.tsx, then compare docs/how-to-add-preview.md with the @diplodoc/transform full-preset configuration. Reproduce the missing emoji, marked, and text-color output in both the editor preview and standalone browser/server usage. Done means the full preset transforms those features to HTML without requiring unsupported props or an incorrect plugin setup.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

question 1

i want to add preview to the editor and i follow the how-to-add-preview structure :
src/SplitModePreview.tsx

// src/SplitModePreview.tsx
import {useEffect, useMemo, useRef, useState} from 'react';
import debounce from 'lodash/debounce';
import {useThemeValue} from '@gravity-ui/uikit';
import {YfmStaticView} from '@gravity-ui/markdown-editor'; // Adjust path if needed
import transform from '@diplodoc/transform'; // Adjust path if needed

interface SplitModePreviewProps {
    plugins?: any[];
    getValue: () => string;
    allowHTML?: boolean;
    breaks?: boolean;
    linkify?: boolean;
    linkifyTlds?: string[];
    needToSanitizeHtml?: boolean;
}

export function SplitModePreview(props: SplitModePreviewProps) {
    const {plugins, getValue, allowHTML, breaks, linkify, linkifyTlds, needToSanitizeHtml} = props;
    const [html, setHtml] = useState('');
    const divRef = useRef<HTMLDivElement>(null);

    const theme = useThemeValue(); 
    const render = useMemo(
        () =>
            debounce(() => {
                const res = transform(getValue(), {
                    allowHTML,
                    breaks,
                    plugins,
                    linkify,
                    linkifyTlds,
                    needToSanitizeHtml,
                }).result;
                console.log(res);
                setHtml(res.html);
            }, 200),
        [getValue, allowHTML, breaks, plugins, linkify, linkifyTlds, needToSanitizeHtml, theme],
    );

    useEffect(() => {
        render();
    }, [props, render]);

    return <YfmStaticView ref={divRef} html={html} noListReset className="demo-preview" />;
}

and this is my editor :
src/editor.tsx

import React, {useCallback} from 'react'; // ✅ Fix: import useCallback
import {
    MarkdownEditorView,
    MarkupString,
    RenderPreview,
    useMarkdownEditor, // ✅ Fix: import props type for renderPreview
} from '@gravity-ui/markdown-editor';
import {SplitModePreview} from './SplitModePreview'; // Adjust the path if needed

export interface EditorProps {
    onSubmit: (value: MarkupString) => void;
}

export const Editor: React.FC<EditorProps> = ({onSubmit}) => {
    const renderPreview = useCallback<RenderPreview>(
        (props) => <SplitModePreview {...props} />,
        [],
    );

    const editor = useMarkdownEditor({
        markupConfig: {
            renderPreview,
    splitMode: 'horizontal',
        },
        md: {
            html: false,
        },
        experimental:{
            directiveSyntax:'enabled'
        },
        initial: {
            splitModeEnabled: true,
            toolbarVisible: true,
        },
    });

    React.useEffect(() => {
        const submitHandler = () => {
            const value = editor.getValue();
            onSubmit(value);
        };

        editor.on('submit', submitHandler);
        return () => {
            editor.off('submit', submitHandler);
        };
    }, [editor, onSubmit]);

    return <MarkdownEditorView stickyToolbar autofocus editor={editor} />;
};

the preview is working for the YFM preset but not for full preset .
i mean the emoji and marked and text color and ... are not tranfoming to html ,

i think the problem is for props .

marked preview

Image

underline preview

Image

question 2

im trying to transform the YFM without the editor just transform as plugin or module on browser or nodejs server but it has the same problem with @diplodoc/transform its not support the "full" preset options ( emoji and marked and text color and ... ). what the way to do that ?

Ngôn ngữ chính
TypeScript
Star
428
Fork
48
Merge trung bình
5 ngày 15 giờ
Pull request đã merge (30 ngày)
47

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của gravity-ui/markdown-editor

Tất cả issue của gravity-ui/markdown-editor

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.