Markdown processing should be optional #253

This commit is contained in:
Alex Mazanov 2021-12-22 18:54:38 -05:00
parent 453e1bb1aa
commit 4c3522f317
No known key found for this signature in database
GPG Key ID: FD35C3C7C1D34AB4
3 changed files with 6 additions and 1 deletions

View File

@ -127,6 +127,7 @@ echo "Line 1 \\n Line2 | size=8"
| `sfcolor` | CSS color or HEX, `light_color,dark_color` | Sets SF Symbol color. If only one color is provided, it is used for both light and dark appearance. If you fame multiple SF Symbols you can provide different colors by adding index, like this `sfcolor2` |
| `font` | macOS font name | Sets font name to use in item text |
| `size` | Number | Sets item text size |
| `md` | True | Enables markdown support in menu title for `**bold**` and `*italic*` |
| `sfsize` | Number | Sets size for SF Symbol image embedded in text|
| `length`| Number | Trims item text to a provided number of characters. The full title will be displayed in a tooltip. |
| `trim` | True | Trims whitespace characters |

View File

@ -539,7 +539,7 @@ extension MenubarItem {
style.alignment = .left
var attributedTitle = NSMutableAttributedString(string: title)
if #available(macOS 12, *), let parsedMD = try? NSAttributedString(markdown: title) {
if #available(macOS 12, *), params.md, let parsedMD = try? NSAttributedString(markdown: title) {
attributedTitle = NSMutableAttributedString(attributedString: parsedMD)
}

View File

@ -102,6 +102,10 @@ struct MenuLineParameters {
params["font"]
}
var md: Bool {
params["md"] == "true"
}
var size: CGFloat? {
guard let sizeStr = params["size"], let pSize = Int(sizeStr) else { return nil }
return CGFloat(pSize)