Skip to content

Commit

Permalink
docs(node-package): 📚 improve type documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneylab committed Dec 18, 2024
1 parent a67da26 commit 297786d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type MarkdownToPlaintextOptions = Omit<MarkdownToHtmlOptions, "searchTerm">;
* Markdown Parser.
*
* @param markdown The Markdown text to parse
* @param {Object} [options={}] - Parse options
* @param {MarkdownToHtmlOptions|undefined} [options={}] - Parse options
* @param {boolean} options.enableSmartPunctuation - `true` if "something" should be replaced with
* “something”, etc.
* @param {string} options.canonicalRootUrl - if included, relative url gain this value as a prefix
Expand All @@ -47,27 +47,30 @@ type MarkdownToPlaintextOptions = Omit<MarkdownToHtmlOptions, "searchTerm">;
* first instance also has `id=search-match` added the mark
* tag. You might use this to scroll the first match into view
* automatically.
* @returns {Object} `markdown` parsed into HTML as an object or an error object. If successful, the HTML is
* @returns {Promise<MarkdownToHtmlOKOutput|MarkdownToHtmlErrorOutput>} `markdown` parsed into HTML as an object or an error object. If successful, the HTML is
* in the `.html` field of the returned object.
*/
const markdownToHtml: (
markdown: string,
options?: MarkdownToHtmlOptions,
options: MarkdownToHtmlOptions | undefined,
) => Promise<MarkdownToHtmlOKOutput | MarkdownToHtmlErrorOutput> =
async function markdownToHtml(markdown, options) {
async function markdownToHtml(
markdown,
options: MarkdownToHtmlOptions | undefined,
): Promise<MarkdownToHtmlOKOutput | MarkdownToHtmlErrorOutput> {
const { markdown_to_html } = await instantiate();
const { canonicalRootUrl, enableSmartPunctuation, searchTerm } = options ??
{};

return markdown_to_html(markdown, {
enable_smart_punctuation: true,
...(typeof canonicalRootUrl !== "undefined"
? { canonical_root_url: canonicalRootUrl }
...(typeof options?.canonicalRootUrl !== "undefined"
? { canonical_root_url: options.canonicalRootUrl }
: {}),
...(typeof enableSmartPunctuation !== "undefined"
? { enable_smart_punctuation: enableSmartPunctuation }
...(typeof options?.enableSmartPunctuation !== "undefined"
? { enable_smart_punctuation: options.enableSmartPunctuation }
: {}),
...(typeof options?.searchTerm !== "undefined"
? { search_term: options.searchTerm }
: {}),
...(typeof searchTerm !== "undefined" ? { search_term: searchTerm } : {}),
});
};

Expand Down

0 comments on commit 297786d

Please sign in to comment.