Skip to content

Commit

Permalink
added some default text to the editor
Browse files Browse the repository at this point in the history
i couldn't do this before, because i didn't know how to make Blazor react to the pre-set text (located at `Index.razor:11`) upon page load. i searched and found some overridable Blazor functions that might help. the "on initialize" function occurs too soon; the default text isn't accessible yet. the "on after render" function is what i needed; it occurs a bit later in the Blazor lifecycle, allowing the overlay to update using the pre-set `textarea` content.

we also have a minor rule change with the `---` lines: you may now include spaces/tabs immediately following the `-` dashes.

and lastly, a fix: the regular expression for the "mono" formatting (the `\`` via back-tick character) was incorrect. when searching for content between the two back-ticks, the pattern was excluding the `_` underscore character, but it should have excluded the back-tick. a classic _copy-paste_ bug: i copied from the "italic" pattern, but failed to make all the necessary changes to the duplicated code.

typing ``` above made me realize that the pattern did _not_ handle that scenario. i started trying to fix this by allowing the content between back-ticks to be a single back-tick. however, three consecutive back-ticks is meant to be the start of "multiline mono" formatting. and the fix still doesn't address the next problem: how do i show _two_ back-ticks in a "mono" black? i think the solution will be to "escape" the inner back-ticks  using a `\` backslash character as a prefix (for example: `\``). this does not seem like an important issue. i am naturally driven to fix it anyway, but it's more important to prioritize and stay on track. i'll document it as a known issue.
  • Loading branch information
connectuum committed Jan 3, 2022
1 parent 8a98c0d commit 72b3280
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
36 changes: 30 additions & 6 deletions solution/Poemdown.Blaze/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
<div class="row">
<div class="editor col-12 col-sm-6">
<textarea class="monospace" @oninput="HandleInput" @onkeydown="HandleKeyDown"
placeholder="just begin."></textarea>
placeholder="just begin.">
does _this_ actually *work*?

---

# test single
more things
e v e n more

## test double
something else

### test triple
this is the `testing` code`
</textarea>
<div class="overlay monospace"></div>
</div>
<div class="preview col-12 col-sm-6">
Expand All @@ -20,15 +34,25 @@

private string previousInput = "";

private void HandleKeyDown(KeyboardEventArgs args) {
UpdateOverlay();
/*protected override async Task OnInitializedAsync() {
await UpdateOverlay(); //too soon; _wait_
}*/

protected override async Task OnAfterRenderAsync(bool isFirstRender) {
if ( isFirstRender ) {
await UpdateOverlay();
}
}

private async void HandleKeyDown(KeyboardEventArgs args) {
await UpdateOverlay();
}

private void HandleInput(ChangeEventArgs args) {
UpdateOverlay();
private async void HandleInput(ChangeEventArgs args) {
await UpdateOverlay();
}

private async void UpdateOverlay() {
private async Task UpdateOverlay() {
string input = await JS.InvokeAsync<string>("getEditorTextareaValue");

if ( input == previousInput ) {
Expand Down
6 changes: 3 additions & 3 deletions solution/Poemdown.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const string sampleText = @"
const string sampleText = @"
does _this_ actually *work*?
---
---
# test single
more things
Expand All @@ -11,7 +11,7 @@ more things
something else
### test triple
what about ``` then
this is the `testing` code
";

Expand Down
4 changes: 2 additions & 2 deletions solution/Poemdown.Core/Convert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static class Convert {
html = Regex.Replace(html, @"\r", "");
html = Regex.Replace(html, @"(\*)([^\*\n]+)(\*)", "<b><c>$1</c>$2<c>$3</c></b>");
html = Regex.Replace(html, @"(_)([^_\n]+)(_)", "<em><c>$1</c>$2<c>$3</c></em>");
html = Regex.Replace(html, @"(`)([^_\n]+)(`)", "<mono><c>$1</c>$2<c>$3</c></mono>");
html = Regex.Replace(html, @"(^|\n)(---)($|\n)", "$1<line><c>$2</c></line><hr/>");
html = Regex.Replace(html, @"(`)([^`\n]+|`)(`)", "<mono><c>$1</c>$2<c>$3</c></mono>");
html = Regex.Replace(html, @"(^|\n)(---)([ \t]*)($|\n)","$1<line><c>$2</c></line>$3<hr/>");
html = Regex.Replace(html, @"(^|\n)(#)(\s+[^$\n]+)", "$1<head1><c>$2</c>$3</head1>");
html = Regex.Replace(html, @"(^|\n)(##)(\s+[^$\n]+)", "$1<head2><c>$2</c>$3</head2>");
html = Regex.Replace(html, @"(^|\n)(###)(\s+[^$\n]+)", "$1<head3><c>$2</c>$3</head3>");
Expand Down

0 comments on commit 72b3280

Please sign in to comment.