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

Hide links, tables, images, and alignment buttons #158

Open
Oren-Lindsey opened this issue Oct 27, 2023 · 5 comments
Open

Hide links, tables, images, and alignment buttons #158

Oren-Lindsey opened this issue Oct 27, 2023 · 5 comments

Comments

@Oren-Lindsey
Copy link

I need to hide the links, tables, images, and alignment buttons, as my app can't support them, and there doesn't seem to be a way to do that. Thanks.

@Oren-Lindsey
Copy link
Author

Oh, and I need to be able to disable all the header options except h2

@stevengharris
Copy link
Owner

stevengharris commented Oct 27, 2023

There is some limited guidance on how to do this, per https://github.com/stevengharris/MarkupEditor#customizing-the-toolbar, but you have to sort it out from ToolbarContents.swift for the details. Here is a version of AppDelegate.init in the SharedDemo folder that does some of what you want:

override init() {
    MarkupEditor.style = .compact
    let myToolbarContents = ToolbarContents(
        insert: false,    // Remove the insert toolbar that allows links, images, and tables
        styleContents: StyleContents(dent: false).   // Remove the indent/outdent button
    )
    ToolbarContents.custom = myToolbarContents
}

I hadn't thought about limiting the styles themselves to some kind of subset. Probably the easiest way to do that would just be to fork the code and modify StyleContext.swift so that it only contains the items you want, like:

    public static let AllCases = [Undefined, Multiple, P, H2]
    public static let StyleCases = [P, H2]
    public static let SizeCases = [P, H2]  // In order smallest to largest

While you're at it, you could change the name used in the menu so it looks more like what you might want (since "Header H2" is a little weird when there is only one style other than "Normal":

    public static let H2 = StyleContext(tag: "H2", name: "Header", fontSize: 24)

IIRC, the font sizes in this static are meaningless because they are controlled via markup.css as factors on apple-system-body.

@stevengharris
Copy link
Owner

FWIW, I'm interested in identifying things people need that really should be part of the API but which they're forced to take care of via a fork right now, so this was helpful to me. Don't go crazy with itemizing them, tho, please 😜.

@stevengharris
Copy link
Owner

I see that limiting the paragraph style options in StyleContext also requires a modification to MarkupMenu so that the menu works properly for Mac Catalyst if you care about it:

private func styleMenu() -> UIMenu {
    let children: [UICommand] = [
        UICommand(title: "Normal", action: #selector(MarkupWKWebView.pStyle)),
        UICommand(title: "Header", action: #selector(MarkupWKWebView.h2Style)),
    ]
    return UIMenu(title: "Style", children: children)
}

The UICommands here really should not be hardcoded and should just have adjusted based on the styles, I think, but I haven't really looked at this area for a long time.

@Oren-Lindsey
Copy link
Author

Thanks for your help!

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

No branches or pull requests

2 participants