script/dom/execcommand/commands/
defaultparagraphseparator.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use crate::dom::bindings::str::DOMString;
6use crate::dom::document::Document;
7use crate::dom::execcommand::basecommand::DefaultSingleLineContainerName;
8
9/// <https://w3c.github.io/editing/docs/execCommand/#the-defaultparagraphseparator-command>
10pub(crate) fn execute_default_paragraph_separator_command(
11    document: &Document,
12    value: DOMString,
13) -> bool {
14    // > Let value be converted to ASCII lowercase. If value is then equal to "p" or "div",
15    // > set the context object's default single-line container name to value, then return true. Otherwise, return false.
16    let value = match value.to_ascii_lowercase().as_str() {
17        "div" => DefaultSingleLineContainerName::Div,
18        "p" => DefaultSingleLineContainerName::Paragraph,
19        _ => return false,
20    };
21
22    document.set_default_single_line_container_name(value);
23
24    true
25}