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

Add ruby pronunciation support on text #222

Merged
merged 1 commit into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/Tutorials/Elements/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ New-PodeWebCard -Content @(
Which looks like below:

![text](../../../images/text.png)

## Pronunciation

You can add small pronunciation text above displayed text by using `-Pronunciation`:

```powershell
New-PodeWebText -Value '漢' -Pronunciation 'ㄏㄢˋ'
```

(Note: for the above to render properly, use PowerShell 6+)
4 changes: 4 additions & 0 deletions examples/full.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Start-PodeServer -StatusPageExceptions Show {
New-PodeWebText -Value 'example' -Style Italics
New-PodeWebText -Value ' paragraphs' -Style Bold
)
New-PodeWebParagraph -Elements @(
New-PodeWebText -Value 'Pronuncation example: '
New-PodeWebText -Value '漢' -Pronunciation 'ㄏㄢˋ'
)
New-PodeWebParagraph -Elements @(
New-PodeWebText -Value "Look, here's a "
New-PodeWebLink -Source 'https://github.com/badgerati/pode' -Value 'link' -NewTab
Expand Down
5 changes: 5 additions & 0 deletions src/Public/Elements.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,10 @@ function New-PodeWebText
[hashtable]
$CssStyle,

[Parameter()]
[string]
$Pronunciation,

[Parameter(ParameterSetName='Paragraph')]
[switch]
$InParagraph
Expand All @@ -1056,6 +1060,7 @@ function New-PodeWebText
Parent = $ElementData
ID = (Get-PodeWebElementId -Tag Txt -Id $Id -RandomToken)
Value = [System.Net.WebUtility]::HtmlEncode($Value)
Pronunciation = [System.Net.WebUtility]::HtmlEncode($Pronunciation)
Style = $Style
InParagraph = $InParagraph.IsPresent
Alignment = $Alignment.ToLowerInvariant()
Expand Down
5 changes: 5 additions & 0 deletions src/Templates/Public/styles/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ button#menu-toggle {
width: 50px;
}

ruby rt {
font-size: 53%;
font-style: normal;
}

.footer.powered-by {
border-width: 1px;
border-style: solid;
Expand Down
4 changes: 4 additions & 0 deletions src/Templates/Views/elements/text.pode
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ $(
}
}

if (![string]::IsNullOrWhiteSpace($data.Pronunciation)) {
$value = "<ruby>$($value) <rt>$($data.Pronunciation)</rt></ruby>"
}

if ($data.InParagraph) {
$value = "<p class='text-$($data.Alignment)'>$($value)</p>"
}
Expand Down