Skip to content

Commit

Permalink
refactored the HTML-conversion process
Browse files Browse the repository at this point in the history
as we enter into algorithm, demands upon concentration increase. find your quiet place, your flow state, your algorithm rhythm.

commit goal: begin the real HTML-conversion algorithm.

immediate obstacles: the existing `ToHtml()` function already feels overly complicated and deeply-branching. also, if we were to write a new `ToBetterHtml()` function, there would be a lot of duplicated code. duplicated code should be healed, collapsed, into a new function, reusable anywhere.

(otherwise: code copies drift out of sync due to human error, leading to a broad class of bugs where human _expectation_ of functional-equivalence collides with a different _reality_. to avoid refactoring is to encourage _more_ such duplication and inconsistency. travel that path long enough, and your problems shall become great enough to earn a name: _technical debt_.)

refactoring is holy: seek it always.

a refactor _appreciates_ code already set in place, understands exactly what that code achieves, its purpose... then shatters it without mercy, reassembling it into something better. [slow zoom out of fractal into itself again]. demand the right to change. to grow. to break. to prune away, then reach ever further. YOU.

now to the problem at hand: refactoring our whitespace-related logic into a new, focused, testable, reusable function.

to perform its work, this function must know which character to consider, and (for tabs) the number of characters present in the current line of converted text. it produces an dual output, for clarity and convenience of use; consider `if ( TryFind(x, out y) ) { use y; }` vs. all the nullness in `var y = FindOrNull(x); if ( y != null ) { use y.Value; }`.

the function's name, inputs, and outputs are its exterior signature. code written elsewhere can call upon this signature, sending along inputs to receive outputs in return. within this new exterior, however, the HTML-conversion logic (the `switch` conditions and their resulting outcomes) remains the same.

with refactor complete, the old `ToHtml()` sheds its shadow, keeping only its unique rainbow-coloring capabilities. the new `ToHtml()` isn't _nearly_ as interesting yet, but is now poised to begin growth. the conversion algorithm shall take root here.

_By and Down the River_ has been my song today, and found its way into the work. the song seems broadly aimed at empty, insincere leadership. but it also admonishes internally: give Light unto your work, share of it and benefit, lest it bloat, betray, and decay you. another scale smaller, and it places you as judge of your own plans, paths, and aspirations; which are worthy? which shall rot your soul?

and here is that holy recursion, that nested depth-wise repetition, we see it everywhere; it resonates throughout. it feels of universe, and the point was: i feel it also in this music, these words. it feels like Truth.

as does [the strain of context]. if everything breaks down _two_, then the challenge is to defy the sharpest oppositional gravities. defy... as in [defy, resist, counter], and _not_ [avoid, provoke, attack]. _not_ [mislead, brainwash, con, confuse]. _not_ [tribes and factions]. _not_ [win or lose].

what feels like Truth is a tapestry of bindings, all-woven from factual, fictional, emotional findings. different perspectives, interconnected, search-and-traversable, social-and-sharable, deeply private-protected. 

to spike into extreme is to deny our collective-connected binding, to boldly test [the strain of context]. this invites judgement, but not aggression: not all extremes are necessarily bad. Trust in the natural strain, and delight in the refactoring. then Trust the strain will smooth our way through change forevermore.
  • Loading branch information
connectuum committed Dec 24, 2021
1 parent 65e2770 commit 132d125
Showing 1 changed file with 90 additions and 32 deletions.
122 changes: 90 additions & 32 deletions solution/Poemdown.Blaze/Shared/PoemdownConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,96 @@ namespace Poemdown.Blaze.Shared;

public static class PoemdownConvert {

public const int TabSize = 4;

#region aristocrat-breaks-down-----two //let us try something new

#region searching-your-eyes-for-a-hint-or-trace-of-it

/////////////////////////////////////////////////////////////////////////////////////////CROWN//
// >>> poemdown-formatted text
// <<< HTML-formatted text that represents the poemdown input
//----------------------------------------------------------------------------------------------
public static string ToHtml(string poemdown) {
var html = new StringBuilder();
int hueSpeed = 3;
int displayCharCount = 0;
int lineCharCount = 0;
const int tabSize = 4;

var html = new StringBuilder();
html.Append("<span style='color:red;'>");

foreach ( char c in poemdown ) {
switch ( c ) {
case '\n':
html.Append("<br/>");
lineCharCount = 0;
continue;
if ( IsHtmlWhitespace(c, ref lineCharCount, out string whiteHtml) ) {
html.Append(whiteHtml);
continue;
}

case '\r':
continue;
html.Append(c);
lineCharCount++;
}

html.Append("</span>");
return html.ToString();
}

case ' ':
html.Append("&nbsp;");
//----------------------------------------------------------------------------------------------
// >>> any single character
// <-> the number of characters in the current line
// <-- HTML-formatted text that represents the character input
// <<< does the character input cause an HTML-formatted result?
//----------------------------------------------------------------------------------------------
public static bool IsHtmlWhitespace(char c, ref int lineCharCount, out string html) {
switch ( c ) {
case '\n':
html = "<br/>";
lineCharCount = 0;
return true;

case '\r':
html = "";
return true;

case ' ':
html = "&nbsp;";
lineCharCount++;
return true;

case '\t':
//test line: 1234 567 89 1 2
int n = TabSize-(lineCharCount%TabSize);
n = (n == 0 ? TabSize : n);

string tabHtml = "";

for ( int i = 0 ; i < n ; i++ ) {
tabHtml += "&nbsp;";
lineCharCount++;
continue;
}

case '\t':
//test line: 1234 567 89 1 2
int spaceCount = tabSize-lineCharCount%tabSize;
spaceCount = (spaceCount == 0 ? tabSize : spaceCount);
html = tabHtml;
return true;
}

html = "";
return false;
}

for ( int i = 0 ; i < spaceCount ; i++ ) {
html.Append("&nbsp;");
lineCharCount++;
}
#endregion

continue;

#region golden-Light-upon-fertilizer

////////////////////////////////////////////////////////////////////////////////////////////////
// >>> poemdown-formatted text
// <<< HTML-formatted text that represents the poemdown input
//----------------------------------------------------------------------------------------------
public static string ToHuespinHtml(string poemdown) {
var html = new StringBuilder();
int displayCharCount = 0;
int lineCharCount = 0;
const int hueSpeed = 3;

foreach ( char c in poemdown ) {
if ( IsHtmlWhitespace(c, ref lineCharCount, out string? whiteHtml) ) {
html.Append(whiteHtml);
continue;
}

int hue = hueSpeed*displayCharCount;
Expand All @@ -57,15 +111,19 @@ public static string ToHtml(string poemdown) {
return html.ToString();
}

#endregion //something-that breaks to... sun? becomes.
#endregion

//showing only sorry delay
//bits and pieces too much to learn
//til the Light betray you hidden bits and pieces
//and your empty elocution they shall aid the execution

//something many-but-one
//something all but none
// -<{ the holy recursion }>-

//(five four three)
//to many of one
//to every from none
//the path has begun
//to connectuum
//EVERYTHING BREAKS DOWN TWO
//you find a way back to YOU
//[crystallized pathways through]
//net of Light guiding True
//(no need left for the hourglass)

}

0 comments on commit 132d125

Please sign in to comment.