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

Utility Entry types #36

Open
kgar opened this issue Aug 10, 2022 · 0 comments
Open

Utility Entry types #36

kgar opened this issue Aug 10, 2022 · 0 comments

Comments

@kgar
Copy link
Owner

kgar commented Aug 10, 2022

ts-markdown has a few entries with the append property. While this was a neat idea at first, more ideas are coming to mind about utilities that would be useful, above and beyond append.

Create a series of utility MarkdownEntry types.

Ideas so far:

  • AppendEntry : takes whatever text was rendered and appends additional content
  • PrependEntry : takes whatever text was rendered and prepends additional content
  • ToLowerCaseEntry
  • ToUpperCaseEntry
  • TrimEntry

Reason:
There are scenarios where you are unable to reliably perform some quick modifications to an array of markdown entries. For example, certain information is not available at the point where a paragraph is created, and now the paragraph needs to be prepended with some text. Rather than write a bunch of duck typing code to handle every possible scenario, utility entries could build these kinds of post-process needs into markdown rendering via data decoration.

What would the code look like?

// Example: prepend some markdown content to the first item in an array of markdown entries

/*
Let's say the entries are supposed to read:
This is some text.

Nice!
*/
let someEntries = getSomeEntriesFromSomewhere();

let firstEntryWithPrepend = { 
  utilPrepend: { 
    text: [bold("Note:")], entry: someEntries[0]
  }
};

someEntries.splice(0, 1, firstEntryWithPrepend);

/*
Now, it should read:
Note: This is some text.

Nice!
*/

Now, take that idea and create helper functions to help with managing the array mutation / copying:

// Example: prepend some markdown content to the first item in an array of markdown entries

/*
Let's say the entries are supposed to read:
This is some text.

Nice!
*/
let someEntries = getSomeEntriesFromSomewhere();

let someEntriesWithPrepend = prependFirst(someEntries, { text: [bold("Note: ")] });

/*
`someEntriesWithPrepend` should read:
Note: This is some text.

Nice!
*/

This is just a rough sketch of the idea and it will surely evolve after some more thought and experimentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant