-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also allows overriding the title by specifying a string after the alert syntax.
- Loading branch information
1 parent
45c96a2
commit 8686e9e
Showing
12 changed files
with
1,144 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// The metadata of an Alert node. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct NodeAlert { | ||
/// Type of alert | ||
pub alert_type: AlertType, | ||
|
||
/// Overridden title. If None, then use the default title. | ||
pub title: Option<String>, | ||
|
||
/// Originated from a multiline blockquote. | ||
pub multiline: bool, | ||
} | ||
|
||
/// The type of alert. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] | ||
pub enum AlertType { | ||
/// Useful information that users should know, even when skimming content | ||
#[default] | ||
Note, | ||
|
||
/// Helpful advice for doing things better or more easily | ||
Tip, | ||
|
||
/// Key information users need to know to achieve their goal | ||
Important, | ||
|
||
/// Urgent info that needs immediate user attention to avoid problems | ||
Warning, | ||
|
||
/// Advises about risks or negative outcomes of certain actions | ||
Caution, | ||
} | ||
|
||
impl AlertType { | ||
/// Returns the default title for an alert type | ||
pub(crate) fn default_title(&self) -> String { | ||
match *self { | ||
AlertType::Note => String::from("Note"), | ||
AlertType::Tip => String::from("Tip"), | ||
AlertType::Important => String::from("Important"), | ||
AlertType::Warning => String::from("Warning"), | ||
AlertType::Caution => String::from("Caution"), | ||
} | ||
} | ||
|
||
/// Returns the CSS class to use for an alert type | ||
pub(crate) fn css_class(&self) -> String { | ||
match *self { | ||
AlertType::Note => String::from("alert-note"), | ||
AlertType::Tip => String::from("alert-tip"), | ||
AlertType::Important => String::from("alert-important"), | ||
AlertType::Warning => String::from("alert-warning"), | ||
AlertType::Caution => String::from("alert-caution"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.