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

customHTMLRenderer behavior in Markdown vs WYSIWYG mode #3234

Open
jasperarmstrong opened this issue Apr 4, 2024 · 0 comments
Open

customHTMLRenderer behavior in Markdown vs WYSIWYG mode #3234

jasperarmstrong opened this issue Apr 4, 2024 · 0 comments
Labels

Comments

@jasperarmstrong
Copy link

jasperarmstrong commented Apr 4, 2024

Summary

I am trying to set up text-align left, center, and right functionality in my app. I have it working how I want in Markdown mode and in the viewer, but it doesn't fully work in WYSIWYG mode.

I'll put some screenshots below, but I've noticed that in the viewer and markdown modes, each paragraph block stays within one p tag, while each line in the WYSIWYG mode is its own separate p tag. Only the first p tag per paragraph is being affected by my customHTMLRenderer code. Also [left], [center], and [right] are not being removed from the displayed text.

I've looked through the docs and tried every sane way I could think of to make the WYSIWYG mode work consistently with the other modes, but I'm running out of ideas. Is there a way to make this work? I'm using the following code:

let lastAlignment;
const alignFunc = (node, context) => {
    const { entering, origin } = context;

    if (node.firstChild?.literal?.startsWith("[center]")) lastAlignment = "center";
    else if (node.firstChild?.literal?.startsWith("[right]")) lastAlignment = "right";
    else if (node.firstChild?.literal?.startsWith("[left]") || node.prev === null) lastAlignment = "left";

    if (entering) {
        let output = origin();
        output.attributes = {
            style: `text-align: ${lastAlignment};`,
        };
        return output;
    }
    return origin();
};
const customHTMLRenderer = {
    heading: alignFunc,
    paragraph: alignFunc,
    text(node, context) {
        const {origin} = context;
        let output = origin();
        output.content = output.content.replace(/^\[(left|center|right)\] ?/g, "");
        return output;
    }
}

Screenshots

Viewer:
image

Markdown Mode:
image

WYSIWYG Mode:
image

Version

3.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant